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

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.

I understand that the problem is with this line:
oclHelper.setInstanceContext(ce);
Because it sets uml:Class context instead of Person. And uml:Class doesn't have age property. But I don't understand how to fix it.

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:

Also I tried to transform generated Ecore-file (with parsed OCL-expressions) by QVTo. When I'm trying to add a metamodel mapping (in project settings) for my Ecore-file, it shows me an error:
Failed to load metamodel from 'platform:/resource/OclToXmi/output/parsedOcl.ecore'

Sorry for flood. Actually my main purpose is to write a QVTo-transformation. And QVTo supports my Pivot-model like a charm. I think I need to dive deeper into the problem to ask a more concrete questions.

Excuse me for noninformative messages. Here is a sample project. I run NewTransformation.qvto from Eclipse with a following input:
platform:/resource/TransformOcl/transforms/parsedOcl.ecore
and fake output:
platform:/resource/TransformOcl/transforms/result.ecore

In a standalone mode it gets all OCL rules from model/OclTest.uml and transforms them into corresponding XPath expressions stored in result.ecore and result.xpath2. And everithing works fine! You can see 'Real.>=(OclSelf) : Boolean' in a result file. References to oclstdlib are resolved.

But If you run transforms/OclToXpath.qvto from Eclipse with output/parsedOcl.ecore as input model and with result2.ecore as output model, you will see that the later one contains 'null() : &quot;&lt;null>&quot;'. It's unable to resolve oclstdlib references.

I will use the transformation in a standalone mode, but I need to debug it in Eclipse during development. Is it possible to make it work in Eclipse?

so the problem may be in the encoding. EMF does not waste time encoding
xmi:id's since application code is expected to get them right. I
certainly did not intend to have % values so I need to revisit the
xmi:id generator. https://bugs.eclipse.org/bugs/show_bug.cgi?id=422777
raised.

(Until recently serialisation of the OCLAS was a much greater disaster.)

Regards

Ed Willink

On 28/11/2013 06:42, Denis Nikiforov wrote:
> Hi
>
> Here is another test project:
> https://github.com/AresEkb/OclToXPath
> (also you need https://github.com/AresEkb/EMFTextXPath2)
>
> In a standalone mode it gets all OCL rules from model/OclTest.uml and
> transforms them into corresponding XPath expressions stored in
> result.ecore and result.xpath2. And everithing works fine! You can see
> 'Real.>=(OclSelf) : Boolean' in a result file. References to oclstdlib
> are resolved.
>
> But If you run transforms/OclToXpath.qvto from Eclipse with
> output/parsedOcl.ecore as input model and with result2.ecore as output
> model, you will see that the later one contains 'null() : "<null>"'.
> It's unable to resolve oclstdlib references.
>
> I will use the transformation in a standalone mode, but I need to
> debug it in Eclipse during development. Is it possible to make it work
> in Eclipse?

The strange thing is that it resolves operations only during first run! If you'll run it again, it won't resolve operations until you restart Eclipse. Maybe this problem is specific for my Eclipse installation only...

And also it doesn't resolve properties and variables:
../model/OclTest.uml.oclas#//@nestedPackage.0/@nestedPackage.0/@ownedType.1/@ownedAttribute.1

I don't have plugins ion C:/Work. If you configure your project as an
Eclipse plugibn, it will sort everything out for you in the MANIFEST.mf.

First run only sounds like someone unloaded the library after the first
run and so emptied it. Shared Java-defined resources should not be put
into ResourceSets that unload when done.

Regards

Ed Willink

On 29/11/2013 06:53, Denis Nikiforov wrote:
> Thanks!
>
> I fixed the code and now it serializes OCL into
> output/parsedOcl.ecore.oclas.
> Also I added a transforms/Test.qvto to simplify testing.
> https://github.com/AresEkb/OclToXPath
>
> The strange thing is that it resolves operations only during first
> run! If you'll run it again, it won't resolve operations until you
> restart Eclipse. Maybe this problem is specific for my Eclipse
> installation only...
>
> And also it doesn't resolve properties and variables:
> ../model/OclTest.uml.oclas#//@nestedPackage.0/@nestedPackage.0/@ownedType.1/@ownedAttribute.1
>