|Re: OCL Constraint on all classes ? [message #1048237 is a reply to message #1047754]
||Wed, 24 April 2013 07:46
| Camille Letavernier
Registered: February 2011
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.
Powered by FUDForum
. Page generated in 0.03542 seconds