How to access name of EnumerationLiteral [message #11892] |
Sat, 17 March 2007 14:54  |
Eclipse User |
|
|
|
Originally posted by: maiera.de.ibm.com
Hi,
I have defined an Enumeration D_Enum in a profile. D_Enum has a few
literals defined, say D1 and D2. D_Enum is used as the type of a
property D in a stereotype S in the same profile.
In an OCL constraint with context S, I would like to access the name of
the enumeration literal currently set in property D. I need the name
because I want to compare it against a string.
The OCL expression
self.D
evaluates to the value of the property D, i.e. to one of the possible
literals D1,D2.
I can successfully compare that property value to one literal (or a set
of literals), e.g.
self.D = <profile-name>::D_Enum::D1
but this does not solve my problem since I need to compare the literal's
name (e.g. "D1") against a string.
I tried
self.D.name
to access the name of the literal, but the OCL engine complains with
"Unrecognized variable (name)".
-> How can I access the name of the actually set literal from within
that context ?
Andy
|
|
|
Re: How to access name of EnumerationLiteral [message #13495 is a reply to message #11892] |
Sun, 18 March 2007 09:39  |
Eclipse User |
|
|
|
Originally posted by: cdamus.ca.ibm.com
Hi, Andy,
OCL provides no means by which to introspect the metamodel, in your case
the definition of the enumeration and its literals. You cannot even use
the fact that Enumerations can have properties for which you can define
values on the literals (which are InstanceSpecifications) because these
values would not be translated into the Ecore definition of the profile.
You will probably have to implement a large nested if-then-else-endif
expression covering every value of your enumeration, to check for the
corresponding values in the strings. Perhaps this could be made cleaner
using Tuples to implement something like an associative array:
let array : Set(Tuple(s : String, d : D_Enum)) =
Set{Tuple{s = 'D1', d = D_Enum::D1},
Tuple{...}, ...} in
...
You could then make assertions about the correspondence of some string
value with the enumeration value. Assuming that stereotype S extends
metaclass M with a string-valued property p:
array->exists(t | t.s = p and t.d = D)
HTH,
Christian
Andreas Maier wrote:
> Hi,
> I have defined an Enumeration D_Enum in a profile. D_Enum has a few
> literals defined, say D1 and D2. D_Enum is used as the type of a
> property D in a stereotype S in the same profile.
> In an OCL constraint with context S, I would like to access the name of
> the enumeration literal currently set in property D. I need the name
> because I want to compare it against a string.
> The OCL expression
> self.D
> evaluates to the value of the property D, i.e. to one of the possible
> literals D1,D2.
> I can successfully compare that property value to one literal (or a set
> of literals), e.g.
> self.D = <profile-name>::D_Enum::D1
> but this does not solve my problem since I need to compare the literal's
> name (e.g. "D1") against a string.
> I tried
> self.D.name
> to access the name of the literal, but the OCL engine complains with
> "Unrecognized variable (name)".
> -> How can I access the name of the actually set literal from within
> that context ?
> Andy
|
|
|
Powered by
FUDForum. Page generated in 0.03729 seconds