Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Package as Ocl Context
Package as Ocl Context [message #894051] Fri, 06 July 2012 13:48 Go to next message
fv fv is currently offline fv fv
Messages: 19
Registered: April 2012
Junior Member
Hi,

up to now I'm using a function parseOCL(org.eclipse.uml2.uml.Class c, java.lang.String s) which parses an OCL Constraint.
The body of this function consists basically of the following lines:

oclhelper.setContext(c);
constraint = (Constraint)oclhelper.createInvariant(s);

Now, I have an OCL Constraint which uses several classes (let's say A and B) which are not connected through an association. The constraint has the following expression:
A.id + B.id >= 0

Is it possible to parse such an OCL Constraint?
What do I have to give setContext() as parameter? If I use Class A as parameter, the raised error tells me:
Unrecognized Variable(id)
which is correct because Class A can't see B.id (because of the missing association)

I'm wondering if it's possible to call setContext with the package which contains the classes (A and B in the example) but I get the following error:

java.lang.ClassCastException: org.eclipse.uml2.uml.internal.impl.PackageImpl cannot be cast to org.eclipse.uml2.uml.Classifier
	at org.eclipse.ocl.uml.internal.UMLReflectionImpl.asOCLType(UMLReflectionImpl.java:1)
	at org.eclipse.ocl.AbstractEnvironmentFactory.createClassifierContext(AbstractEnvironmentFactory.java:135)
	at org.eclipse.ocl.internal.helper.OCLHelperImpl.setContext(OCLHelperImpl.java:119)


Is there a possiblity to parse such a Constraint?

Thank's!
Re: Package as Ocl Context [message #894169 is a reply to message #894051] Sat, 07 July 2012 08:58 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4046
Registered: July 2009
Senior Member
Hi

What you pass as the context determines the 'self' object. If you don't
need a self you can use any old object. The newer code allows you to
pass null.

Your A.id + B.id >= 0 example makes little sense since you seem to
confuse classes and instances. It seems you want two self instances
without any idea as to where they come from. Perhaps you want a two
argument operation returning true/false.

Regards

Ed Willink


On 06/07/2012 14:48, fv fv wrote:
> Hi,
>
> up to now I'm using a function parseOCL(org.eclipse.uml2.uml.Class c,
> java.lang.String s) which parses an OCL Constraint.
> The body of this function consists basically of the following lines:
>
> oclhelper.setContext(c);
> constraint = (Constraint)oclhelper.createInvariant(s);
> Now, I have an OCL Constraint which uses several classes (let's say A
> and B) which are not connected through an association. The constraint
> has the following expression:
> A.id + B.id >= 0
>
> Is it possible to parse such an OCL Constraint?
> What do I have to give setContext() as parameter? If I use Class A as
> parameter, the raised error tells me:
> Unrecognized Variable(id)
> which is correct because Class A can't see B.id (because of the
> missing association)
>
> I'm wondering if it's possible to call setContext with the package
> which contains the classes (A and B in the example) but I get the
> following error:
>
> java.lang.ClassCastException:
> org.eclipse.uml2.uml.internal.impl.PackageImpl cannot be cast to
> org.eclipse.uml2.uml.Classifier
> at
> org.eclipse.ocl.uml.internal.UMLReflectionImpl.asOCLType(UMLReflectionImpl.java:1)
> at
> org.eclipse.ocl.AbstractEnvironmentFactory.createClassifierContext(AbstractEnvironmentFactory.java:135)
> at
> org.eclipse.ocl.internal.helper.OCLHelperImpl.setContext(OCLHelperImpl.java:119)
>
> Is there a possiblity to parse such a Constraint?
>
> Thank's!
Re: Package as Ocl Context [message #895296 is a reply to message #894051] Thu, 12 July 2012 11:56 Go to previous message
fv fv is currently offline fv fv
Messages: 19
Registered: April 2012
Junior Member
Hi,

I've resolved the problem by using allInstances() because I don't need a concrete object. Now it works, thank's for your help!
Previous Topic:OCL: Iterate over code lines
Next Topic:Referencing to OCL constraint
Goto Forum:
  


Current Time: Tue Sep 23 18:32:38 GMT 2014

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

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