Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » OCLHelper
OCLHelper [message #24744] Sat, 26 May 2007 00:59 Go to next message
Eclipse UserFriend
Originally posted by: asma.charfi.com

Hi,
I tried to parse an ocl constraints added to my profile (on stereotype
Client)
I want to follow these 5 steps that Christian suggest in
http://dev.eclipse.org/newslists/news.eclipse.modeling.mdt.o cl/msg00137.html
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

when I use getConstrainedElements(),it returns a list (of Elements)
so I can not use setcontext(classifier) to my helper. (I can not cast
Element to Classifier)

In the steps 4, I did not know what should I put as parameter in
org.eclipse.ocl.uml.OCL.newInstance(.....)?
I red in this thread "problem with parsing ocl expression in standalone
environnement(4/05/2007)" that we can:
createModel(model);
rset = new org.eclipse.emf.ecore.resource.impl.ResourceSetImpl();
URI uri = URI.createURI("test.uml");
res = rset.createResource(uri);
res.getContents().add(model);
res.save(null);
org.eclipse.ocl.uml.OCL ocl
=org.eclipse.ocl.uml.OCL.newInstance(res.getResourceSet());
but I want my plugin to be generic and I did not want to write "test.uml" in
my code

thank you very much!

here is my code: (when I click to class Client1 wich apply sterotype Client
that have a constraint):
public void selectionChanged(IAction action, final ISelection selection) {

if (selection instanceof IStructuredSelection) {

IStructuredSelection structuredSelection = (IStructuredSelection) selection;

objectselected = (Element) structuredSelection.getFirstElement();} // I cast
to Element to use getAppliedSteretypes()

.....}

EList<Constraint>
constraints=objectselected.getAppliedStereotypes().get(0).ge tOwnedRules();

MessageDialog.openInformation(shell,"Validerprofile Plug-in","this list
contain "+constraints.size()+"constraints"); //it return 1

Constraint myconstraint=constraints.get(0);


EList<Element> classifiers=myconstraint.getConstrainedElements();

String classifier=myconstraint.getContext().getName(); //it returns the
contexte of the constraint which is the Stereotype Client

.......
Re: OCLHelper [message #24781 is a reply to message #24744] Fri, 25 May 2007 16:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Asma,

See some replies, in-line, below.

HTH,

Christian


charfi asma wrote:

> Hi,
> I tried to parse an ocl constraints added to my profile (on stereotype
> Client)
> I want to follow these 5 steps that Christian suggest in
>
http://dev.eclipse.org/newslists/news.eclipse.modeling.mdt.o cl/msg00137.html
> 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
>
> when I use getConstrainedElements(),it returns a list (of Elements)
> so I can not use setcontext(classifier) to my helper. (I can not cast
> Element to Classifier)

Search the list for the first element that is "instanceof Classifier" and
cast it to Classifier. This is how OCL specifies that a UML model
indicates the context classifier. The OCL specification ignores the
"context" attribute of the UML Constraint metaclass.


> In the steps 4, I did not know what should I put as parameter in
> org.eclipse.ocl.uml.OCL.newInstance(.....)?
> I red in this thread "problem with parsing ocl expression in standalone
> environnement(4/05/2007)" that we can:
> createModel(model);
> rset = new org.eclipse.emf.ecore.resource.impl.ResourceSetImpl();
> URI uri = URI.createURI("test.uml");
> res = rset.createResource(uri);
> res.getContents().add(model);
> res.save(null);
> org.eclipse.ocl.uml.OCL ocl
> =org.eclipse.ocl.uml.OCL.newInstance(res.getResourceSet());
> but I want my plugin to be generic and I did not want to write "test.uml"
> in my code

You already have a UML model resource if you have Elements on which to
evaluate constraints, so just use the OCL.newInstance(ResourceSet) factory
method to create an OCL instance that will find the UML metamodel and
related resources in your model's resource set.


> thank you very much!
>
> here is my code: (when I click to class Client1 wich apply sterotype
> Client that have a constraint):
> public void selectionChanged(IAction action, final ISelection selection) {
>
> if (selection instanceof IStructuredSelection) {
>
> IStructuredSelection structuredSelection = (IStructuredSelection)
> selection;
>
> objectselected = (Element) structuredSelection.getFirstElement();} // I
> cast to Element to use getAppliedSteretypes()
>
> ....}
>
> EList<Constraint>
> constraints=objectselected.getAppliedStereotypes().get(0).ge tOwnedRules();
>
> MessageDialog.openInformation(shell,"Validerprofile Plug-in","this list
> contain "+constraints.size()+"constraints"); //it return 1
>
> Constraint myconstraint=constraints.get(0);
>
>
> EList<Element> classifiers=myconstraint.getConstrainedElements();
>
> String classifier=myconstraint.getContext().getName(); //it returns the
> contexte of the constraint which is the Stereotype Client
>
> ......
Re: OCLHelper [message #24816 is a reply to message #24781] Sat, 26 May 2007 22:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: asma.charfi.com

Hi Christian,

thank you for our help I can now use the helper.setContexte() method.

but I did not understand how I can just use the OCL.newInstance(ResourceSet)
factory method to create an OCL instance?
is writing that sufficient?
ResourceSetImpl rset = new
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl();

OCL ocl = org.eclipse.ocl.uml.OCL.newInstance(rset);

is there a help on line of org.eclipse.ocl.uml.OCL?

--I did not find any methode called parseIvanriant()?

the only method I found is parse (inputOCL) and I don't want to specify any
package or documents in code :(

thank you!

"Christian W. Damus" <cdamus@ca.ibm.com> a
Re: OCLHelper [message #24997 is a reply to message #24816] Mon, 28 May 2007 17:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Asma,

All of the documentation that exists is available in the "Help -> Help
Contents" window, under the "OCL Developer Guide" book. This includes a
Programmer's Guide and complete Javadocs (which are only as good as the doc
comments in the code, of course).

You only need to specify other arguments in the construction of the OCL
instance if
- you already have an Environment object that you want to reuse
- you want to load a persisted Environment from a Resource
- etc.

The OCLHelper interface has a createInvariant(String) method that accepts
simply the boolean constraint expression. I probably mistyped this as
parseInvariant() ... I do that a lot, which leads me to think that maybe
that would have been a better name ;-)

Cheers,

Christian


charfi asma wrote:

> Hi Christian,
>
> thank you for our help I can now use the helper.setContexte() method.
>
> but I did not understand how I can just use the
> OCL.newInstance(ResourceSet) factory method to create an OCL instance?
> is writing that sufficient?
> ResourceSetImpl rset = new
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl();
>
> OCL ocl = org.eclipse.ocl.uml.OCL.newInstance(rset);
>
> is there a help on line of org.eclipse.ocl.uml.OCL?
>
> --I did not find any methode called parseIvanriant()?
>
> the only method I found is parse (inputOCL) and I don't want to specify
> any package or documents in code :(
>
> thank you!
>
> "Christian W. Damus" <cdamus@ca.ibm.com> a �rit dans le message de news:
> f3726a$r8s$1@build.eclipse.org...
>> Hi, Asma,
>>
>> See some replies, in-line, below.
>>
>> HTH,
>>
>> Christian
>>
>>

<snip>
Re: OCLHelper [message #25114 is a reply to message #24997] Tue, 29 May 2007 09:02 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: asma.charfi.com

Hi Christian,
finally I succeeded in doing it !! thanks to you of corse ;-)

I added my constraint to my stereotype (using UMLEditor) and then I
developped a simple plugin that:
-extract this constraint from stereotype.
-parse it using a helper
-evaluate it using ocl.evaluate()
but, I used org.eclipse.ocl.ecore.OCL instead of org.eclipse.ocl.uml.OCL
and I defined my new instance of OCL using this code

"OCL ocl = OCL.newInstance(new EcoreEnvironmentFactory(
new DelegatingPackageRegistry(
context.eResource().getResourceSet().getPackageRegistry(),EP ackage.Registry.INSTANCE))); "

I know it's yours (ocl interpreter example) and you always put a copyright,
but I use it any way ;)

THANKS A LOT!!




I specify an OCL constraint i my stereotype (using umlEditor) and I develop
a simple plugin that extract this constraint from profile

"Christian W. Damus" <cdamus@ca.ibm.com> a
Re: OCLHelper [message #25155 is a reply to message #25114] Tue, 29 May 2007 13:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Asma,

I'm glad that you got this to work.

However, if you needed to resort to the Ecore environment because the UML
environment wasn't working for you, then perhaps there's a bug in the UML
implementation that should be fixed. If you can provide a reproducible
test case, plase raise a bug and attach it so that we can investigate.

Thanks,

Christian


charfi asma wrote:

> Hi Christian,
> finally I succeeded in doing it !! thanks to you of corse ;-)
>
> I added my constraint to my stereotype (using UMLEditor) and then I
> developped a simple plugin that:
> -extract this constraint from stereotype.
> -parse it using a helper
> -evaluate it using ocl.evaluate()
> but, I used org.eclipse.ocl.ecore.OCL instead of org.eclipse.ocl.uml.OCL
> and I defined my new instance of OCL using this code
>
> "OCL ocl = OCL.newInstance(new EcoreEnvironmentFactory(
> new DelegatingPackageRegistry(
>
context.eResource().getResourceSet().getPackageRegistry(),EP ackage.Registry.INSTANCE))); "
>
> I know it's yours (ocl interpreter example) and you always put a
> copyright, but I use it any way ;)
>
> THANKS A LOT!!
>

<snip>
Re: OCLHelper [message #25316 is a reply to message #25114] Tue, 29 May 2007 13:41 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: firstname.name.gmail.com

In the last post, on 05/29 about 11h, "charfi" (charfi asma) wrote:

charfi> Hi Christian, finally I succeeded in doing it !! thanks to you of
charfi> corse ;-)

hello,

I am also interesting in a such feature, is it possible that you (charfi) make
your plugin and an example available.

charfi> I used org.eclipse.ocl.ecore.OCL instead of
charfi> org.eclipse.ocl.uml.OCL and I defined my new instance of OCL
charfi> using this code

Are OCL features from ecore.OCL more restricted than the ones from ocl.UML.OCL ?

I still have difficulties to understand differences with these two libraries. I
am interested in constraining UML models.

thanks.

--
F. Lagarde
Re: OCLHelper [message #25437 is a reply to message #25316] Tue, 29 May 2007 14:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, François, Asma,

Any examples that you would like to share with the community are welcome on
the OCL Wiki page: http://wiki.eclipse.org/index.php/MDT-OCL

You can find out more about the difference between the Ecore and UML
bindings for OCL in the Programmer's Guide (since M7/RC0). Essentially,
the UML binding provides support for concepts available in UML that Ecore
does not understand, including (but not limited to):

- query vs. non-query operations (important for guaranteeing the
side-effect-free characteristic of OCL)
- static operations and attributes
- association classes
- association-end qualifiers
- navigation of non-navigable association ends
- states (OclAny::oclIsInState operation)
- evaluation of constraints on InstanceSpecifications as well as EObjects
of the generated API

Cheers,

Christian

François Lagarde wrote:

> In the last post, on 05/29 about 11h, "charfi" (charfi asma) wrote:
>
> charfi> Hi Christian, finally I succeeded in doing it !! thanks to
> you of charfi> corse ;-)
>
> hello,
>
> I am also interesting in a such feature, is it possible that you (charfi)
> make your plugin and an example available.
>
> charfi> I used org.eclipse.ocl.ecore.OCL instead of
> charfi> org.eclipse.ocl.uml.OCL and I defined my new instance of
> OCL charfi> using this code
>
> Are OCL features from ecore.OCL more restricted than the ones from
> ocl.UML.OCL ?
>
> I still have difficulties to understand differences with these two
> libraries. I am interested in constraining UML models.
>
> thanks.
>
Re: OCLHelper [message #25477 is a reply to message #25437] Tue, 29 May 2007 14:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: firstname.name.gmail.com

In the last post, on 05/29 about 04h, "Christian" (Christian W Damus) wrote:


Christian> You can find out more about the difference between the Ecore
Christian> and UML bindings for OCL in the Programmer's Guide (since
Christian> M7/RC0).

thanks for this input (you have already provided me but I forgot...)

I read that the UML Environment supports "constraints defined on
stereotypes". What does-it really mean?

I think that it doesn't mean that OCL expression are evaluated on models with a
simple Validate call, otherwise the Asma's thread was useless.

thanks.

--
F. Lagarde
Re: OCLHelper [message #25668 is a reply to message #25477] Tue, 29 May 2007 15:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, François,

What that means is simply that the UML implementation of the
EvaluationEnvironment supports the evaluation of constraints that are
defined in a Stereotype context on model elements to which the stereotype
is applied. This pretends that the stereotype is a facet of the element,
without requiring the user to get the stereotype application (instance) and
validate it directly.

The OCL API does nothing to find constraints that should be evaluated on any
model element. It only knows how to evaluate constraints given it by a
client, which has the responsibility of finding the constraints relevant to
the application.

Cheers,

Christian

François Lagarde wrote:

> In the last post, on 05/29 about 04h, "Christian" (Christian W Damus)
> wrote:
>
>
> Christian> You can find out more about the difference between the
> Ecore Christian> and UML bindings for OCL in the Programmer's Guide
> (since Christian> M7/RC0).
>
> thanks for this input (you have already provided me but I forgot...)
>
> I read that the UML Environment supports "constraints defined on
> stereotypes". What does-it really mean?
>
> I think that it doesn't mean that OCL expression are evaluated on models
> with a simple Validate call, otherwise the Asma's thread was useless.
>
> thanks.
>
Re: OCLHelper [message #25921 is a reply to message #25316] Thu, 31 May 2007 03:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: asma.charfi.com

Hi Fran
Re: OCLHelper [message #25961 is a reply to message #25155] Thu, 31 May 2007 03:30 Go to previous message
Eclipse UserFriend
Originally posted by: asma.charfi.com

Hi christian,
I raise a bug it is the 189981
I hope that is well done cause it is the fist time that I work with bugzilla
also, when I tried to add my example in
http://wiki.eclipse.org/index.php/MDT-OCL, I erased the link "Example" and
I did not know how to cansel what I have done:-(
asma

"Christian W. Damus" <cdamus@ca.ibm.com> a
Re: OCLHelper [message #26002 is a reply to message #25961] Wed, 30 May 2007 19:13 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi Asma,

Don't worry about it ... I have restored the erased content and linked the
OCL page to your example (as a separate doc):

http://wiki.eclipse.org/index.php/MDT-OCL#Examples

To cancel an edit, simply hit the "Cancel" link next to the "Save", "Show
Preview", and "Show Changes" buttons.

Next to the cancel link is also a link with plenty of helpful information
for editing Wiki documents.

Cheers,

Christian


charfi asma wrote:

> Hi christian,
> I raise a bug it is the 189981
> I hope that is well done cause it is the fist time that I work with
> bugzilla also, when I tried to add my example in
> http://wiki.eclipse.org/index.php/MDT-OCL, I erased the link "Example"
> and I did not know how to cansel what I have done:-(
> asma

<snip>
Previous Topic:[Announce] MDT OCL 1.1.0 1.1RC2 is available
Next Topic:OCL type conformance
Goto Forum:
  


Current Time: Tue Apr 23 16:14:48 GMT 2024

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

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

Back to the top