Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » OCL constraints in profile
OCL constraints in profile [message #13757] Mon, 26 March 2007 18:28 Go to next message
Eclipse UserFriend
Originally posted by: lw_mailme_00.yahoo.com

I saw that OCL1.1M5 supports constraints on stereotypes, but I don't see
how those are used.

A minimal example: I have a profile with stereotypes A and B, both
extensions of uml::Class.
I want to add a constraint to stereotype A that should apply to all
classes in a model with applied stereotype A. Assuming the stereotyped
class has a property named ref, the constraint should check if
stereotype B is applied to the value of ref.

So applying A to a class C should essentially add a constraint to A.

Here are my questions:

- What does such a constraint look like?
- How do I evaluate it? I know that I have to write code that finds the
constraint in the profile, parses, and evaluates it. But what do I have
to do differently if the constraint is part of the stereotype and not
part of the model.

Thanks,
Lutz
Re: OCL constraints in profile [message #13783 is a reply to message #13757] Mon, 26 March 2007 19:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Lutz,

In defining a constraint in a profile, you have a couple of options (as I
see it). You can either define the constraint in the context of the
extended metaclass (in your case, Class), or you can define it in the
context of the stereotype A. To specify the contextual classifier, add
that classifier (either Class or A as the case may be) to the constraint's
constrainedElement property. In either case, be sure that the Constraint
has the <<invariant>> stereotype and that its specification is an
OpaqueExpression with language='OCL' and the body set to the boolean
constraint expression.

For the first approach (extended metaclass is the context), just formulate
the constraint as you would normally. When you need to evaluate the
constraints of your class C, you can

1. use the Element::getAppliedStereotypes() API to find the stereotypes
applied to C
2. for each Stereotype, use the getOwnedRules() method to find Constraints
3. for each <<invariant>> constraint, get the contextual classifier from
the getConstrainedElements() method
4. use the org.eclipse.ocl.uml.OCL.createOCLHelper() method to create a
parsing helper. Set its context classifier to the classifier from 3 and
invoke parseInvariant() with the OpaqueExpression's body
5. use the OCL.check() method to check the constraint on C

For the alternative, defining the constraint in the stereotype context, you
need to write the constraint from the perspective of the stereotype. So,
to access the properties of the extended model element (such as C), you
need to navigate the metaclass extension. For example:

self.base_Class.name = 'C'

(metaclass extensions are just associations, after all). The MDT OCL API
supports the evaluation of stereotype-defined constraints (where the
stereotype is the contextual classifier) on the elements to which those
stereotypes are applied, by following exactly the same procedure as I
outlined, above. For an example of this, have a look at the
org.eclipse.ocl.uml.tests.ProfilesTest JUnit test class, in particular, the
test_parseStereotypeConstraint() method.

I'm not sure how "correct" the first approach is. The context namespace of
a constraint (i.e., the element that owns it) is supposed to determine
which elements are "visible" to the OCL expression. So, perhaps, the
properties of the extended metaclass shouldn't be accessed "directly". The
second appropach ofnavigating the metaclass extension is arguably
"cleaner".

HTH,

Christian


Lutz Wrage wrote:

> I saw that OCL1.1M5 supports constraints on stereotypes, but I don't see
> how those are used.
>
> A minimal example: I have a profile with stereotypes A and B, both
> extensions of uml::Class.
> I want to add a constraint to stereotype A that should apply to all
> classes in a model with applied stereotype A. Assuming the stereotyped
> class has a property named ref, the constraint should check if
> stereotype B is applied to the value of ref.
>
> So applying A to a class C should essentially add a constraint to A.
>
> Here are my questions:
>
> - What does such a constraint look like?
> - How do I evaluate it? I know that I have to write code that finds the
> constraint in the profile, parses, and evaluates it. But what do I have
> to do differently if the constraint is part of the stereotype and not
> part of the model.
>
> Thanks,
> Lutz
Re: OCL constraints in profile [message #13802 is a reply to message #13783] Tue, 27 March 2007 13:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: lw_mailme_00.yahoo.com

Thanks, I'll try that. After reading the specs how to figure out the
semantics of stereotype constraints, it is my impression that the UML
and OCL spec have problems in this area. UML is not very clear about how
stereotypes are instantiated, and I couldn't find anything in the OCL
spec that tells how to access stereotype property values.

- Lutz


Christian W. Damus wrote, on 3/26/2007 3:01 PM:
> Hi, Lutz,
>
> In defining a constraint in a profile, you have a couple of options (as I
> see it). You can either define the constraint in the context of the
> extended metaclass (in your case, Class), or you can define it in the
> context of the stereotype A. To specify the contextual classifier, add
> that classifier (either Class or A as the case may be) to the constraint's
> constrainedElement property. In either case, be sure that the Constraint
> has the <<invariant>> stereotype and that its specification is an
> OpaqueExpression with language='OCL' and the body set to the boolean
> constraint expression.
>
> For the first approach (extended metaclass is the context), just formulate
> the constraint as you would normally. When you need to evaluate the
> constraints of your class C, you can
>
> 1. use the Element::getAppliedStereotypes() API to find the stereotypes
> applied to C
> 2. for each Stereotype, use the getOwnedRules() method to find Constraints
> 3. for each <<invariant>> constraint, get the contextual classifier from
> the getConstrainedElements() method
> 4. use the org.eclipse.ocl.uml.OCL.createOCLHelper() method to create a
> parsing helper. Set its context classifier to the classifier from 3 and
> invoke parseInvariant() with the OpaqueExpression's body
> 5. use the OCL.check() method to check the constraint on C
>
> For the alternative, defining the constraint in the stereotype context, you
> need to write the constraint from the perspective of the stereotype. So,
> to access the properties of the extended model element (such as C), you
> need to navigate the metaclass extension. For example:
>
> self.base_Class.name = 'C'
>
> (metaclass extensions are just associations, after all). The MDT OCL API
> supports the evaluation of stereotype-defined constraints (where the
> stereotype is the contextual classifier) on the elements to which those
> stereotypes are applied, by following exactly the same procedure as I
> outlined, above. For an example of this, have a look at the
> org.eclipse.ocl.uml.tests.ProfilesTest JUnit test class, in particular, the
> test_parseStereotypeConstraint() method.
>
> I'm not sure how "correct" the first approach is. The context namespace of
> a constraint (i.e., the element that owns it) is supposed to determine
> which elements are "visible" to the OCL expression. So, perhaps, the
> properties of the extended metaclass shouldn't be accessed "directly". The
> second appropach ofnavigating the metaclass extension is arguably
> "cleaner".
>
> HTH,
>
> Christian
>
>
> Lutz Wrage wrote:
>
>> I saw that OCL1.1M5 supports constraints on stereotypes, but I don't see
>> how those are used.
>>
>> A minimal example: I have a profile with stereotypes A and B, both
>> extensions of uml::Class.
>> I want to add a constraint to stereotype A that should apply to all
>> classes in a model with applied stereotype A. Assuming the stereotyped
>> class has a property named ref, the constraint should check if
>> stereotype B is applied to the value of ref.
>>
>> So applying A to a class C should essentially add a constraint to A.
>>
>> Here are my questions:
>>
>> - What does such a constraint look like?
>> - How do I evaluate it? I know that I have to write code that finds the
>> constraint in the profile, parses, and evaluates it. But what do I have
>> to do differently if the constraint is part of the stereotype and not
>> part of the model.
>>
>> Thanks,
>> Lutz
>
Re: OCL constraints in profile [message #13822 is a reply to message #13802] Tue, 27 March 2007 13:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Right, you'll find examples in the OCL specification (e.g., in
well-formedness constraints) of the following form:

context Constraint
inv: self.stereotype.name = 'invariant'

which assumes a 'stereotype' feature on UML elements that doesn't exist.
The major problem in UML is not how to define constraints in a stereotype
context, but how to find the stereotypes applied to an element. I think
OCL actually has the answer (though you won't see it in the spec). OCL
permits navigation of non-navigable association ends (this is not yet
implemented in MDT OCL). So, the way to navigate to a stereotype
application is to navigate the metaclass extension in reverse.

e.g., consider stereotype A with property foo : String extending Class in
your example. Then, you could write a constraint as follows:

context Class
inv: not self.extension_A.oclIsUndefined() implies
self.extension_A.foo = 'some text'

We use the oclIsUndefined() query to check that the stereotype A is applied,
then access its properties. This example assumes the default extension end
name as created by Eclipse UML2.

Cheers,

Christian

Lutz Wrage wrote:

> Thanks, I'll try that. After reading the specs how to figure out the
> semantics of stereotype constraints, it is my impression that the UML
> and OCL spec have problems in this area. UML is not very clear about how
> stereotypes are instantiated, and I couldn't find anything in the OCL
> spec that tells how to access stereotype property values.
>
> - Lutz
>

<snip>
Re: OCL constraints in profile [message #23371 is a reply to message #13783] Wed, 16 May 2007 10:45 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: asma.charfi.com

hi Lutz and Christian,
I want to use constraints on stereotype but I did not know how to use
getAppliedStereotypes(),getOwnedRules()....
I am a begginer in this field and I have to develop a plugin which add
constraints on profile and verify that models respect these constraints
thank you for your help
"Christian W. Damus" <cdamus@ca.ibm.com> a
Re: OCL constraints in profile [message #23626 is a reply to message #23371] Wed, 16 May 2007 13:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Asma,

Have a look at the org.eclipse.ocl.uml.tests.ProfilesTest class for examples
of how to parse constraints in a Stereotype context and evaluate them on
elements to which the Stereotype is applied.

If you are planning to use the EMF Validation framework
(org.eclipse.emf.validation) to define and invoke these constraints, then
have a look at the org.eclipse.emf.validation.examples.ocl example plug-in
in the 1.1 M7 build of EMF Validation. This demonstrates a simple
implementation of a constraint provider that loads constraints from an ocl
file, as well as usage of the default plugin.xml-based constraint provider
with OCL.

HTH,

Christian


charfi asma wrote:

> hi Lutz and Christian,
> I want to use constraints on stereotype but I did not know how to use
> getAppliedStereotypes(),getOwnedRules()....
> I am a begginer in this field and I have to develop a plugin which add
> constraints on profile and verify that models respect these constraints
> thank you for your help
> "Christian W. Damus" <cdamus@ca.ibm.com> a �rit dans le message de news:
> eu959c$ldg$1@utils.eclipse.org...
>>

<snip>
Re: OCL constraints in profile [message #23712 is a reply to message #23626] Thu, 17 May 2007 18:04 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: asma.charfi.com

Hi Christian,
concerning the ocl.eclipse.ocl.uml.tests, I generate it from OCLUML.genmodel
in plugin "org;eclipse.ocl.uml",
but I find 17 classes "AnyTypeTest.java, ExpressionOCLTest.java...."and
there is no ProfileTest class!
I used ocl 1.1M5 should I change to ocl1.1M7 and what is new in OCL 1.1M7?
thanks a lot Christian!

"Christian W. Damus" <cdamus@ca.ibm.com> a
Re: OCL constraints in profile [message #23796 is a reply to message #23712] Thu, 17 May 2007 12:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Asma,

I did not generate this test project from the model. Check out the source
from CVS:

Repository: :pserver:dev.eclipse.org:/cvsroot/modeling
Module: org.eclipse.mdt/org.eclipse.ocl/tests
Project: org.eclipse.ocl.uml.tests

Cheers,

Christian

charfi asma wrote:

> Hi Christian,
> concerning the ocl.eclipse.ocl.uml.tests, I generate it from
> OCLUML.genmodel in plugin "org;eclipse.ocl.uml",
> but I find 17 classes "AnyTypeTest.java, ExpressionOCLTest.java...."and
> there is no ProfileTest class!
> I used ocl 1.1M5 should I change to ocl1.1M7 and what is new in OCL 1.1M7?
> thanks a lot Christian!
>
> "Christian W. Damus" <cdamus@ca.ibm.com> a �rit dans le message de news:
> f2f17f$kvk$1@build.eclipse.org...
>>
>> Hi, Asma,
>>
>> Have a look at the org.eclipse.ocl.uml.tests.ProfilesTest class for
>> examples
>> of how to parse constraints in a Stereotype context and evaluate them on
>> elements to which the Stereotype is applied.
>>
>> If you are planning to use the EMF Validation framework
>> (org.eclipse.emf.validation) to define and invoke these constraints, then
>> have a look at the org.eclipse.emf.validation.examples.ocl example
>> plug-in
>> in the 1.1 M7 build of EMF Validation. This demonstrates a simple
>> implementation of a constraint provider that loads constraints from an
>> ocl file, as well as usage of the default plugin.xml-based constraint
>> provider with OCL.
>>
>> HTH,
>>
>> Christian
>>
>>
>> charfi asma wrote:
>>
>>> hi Lutz and Christian,
>>> I want to use constraints on stereotype but I did not know how to use
>>> getAppliedStereotypes(),getOwnedRules()....
>>> I am a begginer in this field and I have to develop a plugin which add
>>> constraints on profile and verify that models respect these constraints
>>> thank you for your help
>>> "Christian W. Damus" <cdamus@ca.ibm.com> a ?rit dans le message de news:
>>> eu959c$ldg$1@utils.eclipse.org...
>>>>
>>
>> <snip>
Re: OCL constraints in profile [message #24148 is a reply to message #23796] Fri, 18 May 2007 21:53 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: asma.charfi.com

Hi christian,
I check it out from cvs and I find the ProfileTest class.
I notice that the constraints are written in java code
If I add constraints using the UML editor,sould I rewrite them in code?
in other terms,can we generate code with constraints from uml
representation(model+profile+constraints)
"Christian W. Damus" <cdamus@ca.ibm.com> a
Re: OCL constraints in profile [message #24256 is a reply to message #24148] Tue, 22 May 2007 14:11 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Asma,

Using the EMF Validation Framework, you could create a Constraint Provider
that finds the constraints in your profile, parses them, and evaluates them
on elements to which those stereotypes are applied.

You could do much the same with a custom validator in EMF's
Diagnostician/EValidator API.

Either way, you shouldn't need to rewrite the constraints in your Java code,
because that would be redundant with the specification in your model, which
just leads to duplicate update problems ...

Note that the UML2 project's 2.1 M7 build gives you a third option. With
the ability to generate static profile definitions (generating a Java
implementation of its stereotypes) and to generate OCL invariant
constraints directly into your code, you basically get the
Diagnostician/EValidator implementation I mentioned above for free. Check
it out in the UML2 project's New & Noteworthy.

HTH,

Christian


charfi asma wrote:

> Hi christian,
> I check it out from cvs and I find the ProfileTest class.
> I notice that the constraints are written in java code
> If I add constraints using the UML editor,sould I rewrite them in code?
> in other terms,can we generate code with constraints from uml
> representation(model+profile+constraints)
> "Christian W. Damus" <cdamus@ca.ibm.com> a �rit dans le message de news:
> f2hjf9$bvk$1@build.eclipse.org...

<snip>
Re: OCL constraints in profile [message #24379 is a reply to message #24256] Wed, 23 May 2007 07:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: asma.charfi.com

hi Christian,
thank you very much for your answer.
I will install UML2 2.1M7 to see java implementation of profile.
but know I want to create my constraintProvider:

in EMF validation Framework, which validate model from extlibrary.ecore,
constraints are not extracted from the .ecore:
--they are written in plugin.xml between <constraint> and </constrain>
--or written in the library.ocl (EMF Validation Framework 1.1M7)

I want to extract them from profile then parse them and evaluate them.
should I create ConstraintProvider extension?
in this case what should I put in the package namespaceuri ?
(I put http:///schemas/ClientServer/_76FLEP3YEduh9M_TJJvjsg/0 the value of
"Ns Uri" property of my profile after definig )
am I in the right way?

thank you again Christian!

asma









"Christian W. Damus" <cdamus@ca.ibm.com> a
Re: OCL constraints in profile [message #24461 is a reply to message #24379] Wed, 23 May 2007 16:15 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Asma,

See some replies in-line, below.

HTH,

Christian


charfi asma wrote:

> hi Christian,
> thank you very much for your answer.
> I will install UML2 2.1M7 to see java implementation of profile.
> but know I want to create my constraintProvider:
>
> in EMF validation Framework, which validate model from extlibrary.ecore,
> constraints are not extracted from the .ecore:
> --they are written in plugin.xml between <constraint> and </constrain>
> --or written in the library.ocl (EMF Validation Framework 1.1M7)

Right. These are, respectively, the default constraint provider and an
*example* constraint provider (not intended for production use).


> I want to extract them from profile then parse them and evaluate them.
> should I create ConstraintProvider extension?

Yes.


> in this case what should I put in the package namespaceuri ?
> (I put http:///schemas/ClientServer/_76FLEP3YEduh9M_TJJvjsg/0 the value of
> "Ns Uri" property of my profile after definig )
> am I in the right way?

That should work. Not that, to avoid having this automatically generated NS
URI (which will change every time that you define the profile), you should
probably specify a static NS URI for your profile, and change it only when
you release new versions of the profile. Apply the <<ePackage>> stereotype
to the profile, and you will find an attribute in which you can set the NS
URI.


>
> thank you again Christian!
>
> asma

<snip>
Previous Topic:Re: OCL in a pojo domain usage scenario
Next Topic:[Announce] MDT OCL 1.1.0 1.1RC1 is available
Goto Forum:
  


Current Time: Thu Mar 28 11:45:16 GMT 2024

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

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

Back to the top