Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Access to Tagged Values in OCL
Access to Tagged Values in OCL [message #65517] Wed, 24 December 2008 09:23 Go to next message
Michael Felderer is currently offline Michael FeldererFriend
Messages: 11
Registered: July 2009
Junior Member
Hello all,

I have created a UML2 profile and want to define profile specific OCL constraints on it. Therefore I
need access to the stereotypes and the tagged values within OCL.

For the STEREOTYPES itself I can work with the getAppliedStereotypes method which works fine for me,
e.g. the following query checks whehter a stereotype Assertion has been applied to an element:

self.allOwnedElements()->select(a | a.getAppliedStereotypes().name->includes('Assertion'))->size() >0

But I still do not know how to access the tagged values within OCL and how to convert them to a
specific type for further reuse within a query (because most of the time the tagged values in my
scenario are not strings and I want to naviagte across them or use their values).
Can someone tell me how this works or if it does not work yet how this functionality can be implemented.

thanks in advance,
Michael Felderer

PS.: For writing queries I use the Advanced OCL Editor (www.squam.info/ocleditor) which works great
for that.
Re: Access to Tagged Values in OCL [message #65538 is a reply to message #65517] Thu, 25 December 2008 04:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rafael.abstratt.com

Michael,

You can use Element.getValue(Stereotype stereotype, String
propertyName). See:

http://wiki.eclipse.org/OCLSnippets#Finding_all_elements_wit h_a_given_tagged_value

Cheers,

Rafael
http://abstratt.com/blog/

Michael Felderer wrote:
> Hello all,
>
> I have created a UML2 profile and want to define profile specific OCL
> constraints on it. Therefore I need access to the stereotypes and the
> tagged values within OCL.
>
> For the STEREOTYPES itself I can work with the getAppliedStereotypes
> method which works fine for me, e.g. the following query checks whehter
> a stereotype Assertion has been applied to an element:
>
> self.allOwnedElements()->select(a |
> a.getAppliedStereotypes().name->includes('Assertion'))->size() >0
>
> But I still do not know how to access the tagged values within OCL and
> how to convert them to a specific type for further reuse within a query
> (because most of the time the tagged values in my scenario are not
> strings and I want to naviagte across them or use their values).
> Can someone tell me how this works or if it does not work yet how this
> functionality can be implemented.
>
> thanks in advance,
> Michael Felderer
>
> PS.: For writing queries I use the Advanced OCL Editor
> (www.squam.info/ocleditor) which works great for that.
Re: Access to Tagged Values in OCL [message #65559 is a reply to message #65538] Fri, 26 December 2008 17:36 Go to previous messageGo to next message
Michael Felderer is currently offline Michael FeldererFriend
Messages: 11
Registered: July 2009
Junior Member
thanks for your reply,

i mastered to access tagged values with, e.g.

self.getValue(self.getAppliedStereotype('TTSProfile::Service call'), 'service')

this returns (something correct).

org.eclipse.uml2.uml.internal.impl.ClassImpl@1930ebb (name: Login, visibility: <unset>) (isLeaf:
false, isAbstract: false) (isActive: false)

The return value is again a stereotype - in OCL it is of type OclAny. How can I now access a tagged
value of this returned stereotype?
Or more general, is there a procedure how i can navigate through references stored in tagged values
which are again stereotypes...

thanks,
Michael


> Michael,
>
> You can use Element.getValue(Stereotype stereotype, String
> propertyName). See:
>
> http://wiki.eclipse.org/OCLSnippets#Finding_all_elements_wit h_a_given_tagged_value
>
>
> Cheers,
>
> Rafael
> http://abstratt.com/blog/
>
> Michael Felderer wrote:
>> Hello all,
>>
>> I have created a UML2 profile and want to define profile specific OCL
>> constraints on it. Therefore I need access to the stereotypes and the
>> tagged values within OCL.
>>
>> For the STEREOTYPES itself I can work with the getAppliedStereotypes
>> method which works fine for me, e.g. the following query checks
>> whehter a stereotype Assertion has been applied to an element:
>>
>> self.allOwnedElements()->select(a |
>> a.getAppliedStereotypes().name->includes('Assertion'))->size() >0
>>
>> But I still do not know how to access the tagged values within OCL and
>> how to convert them to a specific type for further reuse within a
>> query (because most of the time the tagged values in my scenario are
>> not strings and I want to naviagte across them or use their values).
>> Can someone tell me how this works or if it does not work yet how this
>> functionality can be implemented.
>>
>> thanks in advance,
>> Michael Felderer
>>
>> PS.: For writing queries I use the Advanced OCL Editor
>> (www.squam.info/ocleditor) which works great for that.
>
>
>
Re: Access to Tagged Values in OCL [message #65579 is a reply to message #65517] Mon, 29 December 2008 13:04 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

Hi, Michael,

If you are using the UMLEnvironmentFactory from the org.eclipse.ocl.uml
plug-in (which I recommend that you do), then you won't have to use the
somewhat awkward (and non-standard) getAppliedStereotypes() and
getValue() API.

OCL sees stereotypes as peers of the UML metaclasses, and accesses them
as such. The advantage of the UML environment implementation is that it
supports navigation of non-navigable association ends, which is how you
access the stereotype instances linked to your model elements.

For example, assuming that you have defined a profile using the default
names for extension ends, in which a stereotype EntityBean extends the
Class metaclass, you can access the bean attributes of some class like
this (with some helper properties defined for convenience):

context Class
def: isEntityBean : Boolean =
self.extension_EntityBean->notEmpty()
def: asEntityBean : EntityBean =
self.extension_EntityBean->any(true)
inv has_pk_mapping:
self.isEntityBean implies self.asEntityBean.primaryKey->notEmpty()

Probably a constraint like that should be defined on the stereotype, but
I hope this shows the idea.

HTH,

Christian


Michael Felderer wrote:
> Hello all,
>
> I have created a UML2 profile and want to define profile specific OCL
> constraints on it. Therefore I need access to the stereotypes and the
> tagged values within OCL.
>
> For the STEREOTYPES itself I can work with the getAppliedStereotypes
> method which works fine for me, e.g. the following query checks whehter
> a stereotype Assertion has been applied to an element:
>
> self.allOwnedElements()->select(a |
> a.getAppliedStereotypes().name->includes('Assertion'))->size() >0
>
> But I still do not know how to access the tagged values within OCL and
> how to convert them to a specific type for further reuse within a query
> (because most of the time the tagged values in my scenario are not
> strings and I want to naviagte across them or use their values).
> Can someone tell me how this works or if it does not work yet how this
> functionality can be implemented.
>
> thanks in advance,
> Michael Felderer
>
> PS.: For writing queries I use the Advanced OCL Editor
> (www.squam.info/ocleditor) which works great for that.
Previous Topic:Advanced OCL Editor
Next Topic:[Announce] MDT OCL 1.3.0 I200812310804 is available
Goto Forum:
  


Current Time: Wed Apr 24 21:40:49 GMT 2024

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

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

Back to the top