Home » Modeling » OCL » Stereotype attributes and multiplicities
Stereotype attributes and multiplicities [message #735689] |
Wed, 12 October 2011 14:43 |
Lionel Montrieux 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 |
Ed Willink Messages: 7671 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 |
Lionel Montrieux 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 |
Ed Willink Messages: 7671 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
|
|
| | | |
Goto Forum:
Current Time: Thu Sep 26 17:24:36 GMT 2024
Powered by FUDForum. Page generated in 0.03605 seconds
|