Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Class-scope operations
Class-scope operations [message #755335] Tue, 08 November 2011 03:19 Go to next message
Vlad Gheorghe is currently offline Vlad Gheorghe
Messages: 111
Registered: May 2011
Senior Member

Hello,

Is there a way to declare class-scope operations in EMF ? (Which would result in static methods in Java code).

Regards,
Vlad
Re: Class-scope operations [message #755349 is a reply to message #755335] Tue, 08 November 2011 03:39 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26014
Registered: July 2009
Senior Member
Vlad,

No, you can only write those in the Java code. (And they sound like the
type of thing you'd not even need to put in the model code itself.)


On 08/11/2011 9:19 AM, Vlad Gheorghe wrote:
>
> Hello,
>
> Is there a way to declare class-scope operations in EMF ? (Which would
> result in static methods in Java code).
>
> Regards,
> Vlad
>
Re: Class-scope operations [message #755876 is a reply to message #755349] Wed, 09 November 2011 17:46 Go to previous messageGo to next message
Vlad Gheorghe is currently offline Vlad Gheorghe
Messages: 111
Registered: May 2011
Senior Member

Hi Ed,

I agree, these things don't look right, but they are part of a workaround of what seems to be a possible EMF limitation.

Let me elaborate.

Suppose we have a model Mbase, which contains base domain concepts. We expect that this model will be extended by different models MA, MB, ..., in order to obtain specific functionality.

In Mbase, we have an enumerated type CategoryKind, with values Cat1, Cat2, Cat3.
In MA, we would like to add the categories CatA1, CatA2.

Also in Mbase, there is a class A, with attribute category.

We would like that A.category have a type which contains the extension of Mbase::CategoryKind (Cat1, Cat2, Cat3), but which is also extesible by arbitrary values.

Because EEnums do not support generalization, we cannot type A.category with such a type.

My workaround was to declare A.category:EInt, and provide conversion utilities from each EEnum to EInt, making sure the values do not overlap.

Should EEnum support generalization ?

Regards,
Vlad

Re: Class-scope operations [message #755896 is a reply to message #755876] Thu, 10 November 2011 00:34 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4035
Registered: July 2009
Senior Member
Hi Vlad
> Should EEnum support generalization ?
I would say no. Enumerations are a closed concept and at the
implementation-ish Java-like level that Ecore supports, it would be
strange if one perspective's expectation of a closed set of values is
changed by another perspective's extensibility convenience.

For extensible Enumerations you needer a higher level of abstraction in
which the open enumeration is compiled to the closed implementation
EEnum. I suspect that a UML Package Merge supports Enumeration merge;
otherwise you may need your own MtoM solution at compile time, or a
dynamic allocation at run-time.

Regards

Ed Willink
Re: Class-scope operations [message #755914 is a reply to message #755876] Thu, 10 November 2011 02:47 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26014
Registered: July 2009
Senior Member
Vlad,

Comments below.

On 09/11/2011 11:46 PM, Vlad Gheorghe wrote:
>
> Hi Ed,
>
> I agree, these things don't look right, but they are part of a
> workaround of what seems to be a possible EMF limitation.
>
> Let me elaborate.
>
> Suppose we have a model Mbase, which contains base domain concepts. We
> expect that this model will be extended by different models MA, MB,
> ..., in order to obtain specific functionality.
>
> In Mbase, we have an enumerated type CategoryKind, with values Cat1,
> Cat2, Cat3.
Of course enums are not extensible.
> In MA, we would like to add the categories CatA1, CatA2.
>
> Also in Mbase, there is a class A, with attribute category.
>
> We would like that A.category have a type which contains the extension
> of Mbase::CategoryKind (Cat1, Cat2, Cat3), but which is also extesible
> by arbitrary values.
You can't use enums that way in any language that supports enums.
>
> Because EEnums do not support generalization, we cannot type
> A.category with such a type.
You should use integer values if you expect it to be extensible.
>
> My workaround was to declare A.category:EInt, and provide conversion
> utilities from each EEnum to EInt, making sure the values do not overlap.
And what do you do if you have a value that's not in the integer range
supported by the enum?
>
> Should EEnum support generalization ?
No, it doesn't make sense. A base implementation would end up with
values that can't be represented by the declared type. The whole point
of an enum is that every possible value is enumerated...

I'm not sure how any of this requires generating static methods in the
implementation class. Any conversion could be done as a static method
in some other class...
>
> Regards,
> Vlad
>
>
Re: Class-scope operations [message #756399 is a reply to message #755914] Sat, 12 November 2011 12:52 Go to previous messageGo to next message
Vlad Gheorghe is currently offline Vlad Gheorghe
Messages: 111
Registered: May 2011
Senior Member
Hello Ed, Ed,

Ed Merks wrote on Thu, 10 November 2011 09:47
Vlad,

> We would like that A.category have a type which contains the extension
> of Mbase::CategoryKind (Cat1, Cat2, Cat3), but which is also extesible
> by arbitrary values.
You can't use enums that way in any language that supports enums.
>
> Because EEnums do not support generalization, we cannot type
> A.category with such a type.
You should use integer values if you expect it to be extensible.

I try to use Integer as the type of the attribute - so that it can hold arbitrary values, but define the known set of values at Mbase level as an EEnum.

Quote:

>
> My workaround was to declare A.category:EInt, and provide conversion
> utilities from each EEnum to EInt, making sure the values do not overlap.
And what do you do if you have a value that's not in the integer range
supported by the enum?

Well, this is just a data model whose instances will be "interpreted" by a runtime engine. For each defined value there will correspond a behaviour implemented in the engine. There is a requirement that the engine must be extensible - new "categories" can be added (in MA, MB), and corresponding policies must be implemented as engine extensions.

The intention in using the EEnum is to have a fixed list of values for the base categories, in order to get some type safety *into* the model. (better than using Integer values directly)

If the integer value is not amongst the base values, then it may be defined in the extended set of categories, otherwise the instance is invalid.

I'd also like to use OCL to define constraints for these models.

One related issue is that the value of an EEnum Literal is not available in OCL, so that I can compare it with the Integer attribute. (I've asked about this in the OCL form).

(Is it so wrong to have it accessible from OCL ? )

Quote:

>
> Should EEnum support generalization ?
No, it doesn't make sense. A base implementation would end up with
values that can't be represented by the declared type. The whole point
of an enum is that every possible value is enumerated...

I can agree with this.

Still, if I can't convert it to Integer, I have no solution to my practical problem.

Quote:

I'm not sure how any of this requires generating static methods in the
implementation class. Any conversion could be done as a static method
in some other class...

Correct.
But I need it to be accessible from OCL queries.

To sum it up:
- extensible EEnums - doesn't make sense
- declare static operations in EMF - no
- access the EEnumLiteral value from OCL ?
- it's not supported right now out of the box, but shouldn't it ?
(also see http://www.eclipse.org/forums/index.php/mv/msg/261496/754965/#msg_754965 )
- access static methods (declared in Java) from OCL ?

Regards,
Vlad Gheorghe

Re: Class-scope operations [message #756441 is a reply to message #756399] Sun, 13 November 2011 06:13 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26014
Registered: July 2009
Senior Member
Vlad,

Comments below.

On 12/11/2011 6:52 PM, Vlad Gheorghe wrote:
> Hello Ed, Ed,
>
> Ed Merks wrote on Thu, 10 November 2011 09:47
>> Vlad,
>>
>> > We would like that A.category have a type which contains the
>> extension > of Mbase::CategoryKind (Cat1, Cat2, Cat3), but which is
>> also extesible > by arbitrary values.
>> You can't use enums that way in any language that supports enums.
>> >
>> > Because EEnums do not support generalization, we cannot type >
>> A.category with such a type.
>> You should use integer values if you expect it to be extensible.
>
> I try to use Integer as the type of the attribute - so that it can
> hold arbitrary values, but define the known set of values at Mbase
> level as an EEnum.
>
> Quote:
>> >
>> > My workaround was to declare A.category:EInt, and provide
>> conversion > utilities from each EEnum to EInt, making sure the
>> values do not overlap.
>> And what do you do if you have a value that's not in the integer
>> range supported by the enum?
>
> Well, this is just a data model whose instances will be "interpreted"
> by a runtime engine. For each defined value there will correspond a
> behaviour implemented in the engine. There is a requirement that the
> engine must be extensible - new "categories" can be added (in MA, MB),
> and corresponding policies must be implemented as engine extensions.
Again, enums aren't extensible so using them as the basis for an
extensible design doesn't sound like the right approach.
>
> The intention in using the EEnum is to have a fixed list of values for
> the base categories, in order to get some type safety *into* the
> model. (better than using Integer values directly)
I don't see how it's better when the enumeration doesn't ever enumerate
all possibilities.
>
> If the integer value is not amongst the base values, then it may be
> defined in the extended set of categories, otherwise the instance is
> invalid.
And how many extended categories would you define. How would any code
knowing about the base even know about those additional categories.
>
> I'd also like to use OCL to define constraints for these models.
>
> One related issue is that the value of an EEnum Literal is not
> available in OCL, so that I can compare it with the Integer attribute.
> (I've asked about this in the OCL form).
Sounds like yet another reason not to use enums.
>
> (Is it so wrong to have it accessible from OCL ? )
That's an OCL question best asked on the OCL newsgroup.
>
> Quote:
>> >
>> > Should EEnum support generalization ?
>> No, it doesn't make sense. A base implementation would end up with
>> values that can't be represented by the declared type. The whole
>> point of an enum is that every possible value is enumerated...
>
> I can agree with this.
>
> Still, if I can't convert it to Integer, I have no solution to my
> practical problem.
People solved problems like this before Java had enums so I'm sure you
don't need them and I don't think they're a practical solution to a
problem that needs to deal with extensibility.
>
> Quote:
>> I'm not sure how any of this requires generating static methods in
>> the implementation class. Any conversion could be done as a static
>> method in some other class...
>
> Correct.
> But I need it to be accessible from OCL queries.
OCL shouldn't be accessing the implementation classes...
>
> To sum it up:
> - extensible EEnums - doesn't make sense
No.
> - declare static operations in EMF - no
You should only be using the APIs generated for your models and
interfaces in Java don't support static methods.
> - access the EEnumLiteral value from OCL ?
It's an OCL question.
> - it's not supported right now out of the box, but shouldn't it ?
There's always the balance between what the OMG specification says and
what's pragmatic.
> (also see
> http://www.eclipse.org/forums/index.php/mv/msg/261496/754965/#msg_754965
> )
> - access static methods (declared in Java) from OCL ?
Again, an OCL question.
>
> Regards,
> Vlad Gheorghe
>
>
Re: Class-scope operations [message #756483 is a reply to message #756441] Sun, 13 November 2011 16:54 Go to previous message
Vlad Gheorghe is currently offline Vlad Gheorghe
Messages: 111
Registered: May 2011
Senior Member
Hello Ed,

Thank you for the insights, and all the energy you put in supporting the EMF community.


Kind regards,
Vlad Gheorghe
Previous Topic:[CDO] CDOView omits ETypes in Ecore models
Next Topic:TENEO EAV (Entity-attribute-value model ) Problem
Goto Forum:
  


Current Time: Fri Aug 29 22:24:55 EDT 2014

Powered by FUDForum. Page generated in 0.03726 seconds