Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » OCL Constraint on all classes ?
OCL Constraint on all classes ? [message #1047754] Tue, 23 April 2013 15:54 Go to next message
Vincent Verdier is currently offline Vincent VerdierFriend
Messages: 12
Registered: April 2013
Junior Member
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 07:46 Go to previous messageGo to next message
Camille Letavernier is currently offline Camille LetavernierFriend
Messages: 952
Registered: February 2011
Senior Member
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


Camille Letavernier
Re: OCL Constraint on all classes ? [message #1048288 is a reply to message #1048237] Wed, 24 April 2013 09:06 Go to previous messageGo to next message
Vincent Verdier is currently offline Vincent VerdierFriend
Messages: 12
Registered: April 2013
Junior Member
Thanks for your answer, it's very interesting.

I would prefer the first solution which is more precise. However I didn't find the isRequired option...
Re: OCL Constraint on all classes ? [message #1048373 is a reply to message #1047754] Wed, 24 April 2013 11:21 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
HI

It is very easy to get confused about meta-levels once you start using
profiles and have classes at at least two levels..

Your problem and Camille's suggestions don't seem completely sensible.

Could you provide a small example of what you are really trying to do.

Regards

Ed Willink



On 23/04/2013 16:54, Vincent Verdier wrote:
> 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 #1048420 is a reply to message #1047754] Wed, 24 April 2013 12:49 Go to previous messageGo to next message
Vincent Verdier is currently offline Vincent VerdierFriend
Messages: 12
Registered: April 2013
Junior Member
I made a schema to explain the problem :)

index.php/fa/14500/0/
  • Attachment: desc.png
    (Size: 38.14KB, Downloaded 883 times)

[Updated on: Wed, 24 April 2013 12:53]

Report message to a moderator

Re: OCL Constraint on all classes ? [message #1049183 is a reply to message #1048420] Thu, 25 April 2013 13:34 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Did that solve your problem, or did you forget to attach it?

Regards

Ed Willink

On 24/04/2013 13:49, Vincent Verdier wrote:
> I made a schema to explain the problem :)
>
Re: OCL Constraint on all classes ? [message #1049190 is a reply to message #1047754] Thu, 25 April 2013 13:42 Go to previous messageGo to next message
Vincent Verdier is currently offline Vincent VerdierFriend
Messages: 12
Registered: April 2013
Junior Member
I attached the schema in my previous message. Strange you can't see it. Here another link to the schema : https://docs.google.com/file/d/0Bxg-oe5gzYQjMkxfbEJCVWZhZnc/edit?usp=sharing
Re: OCL Constraint on all classes ? [message #1049194 is a reply to message #1049190] Thu, 25 April 2013 13:50 Go to previous messageGo to next message
Klaas Gadeyne is currently offline Klaas GadeyneFriend
Messages: 165
Registered: July 2009
Senior Member
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, 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.

However, if you are only looking to add constraints to the UML meta-model, I don't really get why you would introduce a profile? So I'm not sure I understood your requirements correctly.

HTH,

Klaas
Re: OCL Constraint on all classes ? [message #1051362 is a reply to message #1049194] Sun, 28 April 2013 17:11 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
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
Previous Topic:Information on model explorer customization
Next Topic:Import UML to Papyrus
Goto Forum:
  


Current Time: Fri Apr 19 09:58:51 GMT 2024

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

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

Back to the top