|
|
|
|
Re: [CDO] Load model under alternative EMF metamodel [message #1741987 is a reply to message #1740624] |
Tue, 16 August 2016 13:39 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Simon,
It's a limitation of dynamic EMF models that it must be able to create
an instance of the non-dynamic super class because that instance is
what's used to emulate the dynamic extension.
So you have two choices. One, don't make this base class abstract. Two,
specialize the factory of this base class.
We did this, for example, for Oomph's Setup model. Here SetupTask
itself is abstract:
public abstract class SetupTaskImpl extends ModelElementImpl implements
SetupTask
{
But we need to be able to create dynamic instances of subclasses of it.
So we hand implemented a non-abstract subclass, i.e., just implement
stubs for any missing implementations:
public final class DynamicSetupTaskImpl extends SetupTaskImpl
{
public boolean isNeeded(SetupTaskContext context) throws Exception
{
return false;
}
public void perform(SetupTaskContext context) throws Exception
{
// Do nothing.
}
}
And in the SetupFactoryImpl we added this hand written method:
@Override
public EObject create(EClass eClass)
{
if (eClass == SetupPackage.Literals.SETUP_TASK)
{
return new DynamicSetupTaskImpl();
}
return createGen(eClass);
}
And used the "Gen" pattern on the original generated method:
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EObject createGen(EClass eClass)
{
So when the SetupFactory needs to create an instance of SetupTask, it
creates a DynamicSetupTaskImpl.
On 16.08.2016 14:20, Simon Goodall wrote:
> Thanks. I've tried changing my code to use different nsURIs. However I
> get a new problem. CDO seems to have problems creating a dynamic
> instance when the super type is a generated abstract class. It fails
> with an invalid classifier exception.
>
> I have created a small project
> (https://github.com/drsgoodall/cdo-test-1) to highlight this. I used
> oomph to install a neon based CDO workspace. The "MainClassTest" can
> be run as a JUnit-Plugin test.
>
> There are two ecore models - base.ecore and example.ecore - both
> generated. There is also an example-v1.ecore which contains my
> previous example.ecore version used to build the embedded repository
> database.
>
> When my object does not have a superclass I am able to load up the v1
> model instance. However when the object extends the class in the
> base.ecore I get the exception.
>
> Regards.
>
> Simon
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03397 seconds