Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Replace/Override EFactory
Replace/Override EFactory [message #421079] Wed, 23 July 2008 15:46 Go to next message
Eclipse UserFriend
Originally posted by: swt.magellium.fr

Hello all !

I'd like to override the "create(EClass)" method of EFactoryImpl.
Is there a simple way to achieve that ?

For instance, I'd like to create my own EFactoryImpl class (subclass of
emf's EFactoryImpl) and to get all Factories to extend this class
instead of emf's EFactoryImpl when generating model code...

Thanks a lot in advance !
Stephane
Re: Replace/Override EFactory [message #421080 is a reply to message #421079] Wed, 23 July 2008 17:07 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: swt.magellium.fr

I found that the "create(EClass)" method of EFactoryImpl seems to be
used only for dynamic EObjects, and that each subclasses (package
factories) redefines this "create" method in order to create non-dynamic
objects (I think there is a way to always create dynamic objects, but I
don't want dynamic objects...)
What I'd really like to do is to have a piece of code executed whenever
a model object is created...

SWT wrote :
> Hello all !
>
> I'd like to override the "create(EClass)" method of EFactoryImpl.
> Is there a simple way to achieve that ?
>
> For instance, I'd like to create my own EFactoryImpl class (subclass of
> emf's EFactoryImpl) and to get all Factories to extend this class
> instead of emf's EFactoryImpl when generating model code...
>
> Thanks a lot in advance !
> Stephane
Re: Replace/Override EFactory [message #421086 is a reply to message #421080] Wed, 23 July 2008 17:32 Go to previous message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Stephane,

There's no generic way to modify the behaviour of generated factories at
runtime. See Ed's famous metapher of the "poisoned fountain":
http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg0 5672.html

Of course you can handcraft all aspects of your own generated code,
including the factory interfaces and implementation classes: add
methods, change bodies, etc.. Just mark the changed methods "@generated
NOT". IIRC you can also change the super class and preserve this change
by adding an @extends JavaDoc comment. See
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.emf/org .eclipse.emf.cdo/plugins/org.eclipse.emf.cdo/src/org/eclipse /emf/cdo/eresource/CDOResource.java?root=Modeling_Project&am p;view=co
for an example.

Cheers
/Eike



SWT schrieb:
> I found that the "create(EClass)" method of EFactoryImpl seems to be
> used only for dynamic EObjects, and that each subclasses (package
> factories) redefines this "create" method in order to create
> non-dynamic objects (I think there is a way to always create dynamic
> objects, but I don't want dynamic objects...)
> What I'd really like to do is to have a piece of code executed
> whenever a model object is created...
>
> SWT wrote :
>> Hello all !
>>
>> I'd like to override the "create(EClass)" method of EFactoryImpl.
>> Is there a simple way to achieve that ?
>>
>> For instance, I'd like to create my own EFactoryImpl class (subclass
>> of emf's EFactoryImpl) and to get all Factories to extend this class
>> instead of emf's EFactoryImpl when generating model code...
>>
>> Thanks a lot in advance !
>> Stephane


Previous Topic:instantiate a containment reference between multiple ecore models
Next Topic:[Teneo]HibernateResource save very slowly!!
Goto Forum:
  


Current Time: Fri Apr 26 03:26:09 GMT 2024

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

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

Back to the top