ECore "abstract attribute" [message #877513] |
Sat, 26 May 2012 22:51 |
Søren Qvist 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 #877674 is a reply to message #877666] |
Sun, 27 May 2012 11:07 |
Ed Willink 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 |
|
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
>>
>>
>>
>>
>>
>>
|
|
|
Powered by
FUDForum. Page generated in 0.03515 seconds