Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Defining helper operations in Java(using Pivot OCL)
Defining helper operations in Java [message #1770437] Fri, 11 August 2017 11:48 Go to next message
Dominik Engelhardt is currently offline Dominik EngelhardtFriend
Messages: 3
Registered: August 2017
Junior Member
Hi,

I am using the Pivot OCL interpreted by the OCLHelper from the org.eclipse.ocl.pivot (1.1.1) Plug-in to query instances of an ecore model in a Neon RCP application.
Now I want to provide a few helper operations written in Java. In Classic Ecore OCL you would create your own Environment, EvaluationEnvironment
and an EnvironmentFactory and use it to create your OCL instance.

But Pivot OCL doesn't seem to have a simmilar concept of an Environment.
There are EvaluationEnvironments and CompleteEnvironments but neither provide a way to add operations.
The EvaluationEnvironment can just be used to provide bindings for variables, it seems.

The OCL FAQ claims "You may add operations and properties directly from Java code. (More details needed.)", though.
So how would I add custom operations programmatically? Extending the OCLstdlib? It looks like that is not the right approach.
Re: Defining helper operations in Java [message #1770478 is a reply to message #1770437] Sat, 12 August 2017 08:47 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Well done for looking at the FAQ. Sorry that it is not helpful enough. At least I provided the details from my JUnit tests on how to define a custom standard library.

Unfortunately the custom OCLstdlib tutorial is still on my to-do list; https://bugs.eclipse.org/bugs/show_bug.cgi?id=415146

(I don't find OCLHelper very useful; it was created to try to immitate the Classic Ecore OCL API and in so far as it succeeds, it demonstrates how exploiting ExpressionInOCL in the API makes things more regular.)

The old Environment concept with additional operations/properties could not easily comply with the OCL specification requirement that everything be XMI serializable and that additional features be just like ordinary features. The new approach defines them all within classes and packages so that they are regular. In principle your model that needs additional facilities just imports the additional library; no Java hacking required by the caller.

If you only have a couple of helpers, it is easiest to squirrel them away in a (possibly bogus) class in one of your Ecore models. static methods now work.

If you want a serious suite of helpers such as a matrix library or a positioning library then a custom library is the way to go. Not easy, but you may avoid the difficulties that I had with a maths library since you may not be trying to offer an infix appearance.

Another easy option on my todo list is https://bugs.eclipse.org/bugs/show_bug.cgi?id=394658

If you can give me a partial repro of what you're trying to do and are prepared to work bleeding edge, I might be motivated to help.

Regards

Ed Willink
Re: Defining helper operations in Java [message #1770562 is a reply to message #1770478] Mon, 14 August 2017 13:09 Go to previous messageGo to next message
Dominik Engelhardt is currently offline Dominik EngelhardtFriend
Messages: 3
Registered: August 2017
Junior Member
Hi Ed,

thanks for the quick reply! Since I'm a little time constrained working with future bleeding edge builds
- as generous as this offer is - unfortunately is not an option at the moment. So I was thinking that adding
a few methods to one of my ecore models is the way to go.

Unfortunately I'm a little stuck here. Let me elaborate:
The helper functions I want to provide are of higher order. Speciffically I want to write a closure function with a depth parameter.
This would require a parameter of type Lambda, requiring an import of the OCL ecore model in my ecore model which
I can't seem to get to work at the moment. Then in the Java implementation the Lambda would have to be evaluated
which would be possible using the OCLHelper but somehow feels not right.

Do you have any idea on what's the best way to aproach this problem?

Best regards

Dominik
Re: Defining helper operations in Java [message #1770566 is a reply to message #1770562] Mon, 14 August 2017 13:59 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

It is possible to import standard library types such as Lambda using /org.eclipse.ocl.pivot/model-gen/oclstdlib.ecore

Explicit rather than implicit support for Lambda types and expressions is still on the GIT branch that I suspended once I chose to prioritize QVTd progress.

You seem to have an interesting example that would probably make a good regression test, so if you can formulate something simple that makes clear what you are failing to do, it might help me suggests a short term workaround, and also help in the longer term.

Instinctive workaround; pre-condition your problem,; use the standard closure; post-condition the results.

Regards

Ed Willink
Re: Defining helper operations in Java [message #1770615 is a reply to message #1770566] Tue, 15 August 2017 07:41 Go to previous messageGo to next message
Dominik Engelhardt is currently offline Dominik EngelhardtFriend
Messages: 3
Registered: August 2017
Junior Member
Hi

when I import the org.eclipse.ocl.pivot/model-gen/oclstdlib.ecore into one of my ecore models and reload my genmodel I have the choice to either reference the oclstdlib package or treat it as a root package.

In the first case I get the following exception during model generation (I guess because there is no genmodel in org.eclipse.ocl.pivot/model-gen/):
java.lang.NullPointerException
	at org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl$DependencyHelper.handle(GenPackageImpl.java:2472)
	at org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl$DependencyHelper.<init>(GenPackageImpl.java:2434)
	at org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl.prepareCache(GenPackageImpl.java:3202)
	at org.eclipse.emf.codegen.ecore.genmodel.generator.GenPackageGeneratorAdapter.doPreGenerate(GenPackageGeneratorAdapter.java:177)
	at org.eclipse.emf.codegen.ecore.generator.AbstractGeneratorAdapter.preGenerate(AbstractGeneratorAdapter.java:283)
	at org.eclipse.emf.codegen.ecore.generator.Generator.generate(Generator.java:700)
	at org.eclipse.emf.codegen.ecore.generator.Generator.generate(Generator.java:619)
	at org.eclipse.emf.mwe2.ecore.EcoreGenerator.invoke(EcoreGenerator.java:129)
	at org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkflowComponent.invoke(AbstractCompositeWorkflowComponent.java:35)
	at org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow.java:19)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:102)
	... 4 more

In the second case the oclstdlib.ecore is copied into my workspace and the whole ocl model code is generated. But then there is an IllegalStateException when creating the OCLHelper since somehow projectDescriptor.getResourceDescriptors() returns an oclstdlib.genmodel element which doesn't exist. So resourceDescriptor.getPlatformPluginURI() throws the exception. See stack trace below:
java.lang.IllegalStateException
	at org.eclipse.ocl.pivot.utilities.ClassUtil.nonNullState(ClassUtil.java:226)
	at org.eclipse.ocl.pivot.internal.resource.StandaloneProjectMap$AbstractResourceDescriptor.getPlatformPluginURI(StandaloneProjectMap.java:1456)
	at org.eclipse.ocl.pivot.internal.ecore.es2as.Ecore2AS.resolveImportURI(Ecore2AS.java:716)
	at org.eclipse.ocl.pivot.internal.ecore.es2as.Ecore2AS.loadImports(Ecore2AS.java:659)
	at org.eclipse.ocl.pivot.internal.ecore.es2as.Ecore2AS.loadImports(Ecore2AS.java:633)
	at org.eclipse.ocl.pivot.internal.ecore.es2as.Ecore2AS.getASModel(Ecore2AS.java:335)
	at org.eclipse.ocl.pivot.internal.ecore.es2as.Ecore2AS.getASOfEcore(Ecore2AS.java:357)
	at org.eclipse.ocl.pivot.internal.ecore.es2as.Ecore2AS.getCreated(Ecore2AS.java:430)
	at org.eclipse.ocl.pivot.internal.manager.PivotMetamodelManager.getASOfEcore(PivotMetamodelManager.java:818)
	at org.eclipse.ocl.pivot.internal.ecore.EcoreASResourceFactory.getASElement(EcoreASResourceFactory.java:63)
	at org.eclipse.ocl.pivot.internal.manager.PivotMetamodelManager.getASOf(PivotMetamodelManager.java:799)
	at org.eclipse.ocl.pivot.internal.helper.OCLHelperImpl.<init>(OCLHelperImpl.java:59)
	at org.eclipse.ocl.pivot.utilities.OCL.createOCLHelper(OCL.java:277)
	at de.dlr.premise.query.PivotOCLQueryInterpreter.<init>(PivotOCLQueryInterpreter.java:41)
	at premise.presentation.my.query.QueryableTree.<init>(QueryableTree.java:90)
	at premise.presentation.my.PremiseEditorMy.createPages(PremiseEditorMy.java:210)
	at org.eclipse.ui.part.MultiPageEditorPart.createPartControl(MultiPageEditorPart.java:363)
	(shortened irrelevant rcp startup trace)


Best Regards

Dominik
Re: Defining helper operations in Java [message #1770641 is a reply to message #1770615] Tue, 15 August 2017 13:59 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

There is a genmodel at /org.eclipse.ocl.pivot/model/oclstdlib.genmodel

The issues are non-trivial and so I cannot comment on the stack traces without a repro.

I note that you are using an EMF generator from MWE2. This used to crash standalone and so I developed /org.eclipse.ocl.examples.build/src/org/eclipse/ocl/examples/build/utilities/GenerateModel.java Maybe the EMF bugs I reported have now been fixed.

/org.eclipse.qvtd.cs2as.compiler.tests/src/org/eclipse/qvtd/cs2as/compiler/tests/models/example1/EnvExample1.ecore provides an example instantiation of of OCL's Collection<T>.

/org.eclipse.qvtd.build/src/org/eclipse/qvtd/build/mwe2/GenerateExample1Models.mwe2 generates Java models from it usually via /org.eclipse.qvtd.build/src/org/eclipse/qvtd/build/mwe2/GenerateTestModels.mwe2

Regards

Ed Willink
Previous Topic:checking against ecore based model
Next Topic:How to run OCL in Eclipse?
Goto Forum:
  


Current Time: Thu Mar 28 13:30:36 GMT 2024

Powered by FUDForum. Page generated in 0.53759 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top