Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Extending the OCL Standard Library (and using that in the CompleteOCL editor)
Extending the OCL Standard Library (and using that in the CompleteOCL editor) [message #1387764] Wed, 25 June 2014 15:03 Go to next message
Olivier Melois is currently offline Olivier MeloisFriend
Messages: 14
Registered: March 2012
Junior Member
Hello.

I'm trying to figure out how to extend the OCL Standard Library to add some operations (implemented in Java). These additional operations should be usable within the CompleteOCL editor.

From what I gathered, it should be doable by creating a "oclstdlib" source, linking to the correct java implementations, compiling the library using the org.eclipse.ocl.examples.build plugin.

But once this is done, is there a way to programmatically specify that my operations should be loaded aside the default standard library, or should I use the MetamodelManager#setDefaultStandardLibraryURI to replace the original one with my own ? (that would suggest specifying that my library is an extension of the original one).

Regards
Re: Extending the OCL Standard Library (and using that in the CompleteOCL editor) [message #1387931 is a reply to message #1387764] Wed, 25 June 2014 20:01 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

There is no need to compile your library (though it will run faster).

There is no documentation on this yet.

See
org.eclipse.ocl.examples.test.xtext.ImportTests.testImport_CompleteOCL_custom_OCLstdlib()

Regards

Ed Willink

On 25/06/2014 16:03, Olivier Melois wrote:
> Hello.
>
> I'm trying to figure out how to extend the OCL Standard Library to add
> some operations (implemented in Java). These additional operations
> should be usable within the CompleteOCL editor.
>
> From what I gathered, it should be doable by creating a "oclstdlib"
> source, linking to the correct java implementations, compiling the
> library using the org.eclipse.ocl.examples.build plugin.
> But once this is done, is there a way to programmatically specify that
> my operations should be loaded aside the default standard library, or
> should I use the MetamodelManager#setDefaultStandardLibraryURI to
> replace the original one with my own ? (that would suggest specifying
> that my library is an extension of the original one).
> Regards
Re: Extending the OCL Standard Library (and using that in the CompleteOCL editor) [message #1391133 is a reply to message #1387931] Mon, 30 June 2014 13:44 Go to previous messageGo to next message
Olivier Melois is currently offline Olivier MeloisFriend
Messages: 14
Registered: March 2012
Junior Member
Hello again. Thank you for the tip, I think I'm on the right path but still require some help : my custom operation has to be packaged in a plugin so it can to be called by the user of the CompleteOCL editor.

What I did was implementing a org.eclipse.ocl.examples.pivot.library.StandardLibraryContribution in order to create an extension for the org.eclipse.ocl.examples.pivot.standard_library extension point. My #getResource Method looks like this :
	@Override
	public Resource getResource() {
		if(resource == null) {
			URI libraryURI = URI.createPlatformPluginURI(MyPlugin.PLUGIN_ID + "/resources/myLib.oclstdlib", true);
			MetaModelManager metaModelManager = new MetaModelManager();
			ResourceSet resourceSet = new ResourceSetImpl();
			MetaModelManagerResourceSetAdapter.getAdapter(resourceSet, metaModelManager);
			BaseCSResource xtextResource = (BaseCSResource)resourceSet.getResource(libraryURI, true);
			CS2PivotResourceAdapter adapter = xtextResource.getCS2ASAdapter(metaModelManager);
			resource = adapter.getASResource(xtextResource);
		}
		return resource;
	}



myLib.oclstdlib looks like that :

import 'http://www.eclipse.org/ocl/3.1.0/OCL.oclstdlib'; 

library lib : lib = 'http://www.eclipse.org/ocl/3.1.0/OCL.oclstdlib'
{

	type OCLElement
	{
		operation testOperation(arg : String) : Set(OclElement)
		=> 'myJavaPackage.OclInvReferencesOperation';
	}
}



(the goal is of course to provide the user with an operation allowing the inverse navigation through references pointing to the context element. I thought about adding it to the OCLElement type as it would go with the oclContents operation. However, when I reference this library at runtime in my ocl source file (using the CompleteOCL editor), I get the following error message :

- No 'OclInvalid' type in the OCL Standard Library
- Unresolved library 'http://myLibrary'
: No 'OclAny' type in the OCL Standard Library

Could you give me some pointers on what I should do ?

Re: Extending the OCL Standard Library (and using that in the CompleteOCL editor) [message #1391220 is a reply to message #1391133] Mon, 30 June 2014 15:55 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You give me nothing to download and play with, but guessing

No 'OclAny' type in the OCL Standard Library

beans you have a standard library without an OclAny type, which would be
consistent with your library displacing rather than augmenting the basic
standard library.

I think that changing

library lib : lib = 'http://www.eclipse.org/ocl/3.1.0/OCL.oclstdlib'

to

library lib

should make it clear that you are extending.

or

library lib : lib = 'http://myLibrary'

will make it clear that you are defining a new library.

Regards

Ed Willink


On 30/06/2014 14:44, Olivier Melois wrote:
> Hello again. Thank you for the tip, I think I'm on the right path but
> still require some help : my custom operation has to be packaged in a
> plugin so it can to be called by the user of the CompleteOCL editor.
> What I did was implementing a
> org.eclipse.ocl.examples.pivot.library.StandardLibraryContribution in
> order to create an extension for the
> org.eclipse.ocl.examples.pivot.standard_library extension point. My
> #getResource Method looks like this :
> @Override
> public Resource getResource() {
> if(resource == null) {
> URI libraryURI =
> URI.createPlatformPluginURI(MyPlugin.PLUGIN_ID +
> "/resources/myLib.oclstdlib", true);
> MetaModelManager metaModelManager = new MetaModelManager();
> ResourceSet resourceSet = new ResourceSetImpl();
> MetaModelManagerResourceSetAdapter.getAdapter(resourceSet,
> metaModelManager);
> BaseCSResource xtextResource =
> (BaseCSResource)resourceSet.getResource(libraryURI, true);
> CS2PivotResourceAdapter adapter =
> xtextResource.getCS2ASAdapter(metaModelManager);
> resource = adapter.getASResource(xtextResource);
> }
> return resource;
> }
>
>
>
> myLib.oclstdlib looks like that :
>
> import 'http://www.eclipse.org/ocl/3.1.0/OCL.oclstdlib';
> library lib : lib = 'http://www.eclipse.org/ocl/3.1.0/OCL.oclstdlib'
> {
>
> type OCLElement
> {
> operation testOperation(arg : String) : Set(OclElement)
> => 'myJavaPackage.OclInvReferencesOperation';
> }
> }
>
>
>
> (the goal is of course to provide the user with an operation allowing
> the inverse navigation through references pointing to the context
> element. I thought about adding it to the OCLElement type as it would
> go with the oclContents operation. However, when I reference this
> library at runtime in my ocl source file (using the CompleteOCL
> editor), I get the following error message :
> - No 'OclInvalid' type in the OCL Standard Library
> - Unresolved library 'http://myLibrary'
> : No 'OclAny' type in the OCL Standard Library
> Could you give me some pointers on what I should do ?
>
Re: Extending the OCL Standard Library (and using that in the CompleteOCL editor) [message #1391228 is a reply to message #1391133] Mon, 30 June 2014 16:11 Go to previous messageGo to next message
Olivier Melois is currently offline Olivier MeloisFriend
Messages: 14
Registered: March 2012
Junior Member
Okay I've figured that I should import both the standard library and my library in the CompleteOCL (I supposed that the standard one was always imported).

library 'http://www.eclipse.org/ocl/3.1.0/OCL.oclstdlib'
library 'http://myLibrary/lib.oclstdlib'

However, now I've got the following issues : apparently I cannot add an operation to OclElement. Indeed, creating such an operation triggers the following error in my CompleteOCL file :

 java.lang.IllegalStateException: Inheritance loop for 
  UML::Element


so I'm working around and added an operation to OclAny instead. My CompleteOCL regognize the static call and therefore compiles. However, the operation does not execute : the call to
dynamicSourceType.lookupImplementation(metaModelManager, staticOperation) returns a UnsupportedException. So I've looked at the Resource I return in my Library Loader and my Operation (the new one, owned by OclAny) does not have its "implementation" property set, nor its "implementationClass", which might be the problem. Should I set these manually or is there a better way to load my library ?

Regards

Re: Extending the OCL Standard Library (and using that in the CompleteOCL editor) [message #1391229 is a reply to message #1391220] Mon, 30 June 2014 16:13 Go to previous messageGo to next message
Olivier Melois is currently offline Olivier MeloisFriend
Messages: 14
Registered: March 2012
Junior Member
Ed Willink wrote on Mon, 30 June 2014 11:55
Hi

You give me nothing to download and play with, but guessing



I'm gonna go ahead and upload a test plugin.
Re: Extending the OCL Standard Library (and using that in the CompleteOCL editor) [message #1391241 is a reply to message #1391229] Mon, 30 June 2014 16:34 Go to previous messageGo to next message
Olivier Melois is currently offline Olivier MeloisFriend
Messages: 14
Registered: March 2012
Junior Member
There you go :

https://github.com/Baccata/TestsAndBugs

If you execute the "OperationExecutionTest" as a JUnit plug-in test, an UnsupportedOperationException should occur, though the CustomOperation class seems to be well referenced in the test.oclstdlib library.





Re: Extending the OCL Standard Library (and using that in the CompleteOCL editor) [message #1392408 is a reply to message #1391241] Wed, 02 July 2014 09:32 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Thanks an excellent repro; saves me a lot of time.

The first problem is that you have ignored error messages or rather
OCL.parse(URI) has hidden them; see
https://bugs.eclipse.org/bugs/show_bug.cgi?id=438695.

That solved, your example seems resistant to working. I could just
observe that custom libraries have never been written up with an
example, so they are just something that could work. However I'll see
what is adrift, since indeed they should work. Almost certainly going to
need a bug fix, though there might be a workaround.

Regards

Ed Willink


On 30/06/2014 17:34, Olivier Melois wrote:
> There you go :
> https://github.com/Baccata/TestsAndBugs
>
> If you execute the "OperationExecutionTest" as a JUnit plug-in test,
> an UnsupportedOperationException should occur, though the
> CustomOperation class seems to be well referenced in the
> test.oclstdlib library.
>
>
>
>
>
Re: Extending the OCL Standard Library (and using that in the CompleteOCL editor) [message #1392471 is a reply to message #1392408] Wed, 02 July 2014 11:36 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

On 02/07/2014 10:32, Ed Willink wrote:
>
> That solved, your example seems resistant to working.

Responded too soon.

Your test() method is declared as test(String) but you invoke test(true).

You need to export your OCL custom methods package to the classpath.

The Pivot OCL Open Class/Package extension philosophy of merge by
colliding nsURI seems to work fine.

So in the test.oclstdlib

import 'http://www.eclipse.org/ocl/3.1.0/OCL.oclstdlib';
library lib : lib = 'http://www.eclipse.org/ocl/3.1.0/OCL.oclstdlib'

the "import" imports the normal OCL Standard Library
the "library" declares a new library that merges with the same nsURI

And in the test.ocl

library 'test.oclstdlib'

the "library" imports your custom library (and the standard library)

However this only works at edit-time. The corresponding Xtext support at
run-time is missing.
See https://bugs.eclipse.org/bugs/show_bug.cgi?id=438717.

Sorry. This means that with today's code you must code generate a custom
OCL Standard Library, which probably requires a couple of minor
adjustments to

/org.eclipse.ocl.examples.build/src/org/eclipse/ocl/examples/build/GenerateOCLstdlibModel.mwe2

Regards

Ed Willink
Previous Topic:Best way for evaluating an operation with parameters
Next Topic:OCL for defining attribute facet
Goto Forum:
  


Current Time: Tue Mar 19 06:05:04 GMT 2024

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

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

Back to the top