Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » OCL Variables
OCL Variables [message #52814] Thu, 13 March 2008 15:15 Go to next message
Eclipse UserFriend
Originally posted by: x.maysonnave.gmail.com

Hi,

I'm implementing some support for OCL variables in our tool.
The idea is the folowing, I have defined an emf model with two kinds of
OCL objects. OCLCondition and OCLVariables. In the OCLConditon you specify
the context and the body of your statement while you define variables with
OCLVariables. I try to use emf validation facilities to validate the ocl
query. It means that this validation occur at the M2 level.
Here is the problem :
Let's say that you define a variable _name_ with the folowing type
EcorePackage.Literals.ESTRING
Here is the body : self.title <> _name_
the context is Book (extlibrary)
While validating

OCL ocl = OCL.newInstance();
Environment env = ocl.getEnvironment();
Variable<EClassifier, EParameter> var =
env.getOCLFactory().createVariable();
var.setName("_name_");
var.setType(EcorePackage.Literals.ESTRING);
env.addElement(name, var, true);
BooleanOCLCondition consition = new BooleanOCLConsition(env, body,
context);

I got the folowing error :

org.eclipse.ocl.SemanticException: Type mismatch. No common supertype:
(String), (EString)

I'm stuck on this one.

Thanks.
Re: OCL Variables [message #52843 is a reply to message #52814] Thu, 13 March 2008 15:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Maysonnave,

This same problem actually was raised in this newsgroup just recently, in
the "EClassifier for primitive variables" thread.

The OCL parser automatically maps certain of the Ecore data types to OCL's
corresponding pre-defined primitive types when introspecting features of
model classes. So, for example, an EOperation parameter of type EString in
your model is re-interpreted as type String from the OCL Standard Library.

The same mapping is not performed for Variables, because these cannot occur
in the models in which context an OCL expression is defined: Variables are
not model elements, but only elements of the OCL syntax.

So, you will have to assign the OCL String type to your variable, instead.
Try this:

OCL ocl = OCL.newInstance();
Environment env = ocl.getEnvironment();
Variable<EClassifier, EParameter> var =
env.getOCLFactory().createVariable();
var.setName("_name_");
var.setType(env.getOCLStandardLibrary().getString());
env.addElement(name, var, true);
BooleanOCLCondition consition = new BooleanOCLConsition(
env, body, context);


HTH,

Christian

Maysonnave wrote:

> Hi,
>
> I'm implementing some support for OCL variables in our tool.
> The idea is the folowing, I have defined an emf model with two kinds of
> OCL objects. OCLCondition and OCLVariables. In the OCLConditon you specify
> the context and the body of your statement while you define variables with
> OCLVariables. I try to use emf validation facilities to validate the ocl
> query. It means that this validation occur at the M2 level.
> Here is the problem :
> Let's say that you define a variable _name_ with the folowing type
> EcorePackage.Literals.ESTRING
> Here is the body : self.title <> _name_
> the context is Book (extlibrary)
> While validating
>
> OCL ocl = OCL.newInstance();
> Environment env = ocl.getEnvironment();
> Variable<EClassifier, EParameter> var =
> env.getOCLFactory().createVariable();
> var.setName("_name_");
> var.setType(EcorePackage.Literals.ESTRING);
> env.addElement(name, var, true);
> BooleanOCLCondition consition = new BooleanOCLConsition(env, body,
> context);
>
> I got the folowing error :
>
> org.eclipse.ocl.SemanticException: Type mismatch. No common supertype:
> (String), (EString)
>
> I'm stuck on this one.
>
> Thanks.
Re: OCL Variables [message #52870 is a reply to message #52843] Thu, 13 March 2008 16:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: x.maysonnave.gmail.com

Hi,

Thanks for your reply.
I have found this thread and got some clues to solve my issues.
If I understand well, for all the standard library defined primitives
- boolean, real, integer and string I need to use them.
for other types of variables I am free to use ecore literal types
- eclass, eobject, epackage, edate, etc...

Thanks.
Re: OCL Variables [message #52897 is a reply to message #52870] Thu, 13 March 2008 18:42 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Xavier,

Yes, that's basically right. You can simplify the process, however, by
letting the environment determine for you the appropriate mapping.

I can improve on my previous revision of your code snippet:

OCL ocl = OCL.newInstance();
Environment env = ocl.getEnvironment();
Variable<EClassifier, EParameter> var =
     env.getOCLFactory().createVariable();
var.setName("_name_");
var.setType(env.getUMLReflection().asOCLType(
EcorePackage.Literals.ESTRING));
env.addElement(name, var, true);
BooleanOCLCondition consition = new BooleanOCLConsition(
     env, body, context);


The UMLReflection API encodes the knowledge of these type mappings, in
addition to the knowledge of how to introspect instances of the target
metamodel.

HTH,

Christian


Xavier Maysonnave wrote:

> Hi,
>
> Thanks for your reply.
> I have found this thread and got some clues to solve my issues.
> If I understand well, for all the standard library defined primitives
> - boolean, real, integer and string I need to use them.
> for other types of variables I am free to use ecore literal types
> - eclass, eobject, epackage, edate, etc...
>
> Thanks.
Previous Topic:Possible bug in the AbstractTypeResolver implementation
Next Topic:New to OCL - Need some Info
Goto Forum:
  


Current Time: Thu Mar 28 09:18:13 GMT 2024

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

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

Back to the top