Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Validating OCL in EMF - RCP(OCL and RCP)
Validating OCL in EMF - RCP [message #1111599] Wed, 18 September 2013 08:43 Go to next message
Leo Sugianto is currently offline Leo Sugianto
Messages: 2
Registered: September 2013
Junior Member
Hi,

I'm creating my EMF and use the RCP as a runtime. In my simple model, I added my simple constraint in ecore file (OCLinEcore) and try validating it using dynamic instance and it works. But when I run it as RCP and try validating my OCL, it gives me an error:
"Unable to find delegate to evaluate the '...' constraint on '...': http://www.eclipse.org/emf/2002/Ecore/OCL"

After I look around for a while, I find http://wiki.eclipse.org/MDT/OCL/FAQ#Embedded_OCL_Issues and I add these lines into my source code, in the EditorAdvisor class, inside initialize method:
String oclDelegateURI = OCLDelegateDomain.OCL_DELEGATE_URI;
EOperation.Internal.InvocationDelegate.Factory.Registry.INSTANCE.put(oclDelegateURI,
    new OCLInvocationDelegateFactory.Global());
EStructuralFeature.Internal.SettingDelegate.Factory.Registry.INSTANCE.put(oclDelegateURI,
    new OCLSettingDelegateFactory.Global());
EValidator.ValidationDelegate.Registry.INSTANCE.put(oclDelegateURI,
    new OCLValidationDelegateFactory.Global());

But it's still not working. Obviously I'm missing something here, but couldn't find what to do to solve this.
This kind of question might have been asked by someone else before, if it has, I didn't find the exact post. I'll be glad if someone could pinpoint that post or other tutorial that solve problem like mine. I've also attached my code here in case if someone is willing to look at it and point me exactly where I'm missing.

Thanks,
Leo
  • Attachment: Library.rar
    (Size: 157.84KB, Downloaded 22 times)
Re: Validating OCL in EMF - RCP [message #1111744 is a reply to message #1111599] Wed, 18 September 2013 13:19 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4014
Registered: July 2009
Senior Member
Hi

Hqave you lookd at the standalone sections in the OCL documentation.
These may have been revised more recently that the FAQ.

Regards

Ed Willink

On 18/09/2013 18:12, Leo Sugianto wrote:
> Hi,
>
> I'm creating my EMF and use the RCP as a runtime. In my simple model, I added my simple constraint in ecore file (OCLinEcore) and try validating it using dynamic instance and it works. But when I run it as RCP and try validating my OCL, it gives me an error:
> "Unable to find delegate to evaluate the '...' constraint on '...': http://www.eclipse.org/emf/2002/Ecore/OCL"
> After I look around for a while, I find http://wiki.eclipse.org/MDT/OCL/FAQ#Embedded_OCL_Issues and I add these lines into my source code, in the EditorAdvisor class, inside initialize method:
> String oclDelegateURI = OCLDelegateDomain.OCL_DELEGATE_URI;
> EOperation.Internal.InvocationDelegate.Factory.Registry.INSTANCE.put(oclDelegateURI,
> new OCLInvocationDelegateFactory.Global());
> EStructuralFeature.Internal.SettingDelegate.Factory.Registry.INSTANCE.put(oclDelegateURI,
> new OCLSettingDelegateFactory.Global());
> EValidator.ValidationDelegate.Registry.INSTANCE.put(oclDelegateURI,
> new OCLValidationDelegateFactory.Global());
> But it's still not working. Obviously I'm missing something here, but couldn't find what to do to solve this.
> This kind of question might have been asked by someone else before, if it has, I didn't find the exact post. I'll be glad if someone could pinpoint that post or other tutorial that solve problem like mine. I've also attached my code here in case if someone is willing to look at it and point me exactly where I'm missing.
>
> Thanks,
> Leo
Re: Validating OCL in EMF - RCP [message #1112295 is a reply to message #1111744] Thu, 19 September 2013 07:37 Go to previous messageGo to next message
Leo Sugianto is currently offline Leo Sugianto
Messages: 2
Registered: September 2013
Junior Member
Hi Ed,

Thank for the reply even though it is not a bug or something like that, I appreciate it Smile
I searched for OCL documentation like you suggested but couldn't understand how to implement those in my code.

However, after looking around little bit further, I found the source code that I'm looking for.
For those who are having the same issue with mine, here is my implementation in EditorAdvisor.java:
//import org.eclipse.ocl.ecore.delegate.*; << Do not use this one
import org.eclipse.ocl.examples.pivot.delegate.*; // Use this one instead

public void initialize(IWorkbenchConfigurer configurer) {
		super.initialize(configurer);
		configurer.setSaveAndRestore(true);		
		//***************** OCL ******************/	
		// register Pivot globally (resourceSet == null)
		org.eclipse.ocl.examples.pivot.OCL.initialize(null);

		String oclDelegateURI = OCLDelegateDomain.OCL_DELEGATE_URI_PIVOT;
		EOperation.Internal.InvocationDelegate.Factory.Registry.INSTANCE.put(oclDelegateURI,
		    new OCLInvocationDelegateFactory.Global());
		EStructuralFeature.Internal.SettingDelegate.Factory.Registry.INSTANCE.put(oclDelegateURI,
		    new OCLSettingDelegateFactory.Global());
		EValidator.ValidationDelegate.Registry.INSTANCE.put(oclDelegateURI,
		    new OCLValidationDelegateFactory.Global());
		
		OCLinEcoreStandaloneSetup.doSetup();
		// install the OCL standard library
		OCLstdlib.install();
}

And add the dependencies in plugin.xml
org.eclipse.ocl.examples.xtext.oclinecore
//You might need to add other dependencies:
org.eclipse.ocl.examples
org.eclipse.ocl.examples.pivot

Adding that code should allow your RCP to validate the OCL properly.

Cheers,
Leo
Re: Validating OCL in EMF - RCP [message #1112334 is a reply to message #1112295] Thu, 19 September 2013 08:56 Go to previous message
Ed Willink is currently offline Ed Willink
Messages: 4014
Registered: July 2009
Senior Member
Hi

Thanks for sharing this. It makes it clear that the current init is
unhelpful.

You should find that the seven delegate lines are done by
OCLDelegateDomain.initialize(null); which reduces the OCL init to four
lines.

The first two can easily done by XXXStandaloneSetup.

OCLstdlib.install() is separate to allow users to provide an alternate
library; an irritating flexibility for most users. I'll see if
XXXStandaloneSetup can do OCLstdlib.install() automatically unless a
prior user registration has already been made.

See https://bugs.eclipse.org/bugs/show_bug.cgi?id=417587

Regards

Ed Willink


On 19/09/2013 12:37, Leo Sugianto wrote:
> Hi Ed,
>
> Thank for the reply even though it is not a bug or something like
> that, I appreciate it :) I searched for OCL documentation like you
> suggested but couldn't understand how to implement those in my code.
>
> However, after looking around little bit further, I found the source
> code that I'm looking for.
> For those who are having the same issue with mine, here is my
> implementation in EditorAdvisor.java:
> //import org.eclipse.ocl.ecore.delegate.*; << Do not use this one
> import org.eclipse.ocl.examples.pivot.delegate.*; // Use this one instead
> public void initialize(IWorkbenchConfigurer configurer) {
> super.initialize(configurer);
> configurer.setSaveAndRestore(true);
> //***************** OCL ******************/
> // register Pivot globally (resourceSet == null)
> org.eclipse.ocl.examples.pivot.OCL.initialize(null);
>
> String oclDelegateURI = OCLDelegateDomain.OCL_DELEGATE_URI_PIVOT;
> EOperation.Internal.InvocationDelegate.Factory.Registry.INSTANCE.put(oclDelegateURI,
> new OCLInvocationDelegateFactory.Global());
> EStructuralFeature.Internal.SettingDelegate.Factory.Registry.INSTANCE.put(oclDelegateURI,
> new OCLSettingDelegateFactory.Global());
> EValidator.ValidationDelegate.Registry.INSTANCE.put(oclDelegateURI,
> new OCLValidationDelegateFactory.Global());
>
> OCLinEcoreStandaloneSetup.doSetup();
> // install the OCL standard library
> OCLstdlib.install();
> }
> And add the dependencies in plugin.xml
>
> org.eclipse.ocl.examples.xtext.oclinecore
> //You might need to add other dependencies:
> org.eclipse.ocl.examples
> org.eclipse.ocl.examples.pivot
> Adding that code should allow your RCP to validate the OCL properly.
>
> Cheers,
> Leo
Previous Topic:Traversing AST nodes of an OCL constraint programatically
Next Topic:Visiting OCL: Getting the Ecore element related to a Pivot typed element
Goto Forum:
  


Current Time: Wed Jul 30 19:34:24 EDT 2014

Powered by FUDForum. Page generated in 0.03468 seconds