OCL Constraint on all classes ? [message #1047754] |
Tue, 23 April 2013 11:54  |
Eclipse User |
|
|
|
Hi,
Is it possible to define a constraint on all classes in a profile ? Papyrus doesn't let me link a constraint and a metaclass import. So I tried by setting the context and the constrained element to the metaclass Class in the property view. But when I define my profile, the constraint become invalid (the name and content disapear and there is an icon of cross within a circle into the upper-right corner of the constraint element)
The only solution I found is to define a class stereotype but it imply to add the stereotype on every classes of the models which use this profile...
|
|
|
Re: OCL Constraint on all classes ? [message #1048237 is a reply to message #1047754] |
Wed, 24 April 2013 03:46   |
Eclipse User |
|
|
|
Hi Vincent,
The constraint is computed against its context (context == self). Moreover, the context must own the constraint (Which is why you cannot set the <<Metaclass>> Class as the Context of your constraint: it is read-only and cannot contain your constraint. Theres's a bug however, as Papyrus shouldn't even let you set this metaclass as the context of your constraint)
You have two options to write your constraint:
1) Create a Stereotype for Class, and set isRequired = true (Which means the Stereotype needs to be applied on each Class). Define a constraint for this stereotype. Not really the simplest way to do it...
2) Use Class.allInstances()->... to write your constraint. The problem with this declaration is that the constraint will only be validate once, for all the Classes (Instead of once for each Class), and will fail if at least one Class is invalid. Simpler, but way less powerful and precise.
I can't think of a proper way to do it (From a Profile).
The 3) option would be, of course, to define your constraint directly against the UML Metamodel, but I think you'd need a new plug-in + extension point contribution. Less easy to deploy, but at least it should work properly.
Regards,
Camille
|
|
|
|
|
|
|
|
|
Re: OCL Constraint on all classes ? [message #1051362 is a reply to message #1049194] |
Sun, 28 April 2013 13:11  |
Eclipse User |
|
|
|
Hi
On 25/04/2013 14:50, Klaas Gadeyne wrote:
> Hi,
>
> From your example, it looks like you would be helped with the approach
> described at
> http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.ocl.doc%2Fhelp%2FCompleteOCLTutorial.html&cp=49_3_2_8&anchor=CompleteOCLTutorial-UMLComplements,
> but AFAIK (Ed will probably correct me) even in Kepler,
Thanks. I'm glad someone reads the tutorials.
Your apparent requirement is to enhance UML not to add a stereotype, so
you need the flexibility of Complete OCL's open classes to enable you to
modify UML.
Except that if you modify UML you will need to change the spelling of
String and Integer to start with C. This can be fixed by excluding the
UML package from your style rule. Better that than introducing a
mandatory stereotype that will also have to be not applied to UML.
> this is not yet supported in papyrus, and you would have to use the
> UML2 model editor on the .uml model file for the validation.
As a result of a couple of Papyrus bugs that have now been fixed, the
Papyrus validation augments rather than displaces standard MDT/UML2
validation and so the Complete OCL approach should be able to work.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=406750 raised to remind me
to make sure that it does.
Regards
Ed Willink
|
|
|
Powered by
FUDForum. Page generated in 0.24679 seconds