| Home » Modeling » OCL » OCL Variables
 Goto Forum:| 
| OCL Variables [message #52814] | Thu, 13 March 2008 11:15  |  | 
| Eclipse User  |  |  |  |  | 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 11:44   |  | 
| Eclipse User  |  |  |  |  | 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 #52897 is a reply to message #52870] | Thu, 13 March 2008 14:42  |  | 
| Eclipse User  |  |  |  |  | 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.
 |  |  |  | 
 
 
 Current Time: Fri Oct 31 02:17:36 EDT 2025 
 Powered by FUDForum . Page generated in 0.03380 seconds |