|
Re: Transform OCL into some text [message #1177132 is a reply to message #1176057] |
Fri, 08 November 2013 20:00 |
Denis Nikiforov Messages: 346 Registered: August 2013 |
Senior Member |
|
|
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 20:07 |
Ed Willink Messages: 7670 Registered: July 2009 |
Senior Member |
|
|
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
>
|
|
|
|
Re: Transform OCL into some text [message #1195920 is a reply to message #1195731] |
Tue, 19 November 2013 06:45 |
Denis Nikiforov Messages: 346 Registered: August 2013 |
Senior Member |
|
|
Sorry for flood. I replaced all references to org.eclipse.uml2.uml by org.eclipse.ocl.examples.pivot. And everithing works much better now! But it couldn't parse a following rule: self.driver->forAll(p|p.age >= 18)
The exception is:
org.eclipse.ocl.examples.pivot.SemanticException: Errors in 'self.driver->forAll(p|p.age >= 18)'
1: Unresolved Property 'Metaclass(OclTest::Package1::Car)::driver'
1: Unresolved Property 'OclInvalid::age'
at org.eclipse.ocl.examples.pivot.utilities.PivotUtil.checkResourceErrors(PivotUtil.java:176)
at org.eclipse.ocl.examples.pivot.context.AbstractParserContext.parse(AbstractParserContext.java:120)
at org.eclipse.ocl.examples.pivot.helper.OCLHelperImpl.createInvariant(OCLHelperImpl.java:94)
at Main.main(Main.java:64)
And also I don't understand the meaning of the following URLs in a result XMI-file:
http://www.eclipse.org/ocl/3.1.0/orphanage#//@ownedType.816
model/OclTest.uml.oclas#//@nestedPackage.0/@nestedPackage.0/@ownedType.1/@ownedAttribute.3
Where I can get http://www.eclipse.org/ocl/3.1.0/orphanage and model/OclTest.uml.oclas?
[Updated on: Tue, 19 November 2013 06:52] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05819 seconds