Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » ECore "abstract attribute"(ECore "abstract attribute")
ECore "abstract attribute" [message #877513] Sat, 26 May 2012 22:51 Go to next message
Søren Qvist is currently offline Søren QvistFriend
Messages: 3
Registered: May 2012
Junior Member
Hi,

I have an EMF ECore Model, that contains an abstract class A and some derived, concrete classes.
Class 'A' contains some attributes, that are common for all subclasses.
Some of those attributes should have a predefined, constant value, that differs for every subclass. (for example: public final static String = "SOME_VALUE")

I tried to model this behaviour by adding the same attribute (same type, same name) in the subclass.
Everytime I create a dynamic instance of the model and try to edit the properties I get an exception (ArrayIndexOutOfBoundsException). Also, the attribute is shown two-times in the editor.

Does anyone have an idea how to get rid of this?

Thank you,
Søren
Re: ECore "abstract attribute" [message #877666 is a reply to message #877513] Sun, 27 May 2012 10:42 Go to previous messageGo to next message
Vlad Gheorghe is currently offline Vlad GheorgheFriend
Messages: 127
Registered: May 2011
Senior Member
Hello Søren,

One solution is to declare the attribute only in the base class as derived and override the getters in the subclasses - but only in the generated Java code.
Of course, this does not work with dynamic EMF (it relies on the Java classes).

Still, the problem seems to be more deep than this.

I think that Ecore/EMF does not support attribute overriding. That is, in the case you describe, each attribute has its own identity - as you can see in the generated metadata (class XXXPackage).
The generated code does not treat the respective attributes as having any special relationship. The symptoms you describe may have to do with the different attributes having the same name.

BTW - do you get any validation errors in the Ecore model ?

Regards,
Vlad





Re: ECore "abstract attribute" [message #877674 is a reply to message #877666] Sun, 27 May 2012 11:07 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

It's not just an Ecore/EMF limitation; it's also an EMOF, UML
limitation, and you'll have a troublesome time in Java or C++ too.

Properties are not polymorphic; Operations are. So if you want
polymorphism use an operation.

Regards

Ed Willink


On 27/05/2012 11:42, Vlad Gheorghe wrote:
> Hello Søren,
>
> One solution is to declare the attribute only in the base class as
> derived and override the getters in the subclasses - but only in the
> generated Java code.
> Of course, this does not work with dynamic EMF (it relies on the Java
> classes).
>
> Still, the problem seems to be more deep than this.
>
> I think that Ecore/EMF does not support attribute overriding. That is,
> in the case you describe, each attribute has its own identity - as you
> can see in the generated metadata (class XXXPackage).
> The generated code does not treat the respective attributes as having
> any special relationship. The symptoms you describe may have to do
> with the different attributes having the same name.
>
> BTW - do you get any validation errors in the Ecore model ?
>
> Regards,
> Vlad
>
>
>
>
>
>
Re: ECore "abstract attribute" [message #877711 is a reply to message #877674] Sun, 27 May 2012 13:36 Go to previous message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

UML provides property redefinition and subsetting for cases like this. The
Eclipse UML2 code generator supports both of these constructs, though not
in the Ecore that it produces, of course. And, of course, not in dynamic
models.

Cheers,

Christian

Ed Willink <ed@xxxxxxxx.uk> wrote:
> Hi
>
> It's not just an Ecore/EMF limitation; it's also an EMOF, UML limitation,
> and you'll have a troublesome time in Java or C++ too.
>
> Properties are not polymorphic; Operations are. So if you want
> polymorphism use an operation.
>
> Regards
>
> Ed Willink
>
>
> On 27/05/2012 11:42, Vlad Gheorghe wrote:
>> Hello Søren,
>>
>> One solution is to declare the attribute only in the base class as >
>> derived and override the getters in the subclasses - but only in the >
>> generated Java code.
>> Of course, this does not work with dynamic EMF (it relies on the Java > classes).
>>
>> Still, the problem seems to be more deep than this.
>>
>> I think that Ecore/EMF does not support attribute overriding. That is, >
>> in the case you describe, each attribute has its own identity - as you >
>> can see in the generated metadata (class XXXPackage).
>> The generated code does not treat the respective attributes as having >
>> any special relationship. The symptoms you describe may have to do >
>> with the different attributes having the same name.
>>
>> BTW - do you get any validation errors in the Ecore model ?
>>
>> Regards,
>> Vlad
>>
>>
>>
>>
>>
>>
Previous Topic:[TENEO/CDO] Reverse engineer a JPA annotated Pojo model
Next Topic:[TENEO] No zip download?
Goto Forum:
  


Current Time: Fri Apr 26 18:37:31 GMT 2024

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

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

Back to the top