Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Dynamic subclassing of static model classes
Dynamic subclassing of static model classes [message #431909] Wed, 29 July 2009 08:52 Go to next message
Mario Winterer is currently offline Mario WintererFriend
Messages: 136
Registered: July 2009
Senior Member
Hi!

I've played around with dynamic models recently and discovered some
flaws when I've tried to dynamically subclass a static (generated) model
class. Please let me know if I should file bugs for that issues!

(1) It is not possible to instantiate a non-abstract dynamic subclass of
an abstract static base class, as the EFactory-instance tries to create
an instance of the 'nearest' static base class on instantiation which
fails due to it is abstract.
(A possible solution is discussed in 3)

(2) If a dynamic class is defined and added to a static package, the
package factory will still not be able to instantiate the dynamic class,
because the factory is generated too and only checks the static classes.
Although adding dynamic classes to static packages seems to be dirty,
maybe super.create(EClass) should be called instead of throwing an
IllegalArgumentException.

(3) When I use multiple inheritance to subclass two static Ecore classes
Rectangle and Clickable in one single dynamic class Button, the instance
b of class Button is java-instanceof Rectangle.instanceClass but not
java-instanceof Clickable.instanceClass, because - as mentioned 1) - the
factory instantiates the 'nearest' static base class and chooses the
first one in case of multiple base classes (which is S1 in our example).
This issue could be fixed by using the Java Proxy API to dynamically
instatiate a proxy that implements the instance classes (the interfaces)
of all direct static base classes.
(Note that this would also fix the issue mentioned in 1)


Mario
Re: Dynamic subclassing of static model classes [message #431922 is a reply to message #431909] Wed, 29 July 2009 16:46 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Mario,

Comments below.

Mario Winterer wrote:
> Hi!
>
> I've played around with dynamic models recently and discovered some
> flaws when I've tried to dynamically subclass a static (generated)
> model class. Please let me know if I should file bugs for that issues!
>
> (1) It is not possible to instantiate a non-abstract dynamic subclass
> of an abstract static base class, as the EFactory-instance tries to
> create an instance of the 'nearest' static base class on instantiation
> which fails due to it is abstract.
> (A possible solution is discussed in 3)
Yes, this is a limitation. Clearly it's impossible to instantiate an
abstract class and yet it's needed to act as the base in order for the
dynamic instance to behave exactly like the existing implementation...
>
> (2) If a dynamic class is defined and added to a static package, the
> package factory will still not be able to instantiate the dynamic
> class, because the factory is generated too and only checks the static
> classes.
You can't change generated meta data at all.
> Although adding dynamic classes to static packages seems to be dirty,
> maybe super.create(EClass) should be called instead of throwing an
> IllegalArgumentException.
No, it's just not supported.
>
> (3) When I use multiple inheritance to subclass two static Ecore
> classes Rectangle and Clickable in one single dynamic class Button,
> the instance b of class Button is java-instanceof
> Rectangle.instanceClass but not java-instanceof
> Clickable.instanceClass, because - as mentioned 1) - the factory
> instantiates the 'nearest' static base class and chooses the first one
> in case of multiple base classes (which is S1 in our example).
> This issue could be fixed by using the Java Proxy API to dynamically
> instatiate a proxy that implements the instance classes (the
> interfaces) of all direct static base classes.
> (Note that this would also fix the issue mentioned in 1)
I played a bit with Java dynamic proxies but in the end, it's not
possible for them to reuse an existing base class like BasicEObjectImpl
so one ends up having to delegate from the proxy to something that
duplicates all the basic implementation behavior and even then you end
up with problems where the "this" of the proxy is not the same object as
that being delegated to.

The simplest approach is simply to not make the base class abstract.
>
>
> Mario


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Dissolving References?
Next Topic:[CDO] SQL Exception: Failed to create database
Goto Forum:
  


Current Time: Tue Apr 23 13:26:24 GMT 2024

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

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

Back to the top