Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » creating a OCL constraint provider.
creating a OCL constraint provider. [message #26124] Thu, 31 May 2007 13:48 Go to next message
Eclipse UserFriend
Originally posted by: firstname.name.gmail.com

Hello,

I am reusing a part of made in the thread "Re: OCLHelper" by charfi asma. I
would use the emf validation facilities to validate OCL expressions nested in
Stereotype on UML models, as Christian W. Damus suggested it.

I read carefully the "Tutorial: EMF Validation General" which is nice. But, I
can not perform any validation on UML models.

As a first step, I would like to make a batch validation. I sum up what I did so
far:

* extended a AbstractModelConstraint (to reuse charfi's work),
* created a constraintProvider
- category: my.validation.category
- constraint provider,
- constraint: class: my.validation.constraint.oclevaluate
- package: http://www.eclipse.org/uml2/2.1.0/UML
* created a constraintBinding
- clientContext: my.validation.oclcontext (reuse of ValidationDelegateClientSelector from
the example)
- clientBinding: mapping context/category

I also created a popup extension to delegate the validation (as shown in the
tutorial).

When I run my plugin, the dialog informed me that delegation has been done with
success but never call my oclevaluate class.

As I was not sure, I added a
* validationListener to register my clientContext (oclcontext)

I am not able to understand what I missed.. Especially, I don't know what value
of package/namespace (if it is mandatory) to declare inorder to work on UML models..

thanks in advance and pardon for my english.

--
F. Lagarde
Re: creating a OCL constraint provider. [message #26209 is a reply to message #26124] Thu, 31 May 2007 15:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, François,

Find some replies in-line, below.

HTH,

Christian

François Lagarde wrote:

>
> Hello,
>
> I am reusing a part of made in the thread "Re: OCLHelper" by charfi asma.
> I would use the emf validation facilities to validate OCL expressions
> nested in Stereotype on UML models, as Christian W. Damus suggested it.
>
> I read carefully the "Tutorial: EMF Validation General" which is nice.
> But, I can not perform any validation on UML models.

Do you see any messages in the workspace log?


> As a first step, I would like to make a batch validation. I sum up what I
> did so far:
>
> * extended a AbstractModelConstraint (to reuse charfi's work),

Why not extend the AbstractOCLModelConstraint (from the
org.eclipse.emf.validation.ocl plug-in)? That does much of the work for
you.

You may get more of a head start by creating the OCL Validation example
project in your workspace (from the main menu, "File -> New -> Example..."
and select the "OCL" example under the "EMF Validation Plug-ins" category).

This creates a project in your workspace that defines a custom constraint
provider that loads constraints from an OCL text file. This may work for
you as-is (changing, of course, the targeted EPackage namespace URI). Or,
you can just modify the provider to create your custom specialization of
AbstractOCLModelConstraint.

I don't see that you are particularly missing anything; I would actually
have to debug your code. Try debugging a working example from the SDK
(like the one I just mentioned) and compare with your plug-in.

> * created a constraintProvider
> - category: my.validation.category
> - constraint provider,
> - constraint: class: my.validation.constraint.oclevaluate
> - package: http://www.eclipse.org/uml2/2.1.0/UML
> * created a constraintBinding
> - clientContext: my.validation.oclcontext (reuse of
> ValidationDelegateClientSelector from
> the example)
> - clientBinding: mapping context/category
>
> I also created a popup extension to delegate the validation (as shown in
> the tutorial).
>
> When I run my plugin, the dialog informed me that delegation has been done
> with success but never call my oclevaluate class.
>
> As I was not sure, I added a
> * validationListener to register my clientContext (oclcontext)
>
> I am not able to understand what I missed.. Especially, I don't know what
> value of package/namespace (if it is mandatory) to declare inorder to work
> on UML models..

For UML models, the UML namespace URI that you are using should work. The
problem likely lies elsewhere.

>
> thanks in advance and pardon for my english.
>
Re: creating a OCL constraint provider. [message #26250 is a reply to message #26209] Fri, 01 June 2007 09:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: firstname.name.gmail.com

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


Christian> Why not extend the AbstractOCLModelConstraint (from the
Christian> org.eclipse.emf.validation.ocl plug-in)? That does much of
Christian> the work for you.

hello,

thanks for your help. I adapted the provided example
org.eclipse.emf.validation.examples.general to add constraints on UML models.

I tried to extend the AbstractOCLModelConstraint for the purpose of evaluating
constraints owned by a Stereotype on models. For example,
just make a stupid invariant in the context of "MyStereotype":
self.base_Class.name = 'MyClass'

To do so, I read how the OCLConstraint class from the example was done, and
rewrote one for UML.

But I have to confess that I gave up because I am to much confused with the
generic declaration. <C>, <CT>,<CLS>,<E>, could you confirm this is
respectively: uml.Classifier, uml.Constraint, uml.Class, EObject

Since I did not manage it, I tried to manually evaluate the constraint
(i.e, retrieve the constraint and evaluate it) and extended
AbstractModelConstraint.

But the bad thing, is that stereotype is not part of the package, in turn I can
never validate a stereotype i.e, a stereotype application. I used something like that:
// My AbstractModelConstraint
// In the case of batch mode.
if (eType == EMFEventType.NULL) {
Stereotype stereotype = null;
if (eObj instanceof Stereotype) {
... process
}
}

My first alternative is to run a validation on the profile resource (once my
profile is applied), but I do not know if the association to the applied
elements will be resolved.

My second alternative is to check every model elements, if they are stereotyped
evaluate the constraint. Here comes my second problem. When I define a
constraint (owned rule) in my stereotype part of my profile, and then define my
profile, my constraint declaration is ignored. (I tried, constraint
ignore,treated, process). Which means that I can not have knowledge of any
constraint form a applied stereotype viewpoint.


thanks for any helps.

--
F. Lagarde
Re: creating a OCL constraint provider. [message #26291 is a reply to message #26250] Fri, 01 June 2007 10:11 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: firstname.name.gmail.com

In the last post, on 06/01 about 11h, "François" (François Lagarde) wrote:

Sorry, I correct my self.

François> My second alternative is to check every model elements, if they
François> are stereotyped evaluate the constraint. Here comes my second
François> problem. [...] Which means that I can not have knowledge of
François> any constraint form a applied stereotype viewpoint.

I am wrong, I have just tried to check if an element is Stereotyped, and then
verify this constraint. It works.

But what is annoying is that if I want to be *omg compliant*, my stereotype constraint
should be as follow:
Consider MyStereotype extending Class, with a tag value myTag integer typed

inv naming : self.base_Class.name = 'toto'
inv tagConstraint : myTag > 2

consequently if I evaluate this constraint in the context of the stereotyped
element, the property "base_Class" does not exist...

--
F. Lagarde
Re: creating a OCL constraint provider. [message #26330 is a reply to message #26250] Fri, 01 June 2007 14:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, François,

See some replies in-line, below.

HTH

Christian


François Lagarde wrote:

> In the last post, on 05/31 about 05h, "Christian" (Christian W Damus)
> wrote:
>
>
> Christian> Why not extend the AbstractOCLModelConstraint (from the
> Christian> org.eclipse.emf.validation.ocl plug-in)? That does much
> of Christian> the work for you.
>
> hello,
>
> thanks for your help. I adapted the provided example
> org.eclipse.emf.validation.examples.general to add constraints on UML
> models.
>
> I tried to extend the AbstractOCLModelConstraint for the purpose of
> evaluating constraints owned by a Stereotype on models. For example,
> just make a stupid invariant in the context of "MyStereotype":
> self.base_Class.name = 'MyClass'
>
> To do so, I read how the OCLConstraint class from the example was done,
> and rewrote one for UML.
>
> But I have to confess that I gave up because I am to much confused with
> the generic declaration. <C>, <CT>,<CLS>,<E>, could you confirm this is
> respectively: uml.Classifier, uml.Constraint, uml.Class, EObject

That is exactly correct. You can follow the substitutions for the
same-named type parameters in the UMLEnvironment class.


> Since I did not manage it, I tried to manually evaluate the constraint
> (i.e, retrieve the constraint and evaluate it) and extended
> AbstractModelConstraint.
>
> But the bad thing, is that stereotype is not part of the package, in turn
> I can never validate a stereotype i.e, a stereotype application. I used
> something like that: // My AbstractModelConstraint
> // In the case of batch mode.
> if (eType == EMFEventType.NULL) {
> Stereotype stereotype = null;
> if (eObj instanceof Stereotype) {
> ... process
> }
> }

If you want EMF Validation Framework to validate the stereotype applications
(instances), then you would need your constraint provider to declare the NS
URI of the Ecore definition (EPackage) of your UML Profile. An NS URI will
be generated for you if you do not specify it by applying the <<ePackage>>
stereotype to your profile. Expand the annotation on your Profile element
to see the EPackage and its details.


> My first alternative is to run a validation on the profile resource (once
> my profile is applied), but I do not know if the association to the
> applied elements will be resolved.

This will, in general, only be expected to validate the well-formedness of
your profile, not the models to which it is applied.


> My second alternative is to check every model elements, if they are
> stereotyped evaluate the constraint. Here comes my second problem. When I
> define a constraint (owned rule) in my stereotype part of my profile, and
> then define my profile, my constraint declaration is ignored. (I tried,
> constraint ignore,treated, process). Which means that I can not have
> knowledge of any constraint form a applied stereotype viewpoint.

This is what I recommend. Use Element.getAppliedStereotypes() to find the
applied Stereotype elements, then look in the ownedRule attribute of these
stereotypes. Parse the OCL constraint expression as an invariant with the
stereotype as the context classifier (using the
OCLHelper.createInvariant(String) API). You would probably want to find
some way to cache these parsed constraints ...

Once you have a parsed Constraint, you can evaluate it on the element to
which the stereotype is applied. The UML evaluation environment knows how
to evaluate stereotype constraints in this way.


>
>
> thanks for any helps.
>
Re: creating a OCL constraint provider. [message #26368 is a reply to message #26291] Fri, 01 June 2007 14:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, François,

As I indicated in my reply to your other post, you should be able to
evaluate the constraint parsed in a Stereotype context on any Element to
which that stereotype is applied. Provided that you are using the UML
environment implementation ...

Have a look at the ProfilesTest class in the org.eclipse.ocl.uml.tests
plug-in for an example of how this works.

HTH,

Christian

François Lagarde wrote:

> In the last post, on 06/01 about 11h, "François" (François Lagarde) wrote:
>
> Sorry, I correct my self.
>
> François> My second alternative is to check every model elements,
> if they François> are stereotyped evaluate the constraint. Here
> comes my second
> François> problem. [...] Which means that I can not have knowledge
> of François> any constraint form a applied stereotype viewpoint.
>
> I am wrong, I have just tried to check if an element is Stereotyped, and
> then verify this constraint. It works.
>
> But what is annoying is that if I want to be *omg compliant*, my
> stereotype constraint should be as follow:
> Consider MyStereotype extending Class, with a tag value myTag integer
> typed
>
> inv naming : self.base_Class.name = 'toto'
> inv tagConstraint : myTag > 2
>
> consequently if I evaluate this constraint in the context of the
> stereotyped element, the property "base_Class" does not exist...
>
Re: creating a OCL constraint provider. [message #26477 is a reply to message #26368] Mon, 04 June 2007 07:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: firstname.name.gmail.com

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

Christian> Have a look at the ProfilesTest class in the
Christian> org.eclipse.ocl.uml.tests plug-in for an example of how this
Christian> works.

hello.

Thanks a lot for your help. The example was helpful. I can use emf validation
framework to evaluate stereotype OCL constraints on UML models and run
validation from a ocl rule file.


--
F. Lagarde
Re: creating a OCL constraint provider. [message #26508 is a reply to message #26477] Mon, 04 June 2007 20:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: asma.charfi.com

Hi fran
Re: creating a OCL constraint provider. [message #26537 is a reply to message #26508] Mon, 04 June 2007 13:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: firstname.name.gmail.com

In the last post, on 06/04 about 10h, "charfi" (charfi asma) wrote:

charfi> Hi françois, I am interested in this feature cause now I want to
charfi> validate all constraints in my model

I would be glad to provide you with this plugin, but it suffers from poor code
quality. As it, it would not be really useful to put it in the wiki.

I prefer to send to you directly the zip archive, and once (we) will have a
proper version, make it available.


--
F. Lagarde
Re: creating a OCL constraint provider. [message #26600 is a reply to message #26537] Mon, 04 June 2007 22:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: asma.charfi.com

Hi fran
Re: creating a OCL constraint provider. [message #26719 is a reply to message #26537] Tue, 05 June 2007 17:26 Go to previous message
Eclipse UserFriend
Originally posted by: asma.charfi.com

Hi fran
Previous Topic:OCL type conformance
Next Topic:emf validation examples
Goto Forum:
  


Current Time: Thu Nov 27 10:02:28 GMT 2014

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

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