Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » EEnumLiteral and Integer
EEnumLiteral and Integer [message #754631] Thu, 03 November 2011 16:42 Go to next message
Vlad Gheorghe is currently offline Vlad GheorgheFriend
Messages: 127
Registered: May 2011
Senior Member
Hello,

In Ecore, EEnumLiterals have an associated numeric value.

How can this value be obtained (as Integer) in an OCL expression defined for the Ecore model which defines an EEnum ?


Regards,
Vlad
Re: EEnumLiteral and Integer [message #754691 is a reply to message #754631] Thu, 03 November 2011 20:55 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You cannot do this directly; it's contrary to the UML philosophy of
Enumerations.

If you just want to establish an order then you can use the index in the
enumerations.

e.g.
MyEnumeration.allInstances()->asOrderedSet()->indexOf(MyEnumeration::MyEnumerationLiteral)

NB the asOrderedSet() is because allInstances is specified to return a
Set rather than an OrderedSet. The implementation happens to be an
OrderedSet so ->asOrderedSet() does a type-cast. [This could be changed
in a future OMG OCL specification, except that this allInstances() is
inconsistent with Classifier.allInstances().
MyEnumeration.ownedLiterals()->indexOf(MyEnumeration::MyEnumerationLiteral)
is a more likely future (that should work now with the new pivot rather
than Ecore binding).]

If you really want the Ecore value, you must provide a Java helper
function. The library Ecore binding is not easy to extend, so I would
recommend defining a helper in some arbitrary class so that you can do

myArbitraryClass.getMyEnumerationValue(myEnumerationLiteral)

and invoke the one line hand-coded Java in the arbitrary class.

[The new pivot binding has a modelled library so you could add an
Enumeration::value derived property mapped to a Java class that would do
what you want for any Enumeration.]

Regards

Ed Willink



On 03/11/2011 17:42, Vlad Gheorghe wrote:
> Hello,
>
> In Ecore, EEnumLiterals have an associated numeric value.
>
> How can this value be obtained (as Integer) in an OCL expression
> defined for the Ecore model which defines an EEnum ?
>
>
> Regards,
> Vlad
Re: EEnumLiteral and Integer [message #754960 is a reply to message #754691] Sat, 05 November 2011 21:10 Go to previous messageGo to next message
Vlad Gheorghe is currently offline Vlad GheorgheFriend
Messages: 127
Registered: May 2011
Senior Member

Thank you for the response - informative, as always.


I tried to implement the utility class, but I couldn't find a way to define a class-scope operation in EMF (that is, static method in Java). That means that I need to have an instance of the utility class in order to call the helper operation from OCL.

Am I missing something here ?
(I know this belongs to the EMF forum, but I feel that the solution is trivial...)

Regards,
Vlad Gheorghe
Re: EEnumLiteral and Integer [message #754965 is a reply to message #754960] Sat, 05 November 2011 21:57 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Indeed you cannot define a cklass scope methosd.
Define an instnace scpe method in which the 'self' is never actually used.

Regards

Ed Willink

On 05/11/2011 21:10, Vlad Gheorghe wrote:
>
> Thank you for the response - informative, as always.
>
>
> I tried to implement the utility class, but I couldn't find a way to
> define a class-scope operation in EMF (that is, static method in
> Java). That means that I need to have an instance of the utility class
> in order to call the helper operation from OCL.
>
> Am I missing something here ?
> (I know this belongs to the EMF forum, but I feel that the solution is
> trivial...)
>
> Regards,
> Vlad Gheorghe
Previous Topic:How to get the elements of OCL document (.ocl)
Next Topic:Validate an ecore model with ocl constraint from a standalone application
Goto Forum:
  


Current Time: Thu Apr 25 05:59:45 GMT 2024

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

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

Back to the top