Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » ocl constraints' expression
ocl constraints' expression [message #43734] Wed, 21 November 2007 21:09 Go to next message
Eclipse User
Originally posted by: asma.charfi.com

hello,
I have problem in ocl expressions:
in the OCL OMG Available Specification Version 2.0
http://www.cs.chalmers.se/Cs/Grundutb/Kurser/form/Papers/OCL _2.0.pdf
I saw that we can write context Person: self.age ( if age is an
attribute of the class Person)
in my constraint written in OCL using OCL 2.0 plugin I can not write this! I
should write: self.ownedAttribute->select (s|s.name='age')

some expression did not exsist in OCL specification such as
self.getAllAtributes()...or getAppliedStereotypes()... Is these expression
come from UML or EMF?
My probelm is that my constraint expression is a mix of UML, OCL, EMF... can
I write constraint only in OCL and validate them on model in eclipse?

thank you
Re: ocl constraints' expression [message #43783 is a reply to message #43734] Wed, 21 November 2007 13:03 Go to previous messageGo to next message
Eclipse User
Originally posted by: cdamus.ca.ibm.com

Hi, Asma,

I'm not entirely sure that I understood the problem. The example you cite:

context Person: self.age

is not well-formed OCL and is not in the document you reference. The only
occurrence of "self.age" is in the following on p. 15:

context Person inv:
self.age > 0

If the following parses for you:

self.ownedAttribute->select (s|s.name='age')

then you are using the wrong context classifier for parsing the expression.
You would be using the Class metaclass (from the UML metamodel), when you
really need to parse in the context of the Person class (from your model).
If you do that, you will find that "self.age > 0" works.

The getAllAttributes() and getAppliedStereotypes() operations are defined in
the UML metamodel as provided by the MDT UML2 component. If you were to
reference, instead, a metamodel that is strictly compliant with the UML
specification, then you would find that they are not available (these are
added by MDT UML2 in order to include them in the generated Java API).

Which version of MDT OCL are you using, with which metamodel binding? It
sounds like you are, perhaps, using the 1.1 or later version and using
OCLHelper::setInstanceContext(...) instead of OCLHelper::setContext(...) to
set your context classifier, hence jumping up a meta-level.

HTH,

Christian


charfi asma wrote:

> hello,
> I have problem in ocl expressions:
> in the OCL OMG Available Specification Version 2.0
> http://www.cs.chalmers.se/Cs/Grundutb/Kurser/form/Papers/OCL _2.0.pdf
> I saw that we can write context Person: self.age ( if age is an
> attribute of the class Person)
> in my constraint written in OCL using OCL 2.0 plugin I can not write this!
> I should write: self.ownedAttribute->select (s|s.name='age')
>
> some expression did not exsist in OCL specification such as
> self.getAllAtributes()...or getAppliedStereotypes()... Is these expression
> come from UML or EMF?
> My probelm is that my constraint expression is a mix of UML, OCL, EMF...
> can I write constraint only in OCL and validate them on model in eclipse?
>
> thank you
Re: ocl constraints' expression [message #43804 is a reply to message #43783] Thu, 22 November 2007 00:05 Go to previous messageGo to next message
Eclipse User
Originally posted by: asma.charfi.com

Hi Christian,

I used "mdt-ocl-SDK-1.1M7" and I add my constraint to an uml profile that I
defined alone.
as a context I put this:

if (elem instanceof EObject)
{ context = (EObject) elem;}

OCL ocl=OCL.newInstance(new MyEnvironmentFactory());


OCL.Helper helper = ocl.createOCLHelper();

helper.setContext(context.eClass()); // I think that I did
not jump a level

for exemple to get the default value of age using the interactive OCL
(Console),

when I write self.age.default, I get an error: ERROR in (variableExpCS):
(Unrecognized variable: (age))

but when I write: self.ownedAttribute->select(s|s.name='age').default it
works
thank you







"Christian W. Damus" <cdamus@ca.ibm.com> a
Re: ocl constraints' expression [message #43835 is a reply to message #43804] Wed, 21 November 2007 15:31 Go to previous messageGo to next message
Eclipse User
Originally posted by: cdamus.ca.ibm.com

Hi, Asma,

See some replies in-line, below.

HTH,

Christian


charfi asma wrote:

> Hi Christian,
>
> I used "mdt-ocl-SDK-1.1M7" and I add my constraint to an uml profile that
> I defined alone.
> as a context I put this:
>
> if (elem instanceof EObject)
> { context = (EObject) elem;}
>
> OCL ocl=OCL.newInstance(new MyEnvironmentFactory());

What is MyEnvironmentFactory? Is that a subclass of
EcoreEnvironmentFactory? If you're working with UML models (as suggested
by your previous post), then you probably should use/subclass the
UMLEnvironmentFactory.


> OCL.Helper helper = ocl.createOCLHelper();
>
> helper.setContext(context.eClass()); // I think that I did
> not jump a level

Ah, but if the "elem" is already an EClass, then you are jumping a
meta-level. EClasses are EObjects, after all. If "elem" is an EClass,
then perhaps you want it to be the context, rather than its eclass (which
ends up simply being the EClass eclass).

This is where the distinction between the setContext and setInstanceContext
methods can help. The setContext method expects a classifier (EClassifier
in the Ecore metamodel, Classifier in the UML metamodel) whereas
setInstanceContext expects an instance of a classifier (and will,
therefore, take the EClass of any EObject as the context classifier).


> for exemple to get the default value of age using the interactive OCL
> (Console),
>
> when I write self.age.default, I get an error: ERROR in (variableExpCS):
> (Unrecognized variable: (age))

This is probably because you do not have the modeling level control set to
"M1" in the console's action bar, which would use the selected classifier
in your model as the context, rather than its metaclass.


> but when I write: self.ownedAttribute->select(s|s.name='age').default it
> works

Because the console is set to "M2" in the action bar, indicating that the
expression should be parsed on the selected element's metaclass.


> thank you

-----8<-----
Re: ocl constraints' expression [message #43866 is a reply to message #43835] Thu, 22 November 2007 02:03 Go to previous messageGo to next message
Eclipse User
Originally posted by: asma.charfi.com

Hi Christian,

thank you for your help, I change to M1 and it works now.
can you explain me the difference between Metamodel (Ecore and UML) and
Modeling Level (M1 and M2) in the console action's bar?
can we put M1 with Ecore and M2 with UML and what does this mean?
thank you a lot :)

"Christian W. Damus" <cdamus@ca.ibm.com> a
Re: ocl constraints' expression [message #44032 is a reply to message #43866] Wed, 21 November 2007 22:35 Go to previous messageGo to next message
Eclipse User
Originally posted by: cdamus.ca.ibm.com

Hi, Asma,

M1 and M2 are conventional names for two of the modeling levels in the OMG's
four-level modeling stack.

Objects in the M0 level are the objects in the system being modeled.

Objects in the M1 level are the elements of the model of the system. These
are elements in your UML model.

Objects in the M2 level are the metaclasses in the metamodel of which the M1
model is an instance. i.e., these are the metaclasses of the UML
metamodel.

Objects in the M3 level are the meta-metaclasses in the meta-metamodel that
describea your metamodel. For UML, this meta-metamodel is basically MOF.
In the MDT OCL and UML2 implementations, it is Ecore.

The metamodel control in the console selects which metamodel binding
(org.eclipse.ocl.ecore or org.eclipse.ocl.uml) to use to parse your OCL
expressions. This is significant because these bindings have different
capabilities: the former basically corresponds to EssentialOCL and the
latter to CompleteOCL (not meaning to imply any particular compliance
statement).

So, if you are working with an Ecore model or an instance of a metamodel
that was described as an Ecore model (and generated using EMF), you want
the Ecore binding. If you are working with a UML model or an instance of a
metamodel (such as OCL, itself) that was described as a UML model (and
generated using UML2), then you want the UML binding.

Selecting the M1 modeling level lets you parse classifier invariant
constraints and operation constraints in the context of the selected
element in the editor. Selecting the M2 modeling level lets you parse and
evaluate OCL queries in the context of the metaclass of the element
selected in the editor.

HTH,

Christian

charfi asma wrote:

> Hi Christian,
>
> thank you for your help, I change to M1 and it works now.
> can you explain me the difference between Metamodel (Ecore and UML) and
> Modeling Level (M1 and M2) in the console action's bar?
> can we put M1 with Ecore and M2 with UML and what does this mean?
> thank you a lot :)
>
> "Christian W. Damus" <cdamus@ca.ibm.com> a �rit dans le message de news:
> fi1j0h$9in$1@build.eclipse.org...
>> Hi, Asma,
>>
>> See some replies in-line, below.
>>
>> HTH,
>>
>> Christian
>>
>>
>> charfi asma wrote:
>>
>>> Hi Christian,
>>>
>>> I used "mdt-ocl-SDK-1.1M7" and I add my constraint to an uml profile
>>> that
>>> I defined alone.
>>> as a context I put this:
>>>
>>> if (elem instanceof EObject)
>>> { context = (EObject) elem;}
>>>
>>> OCL ocl=OCL.newInstance(new MyEnvironmentFactory());
>>
>> What is MyEnvironmentFactory? Is that a subclass of
>> EcoreEnvironmentFactory? If you're working with UML models (as suggested
>> by your previous post), then you probably should use/subclass the
>> UMLEnvironmentFactory.
>>
>>
>>> OCL.Helper helper = ocl.createOCLHelper();
>>>
>>> helper.setContext(context.eClass()); // I think that I
>>> did
>>> not jump a level
>>
>> Ah, but if the "elem" is already an EClass, then you are jumping a
>> meta-level. EClasses are EObjects, after all. If "elem" is an EClass,
>> then perhaps you want it to be the context, rather than its eclass (which
>> ends up simply being the EClass eclass).
>>
>> This is where the distinction between the setContext and
>> setInstanceContext
>> methods can help. The setContext method expects a classifier
>> (EClassifier in the Ecore metamodel, Classifier in the UML metamodel)
>> whereas setInstanceContext expects an instance of a classifier (and will,
>> therefore, take the EClass of any EObject as the context classifier).
>>
>>
>>> for exemple to get the default value of age using the interactive OCL
>>> (Console),
>>>
>>> when I write self.age.default, I get an error: ERROR in
>>> (variableExpCS): (Unrecognized variable: (age))
>>
>> This is probably because you do not have the modeling level control set
>> to "M1" in the console's action bar, which would use the selected
>> classifier in your model as the context, rather than its metaclass.
>>
>>
>>> but when I write: self.ownedAttribute->select(s|s.name='age').default
>>> it works
>>
>> Because the console is set to "M2" in the action bar, indicating that the
>> expression should be parsed on the selected element's metaclass.
>>
>>
>>> thank you
>>
>> -----8<-----
Re: ocl constraints' expression [message #44120 is a reply to message #44032] Thu, 22 November 2007 07:51 Go to previous message
Eclipse User
Originally posted by: asma.charfi.com

HI,
well explained christian!
thanks a lot:)

"Christian W. Damus" <cdamus@ca.ibm.com> a
Previous Topic:Re: UMLEnvironmentFactory.EvaluationMode unresolved in OCL Console example
Next Topic:Bug: org.eclipse.ocl.ecore.QueryImpl breaks GC of org.eclipse.ocl.Query.evaluate(Object) breaks gene
Goto Forum:
  


Current Time: Sun Oct 26 06:04:25 GMT 2014

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

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