Transform OCL into some text [message #1176057] |
Fri, 08 November 2013 00:06  |
Eclipse User |
|
|
|
Hi!
I have an UML model with OCL constraints. I wrote an Acceleo-transformation from UML model to XML-schema. It works fine, but now I need to transform OCL-constraints into XPath-expressions or schematron.
I think that the simplest solution for me is 1) to parse OCL into Ecore, 2) save it as XMI-file and 3) pass the later one to Acceleo-transformation. But I don't understand how implement the first step. Help me please.
// Offtopic start
Actually I've parsed some abstract OCL stored in text file into Ecore by Dresden OCL. But It lacks documentation, I don't understand how to use it with UML model. I hope I'll have more luck with Eclipse OCL.
// Offtopic end
|
|
|
Re: Transform OCL into some text [message #1177132 is a reply to message #1176057] |
Fri, 08 November 2013 15:00   |
Eclipse User |
|
|
|
I wrote something:
ResourceSet rs = new ResourceSetImpl();
org.eclipse.ocl.uml.OCL.initialize(rs);
rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
Resource model = rs.createResource(URI.createFileURI("model/OclTest.uml"));
model.load(null);
EObject person = model.getEObject("//@packagedElement[name='Package1']/@packagedElement[name='Person']");
Resource res = rs.createResource(URI.createFileURI("myOcl.xmi"));
org.eclipse.ocl.OCL<EPackage, EClassifier, EOperation, EStructuralFeature, EEnumLiteral, EParameter, EObject, CallOperationAction, SendSignalAction, Constraint, EClass, EObject> ocl = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE, res);
OCLHelper<EClassifier, EOperation, EStructuralFeature, Constraint> helper = ocl.createOCLHelper();
// I don't understand how to bind constraint to Person class instead of uml:Class
helper.setInstanceContext(person);
// It creates constraint for uml:Class
Constraint inv = helper.createInvariant("self.name.size() > 0");
// It throws an exception: org.eclipse.ocl.SemanticException: Unrecognized variable: (age)
//Constraint inv = helper.createInvariant("self.age > 0");
EList<EObject> c = res.getContents();
res.save(null);
res.unload();
I don't understand two things:
- How to set Person (instead of uml:Class) context for my invariant
- How to parse OCL-constraints contained in model/OclTest.uml
|
|
|
Re: Transform OCL into some text [message #1178637 is a reply to message #1177132] |
Sat, 09 November 2013 15:07   |
Eclipse User |
|
|
|
Hi
Eclipse OCL supports usgae with Ecore:
e.g. OCLHelper<EClassifier, EOperation, EStructuralFeature, Constraint>
or UML
e.g. org.eclipse.ocl.uml.OCL.initialize
You are mixing the two which is a guaranteed disaster.
If you use UML exclusively, it should work.
Alternatively you might prefer to use the neutral pivot binding that
prototypes resolution of the non-interchangeability of OMG's OCL XMI.
This is available once you use install the OCL Examples and Editors
using e.g. org.eclipse.ocl.examples.pivot.OCL.
OCL is deceptively simple, but once you start considering subtleties
such as invalid you may find it a bit harder and might benefit from the
normalisations and optimisations underway in the OCL to Java code
generator in org.eclipse.ocl.examples.codegen.
Sorry you may not be satisfied by the documentation quality.
If you care to make an OCL to something translator available other users
may benefit too.
Regards
Ed Willink
On 08/11/2013 21:00, Denis Nikiforov wrote:
> I wrote something:
> ResourceSet rs = new ResourceSetImpl();
> org.eclipse.ocl.uml.OCL.initialize(rs);
> rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi",
> new XMIResourceFactoryImpl());
>
> Resource model =
> rs.createResource(URI.createFileURI("model/OclTest.uml"));
> model.load(null);
>
> EObject person =
> model.getEObject("//@packagedElement[name='Package1']/@packagedElement[name='Person']");
>
> Resource res = rs.createResource(URI.createFileURI("myOcl.xmi"));
> org.eclipse.ocl.OCL<EPackage, EClassifier, EOperation,
> EStructuralFeature, EEnumLiteral, EParameter, EObject,
> CallOperationAction, SendSignalAction, Constraint, EClass, EObject>
> ocl = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE, res);
>
> OCLHelper<EClassifier, EOperation, EStructuralFeature, Constraint>
> helper = ocl.createOCLHelper();
>
> // I don't understand how to bind constraint to Person class instead
> of uml:Class
> helper.setInstanceContext(person);
>
> // It creates constraint for uml:Class
> Constraint inv = helper.createInvariant("self.name.size() > 0");
>
> // It throws an exception: org.eclipse.ocl.SemanticException:
> Unrecognized variable: (age)
> //Constraint inv = helper.createInvariant("self.age > 0");
>
> EList<EObject> c = res.getContents();
>
> res.save(null);
> res.unload();
>
> I don't understand two things:
>
> How to set Person (instead of uml:Class) context for my invariant
> How to parse OCL-constraints contained in model/OclTest.uml
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.38070 seconds