Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Verify Stereotypes with OCL
Verify Stereotypes with OCL [message #15226] Wed, 28 March 2007 18:05 Go to next message
Eclipse UserFriend
Originally posted by: mehr.farid.gmail.com

Hi,

I want to query with OCL the UML model elements that have specific
stereotypes applied. Conceptually, these types of queries might not differ
much fom "syntactical" queries, e.g. query model elements that have a
specific name, like: self.getMyModelElements->select(x : NamedElement |
x.name ='InterestingName').

This works very fine with this OCL-implementation. However, I was not able
to do the same for stereotypes. Indeed, I could not extract any relevant
information concerning this from the OCL spec. And, from the UML 2.x
superstructure, it is not clear to me yet, how to navigate to the applied
stereotypes from a model element as there might exist two distinct ways
for that?:

- self.myClasses.extension.ownedEnd.type.name='MyStereotype': Here, I
navigate through the association ends according to the abstract syntax of
the uml profile as depicted in Figure 18.2 in UML 2.x superstructure (self
is of type class). I see two problems with this...: Conceptually, this
would only work for Classes (and their subclasses) as "extension", which
is derived, is defined for the meta-class "Class" in the UML metamodel
only!? I want to be able to query also, for instance, ActivityNode or
ActivityEdges which are NamedElements but not Classes.... Second, with the
OCL implementation I was not able to execute such an query on classes
either. Is this type of navigation not implemented yet for stereotypes
also or am I wrong with my assumption that this should work equally for
stereotypes as well?

- The second "way" of figuring out wether an element has a sterotype
applied is used in a constraint for the meta-class Transition in the UML
superstructure document itself (see especially the last line of the
following code excerpt):
self.source.oclIsKindOf(Pseudostate) implies
(self.source.oclAsType(Pseudostate).kind = #initial) implies
(self.source.container = self.stateMachine.top) implies
((self.trigger->isEmpty) or
(self.trigger.stereotype.name = 'create'))

Unfortunately, I wasn't able to execute such a query with this
implementation either. I tried to fetch all ActivityNodes of an activity
that have the sammple stereotype "MyStereotype" applied:
self.node->selection(action:ActivityNode | action.stereotype.name =
'MyStereotype')
When executing the query, i get an exception (SemanticException) that the
variable stereotype is not recognized. This is true as ActivityNode does
not possess a feature (property, operation...) named "stereotype"....

So, is there any way with this implementation to query UML model elements
that have specific stereotypes applied?

Thx,
Farid
Re: Verify Stereotypes with OCL [message #15259 is a reply to message #15226] Wed, 28 March 2007 18:50 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Farid,

See some responses in-line, below.

HTH,

Christian


Farid Mehr wrote:

> Hi,
>
> I want to query with OCL the UML model elements that have specific
> stereotypes applied. Conceptually, these types of queries might not differ
> much fom "syntactical" queries, e.g. query model elements that have a
> specific name, like: self.getMyModelElements->select(x : NamedElement |
> x.name ='InterestingName').
>
> This works very fine with this OCL-implementation. However, I was not able
> to do the same for stereotypes. Indeed, I could not extract any relevant
> information concerning this from the OCL spec. And, from the UML 2.x
> superstructure, it is not clear to me yet, how to navigate to the applied
> stereotypes from a model element as there might exist two distinct ways
> for that?:
>
> - self.myClasses.extension.ownedEnd.type.name='MyStereotype': Here, I
> navigate through the association ends according to the abstract syntax of
> the uml profile as depicted in Figure 18.2 in UML 2.x superstructure (self
> is of type class). I see two problems with this...: Conceptually, this
> would only work for Classes (and their subclasses) as "extension", which
> is derived, is defined for the meta-class "Class" in the UML metamodel

You're mixing meta-levels, here. The Class::extension attribute is merely
the opposite of the Extension::metaclass attribute. This is the
association between an Extension and a Class playing the role of a
metaclass in the UML metamodel. This is not something that OCL can see, as
it is at the metamodel level (M2; OCL works on the model level, M1).


> only!? I want to be able to query also, for instance, ActivityNode or
> ActivityEdges which are NamedElements but not Classes.... Second, with the
> OCL implementation I was not able to execute such an query on classes
> either. Is this type of navigation not implemented yet for stereotypes
> also or am I wrong with my assumption that this should work equally for
> stereotypes as well?

As I alluded to above, OCL provides no facility for introspecting the UML
metamodel, which stereotypes in effect extend.


> - The second "way" of figuring out wether an element has a sterotype
> applied is used in a constraint for the meta-class Transition in the UML
> superstructure document itself (see especially the last line of the
> following code excerpt):
> self.source.oclIsKindOf(Pseudostate) implies
> (self.source.oclAsType(Pseudostate).kind = #initial) implies
> (self.source.container = self.stateMachine.top) implies
> ((self.trigger->isEmpty) or
> (self.trigger.stereotype.name = 'create'))

This is an incorrectly formulated constraint. There is no "stereotype"
property in the UML metamodel, nor is it defined by OCL.

A compliant OCL expression would navigate the extension from the base
element to the stereotype, as follows:

self.source.oclIsKindOf(Pseudostate) implies
(self.source.oclAsType(Pseudostate).kind = PseudostateKind::initial)
implies
(self.source.container = self.stateMachine.top) implies
((self.trigger->isEmpty) or
(not self.trigger.extension_Create.oclIsUndefined()))

Note the last line in particular, where we navigate the extension end (the
association end owned by the metaclass extension) to the Create stereotype
and test whether there is a stereotype instance, there. This assumes two
things:

- that the extension end is named as it would be by default if you
created it with the Eclipse UML2 implementation. In general, though,
this name would be published by any specification of the profile in
question
- that the OCL implementation supports the (optional) navigation of
non-navigable association ends. MDT OCL does not, yet

The second problem can be worked around using the Eclipse UML2
implementation's getAppliedStereotypes() and getStereotypeApplication()
APIs on Element. You can use the "any" iterator to find a named stereotype
in the appliedStereotypes collection, then use the other UML2 APIs to work
with that stereotype. These APIs are non-standard, so your OCL expressions
would be tied to this particular UML implementation ... In fact, you will
find that all of the query operations (side-effect-free operations) defined
in the UML2 Java API are available in OCL.

> Unfortunately, I wasn't able to execute such a query with this
> implementation either. I tried to fetch all ActivityNodes of an activity
> that have the sammple stereotype "MyStereotype" applied:
> self.node->selection(action:ActivityNode | action.stereotype.name =
> 'MyStereotype')
> When executing the query, i get an exception (SemanticException) that the
> variable stereotype is not recognized. This is true as ActivityNode does
> not possess a feature (property, operation...) named "stereotype"....
>
> So, is there any way with this implementation to query UML model elements
> that have specific stereotypes applied?
>
> Thx,
> Farid
Previous Topic:[Announce] MDT OCL 1.1.0 I200703271636 is available
Next Topic:[Announce] MDT OCL 1.1.0 I200703281811 is available
Goto Forum:
  


Current Time: Fri Apr 26 20:40:16 GMT 2024

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

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

Back to the top