Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Stereotype attributes and multiplicities
Stereotype attributes and multiplicities [message #735689] Wed, 12 October 2011 14:43 Go to next message
Lionel Montrieux is currently offline Lionel MontrieuxFriend
Messages: 4
Registered: October 2011
Location: UK
Junior Member
Hi all,

I am trying to write a few OCL queries on a UML model on which a profile is applied. The profile provides several stereotypes, some of then containing attributes.

Take for example two stereotypes, «User» and «Role». «User» has an 'rbacrole' attribute, and its multiplicity is [0-*]. Therefore, the stereotype «User» applied on the class 'User1' can be associated with two «Role» stereotypes, one applied on the class 'Role1' and the other one on the class 'Role2'.

I'd like to define an OCL query whose context will be a class stereotyped with «User», and that will navigate through _all_ of its associated roles. On the UML model I use something like:
self.extension_User.rbacrole


But of course, if I want to define my query on the ecore model, extension_User doesn't work. I tried using getValue(...) in the following way:

self.getValue(self.getAppliedStereotype('RBAC::User'), 'rbacrole')


The problem is that it only returns the first association, in this case 'Role1', when I need a set (or a bag) that contains both 'Role1' and 'Role2'. How can I do that?

Regards,
L/
Re: Stereotype attributes and multiplicities [message #735780 is a reply to message #735689] Wed, 12 October 2011 17:04 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4153
Registered: July 2009
Senior Member
Hi Lionel

My understanding of UML Profiles is limited. Sadly my understanding of
Eclipse OCL's support for profiles is also limited.

My naive expectation is that a profile should be folded into the
meta-model so that usage from OCL expressions should be unaware that
some features are from profiles and others are inherent. This is planned
for the new pivot model ....

However I recently needed to access profiles in a QVTo transformation
and did not find the above, but did find a comprehensive set of
getAppliedStereotype facilities that solved my problem.

You seem to be using the latter approach and finding problems because
getValue has no type safety. You therefore need to use oclAsType to
reimpose the type. This will probably work, but it is very close to a
bug that was reported with returns from eGet. I think we could only
mitigate, rather than cure the problem. Once type information has been
lost it is difficult to recover it reliably from a Java/Ecore value, so
I'm afraid no guarantees.

If you're using an Ecore model anyway, can't you just use the UML2Ecore
converter to fold in the profiles? This is probably what the OCLinEcore
editor or Complete OCL editors do anyway.

If you can provide a simple example that demonstrates your problem, I'd
appreciate a copy to help improve my understanding.

Regards

Ed Willink


On 12/10/2011 15:43, Lionel Montrieux wrote:
> Hi all,
>
> I am trying to write a few OCL queries on a UML model on which a
> profile is applied. The profile provides several stereotypes, some of
> then containing attributes.
>
> Take for example two stereotypes, «User» and «Role». «User» has an
> 'rbacrole' attribute, and its multiplicity is [0-*]. Therefore, the
> stereotype «User» applied on the class 'User1' can be associated with
> two «Role» stereotypes, one applied on the class 'Role1' and the other
> one on the class 'Role2'.
>
> I'd like to define an OCL query whose context will be a class
> stereotyped with «User», and that will navigate through _all_ of its
> associated roles. On the UML model I use something like:
> self.extension_User.rbacrole
>
> But of course, if I want to define my query on the ecore model,
> extension_User doesn't work. I tried using getValue(...) in the
> following way:
>
> self.getValue(self.getAppliedStereotype('RBAC::User'), 'rbacrole')
>
> The problem is that it only returns the first association, in this
> case 'Role1', when I need a set (or a bag) that contains both 'Role1'
> and 'Role2'. How can I do that?
>
> Regards,
> L/
Re: Stereotype attributes and multiplicities [message #736888 is a reply to message #735780] Fri, 14 October 2011 12:39 Go to previous messageGo to next message
Lionel Montrieux is currently offline Lionel MontrieuxFriend
Messages: 4
Registered: October 2011
Location: UK
Junior Member
Hi Ed,

The problem is that the OCL constraints can not be part of the profile (or at least not all of then), as they are generated by a plugin I'm writing depending on user actions. I have indeed had to use oclAsType() after getValue to cast the result to the expected. The problem is that getValue only returns one element, even when the attribute whose value I try to get has a multiplicity of [0-*].

Here's an example. I have prepared a simplified profile (attached, created using Topcased), that contains two stereotypes: «User», and «Role». The «User» stereotype contains an 'rbacrole' attribute whose multiplicity is [0-*]. In the archive there is also a simple model, created with Topcased, that contains one class stereotyped with «User», and two classes stereotyped with «Role». There are two 'rbacrole' associations from the «User»-stereotyped class, each pointing to one of the «Role» stereotypes in the model.
Consider now the following OCL queries:

Evaluating:
self.getValue(self.getAppliedStereotype('RBACProfile::User'), 'rbacrole').oclAsType(RBACProfile::Role)
Results:
Role

Evaluating:
self.getValue(self.getAppliedStereotype('RBACProfile::User'), 'rbacrole').oclAsType(RBACProfile::Role)->size()
Results:
1


What I expect instead is a set containing two «Role».

Regards,
Lionel
Re: Stereotype attributes and multiplicities [message #736903 is a reply to message #736888] Fri, 14 October 2011 12:57 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4153
Registered: July 2009
Senior Member
Hi

If you want a collection result you must cast to a Collection of some
kind; e.g oclAsType(Set(RBACProfile::Role)) but you are very close to
known bugs and to the evolving OCL specification. Arbitrarily typed
casts were hinted at in OCL 2.3 but arguably are not yet in the
specification. The new pivot Eclipse OCL implementation supports them.
The traditional Ecore code might support them by fortuitous accident;
but I suspect that you are in trouble. I recommend adding an explicit
operation to your model that you can implement in Java or via an OCL
delegate.

Regards

Ed Willink



On 14/10/2011 13:39, Lionel Montrieux wrote:
> Hi Ed,
>
> The problem is that the OCL constraints can not be part of the profile (or at least not all of then), as they are generated by a plugin I'm writing depending on user actions. I have indeed had to use oclAsType() after getValue to cast the result to the expected. The problem is that getValue only returns one element, even when the attribute whose value I try to get has a multiplicity of [0-*].
>
> Here's an example. I have prepared a simplified profile (attached, created using Topcased), that contains two stereotypes: «User», and «Role». The «User» stereotype contains an 'rbacrole' attribute whose multiplicity is [0-*]. In the archive there is also a simple model, created with Topcased, that contains one class stereotyped with «User», and two classes stereotyped with «Role». There are two 'rbacrole' associations from the «User»-stereotyped class, each pointing to one of the «Role» stereotypes in the model.
> Consider now the following OCL queries:
>
>
> Evaluating:
> self.getValue(self.getAppliedStereotype('RBACProfile::User'), 'rbacrole').oclAsType(RBACProfile::Role)
> Results:
> Role
>
> Evaluating:
> self.getValue(self.getAppliedStereotype('RBACProfile::User'), 'rbacrole').oclAsType(RBACProfile::Role)->size()
> Results:
> 1
>
>
> What I expect instead is a set containing two «Role».
>
> Regards,
> Lionel
Re: Stereotype attributes and multiplicities [message #736920 is a reply to message #736903] Fri, 14 October 2011 13:18 Go to previous messageGo to next message
Lionel Montrieux is currently offline Lionel MontrieuxFriend
Messages: 4
Registered: October 2011
Location: UK
Junior Member
Hi,

It doesn't seem that I can just cast the result to a set (or a Bag or a Collection):

Evaluating:
self.getValue(self.getAppliedStereotype('RBACProfile::User'), 'rbacrole').oclAsType(Set(RBACProfile::Role))
Results:
Unrecognized variable: (Set)


However, if I try to compute the size of the result, it seems to only contain one element:
Evaluating:
self.getValue(self.getAppliedStereotype('RBACProfile::User'), 'rbacrole')->size()
Results:
1


I'll try the workaround you recommend, thanks a lot.

Regards,
Lionel
Re: Stereotype attributes and multiplicities [message #1028485 is a reply to message #736920] Thu, 28 March 2013 10:07 Go to previous messageGo to next message
Marc Z is currently offline Marc ZFriend
Messages: 20
Registered: July 2012
Junior Member
Hi,

i have the same problem.
Does anyone has a workaround or is this bug already fixed?

Best regards,

Marc
Re: Stereotype attributes and multiplicities [message #1028599 is a reply to message #1028485] Thu, 28 March 2013 13:34 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4153
Registered: July 2009
Senior Member
Hi

The Kepler release has a lot of improvements to support OCL within UML
and Papyrus, so I expect that this is fixed.

If you use the M6 release from
http://www.eclipse.org/modeling/mdt/downloads/?project=ocl and it
doesn't work please post an example.

Regards

Ed Willink


On 28/03/2013 10:07, Marc Z wrote:
> Hi,
>
> i have the same problem.
> Does anyone has a workaround or is this bug already fixed?
>
> Best regards,
>
> Marc
Previous Topic:OCL Constraint in ecore model
Next Topic:[OCLinEcore] Generating OCLinEcoreEObjectValidator supertype for the validator
Goto Forum:
  


Current Time: Wed Nov 26 05:39:55 GMT 2014

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

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