I have defined a dynamic model with two classes A and B.
I have an interface modeled regularly through the model editor: IMyInterface.
I add IMyInterface to the eSuperTypes lists of both A and B but I am getting the hint that IMyInterface is not a valid classifier as the factory of IMyInterface cannot instantiate IMyInterface directly.
How do I handle this?
This is the code for A (B is configured in the same way):
EClass a = EcoreFactory.eINSTANCE.createEClass();
a.setName("A");
a.getESuperTypes().add(RegularPackage.Literals.IMyInterface);
pak.getEClassifiers().add(a);
Am 01.10.2012 11:25, schrieb Erdal Karaca:
> I have defined a dynamic model with two classes A and B.
> I have an interface modeled regularly through the model editor: IMyInterface.
>
> I add IMyInterface to the eSuperTypes lists of both A and B but I am getting the hint that IMyInterface is not a valid
> classifier as the factory of IMyInterface cannot instantiate IMyInterface directly.
>
> How do I handle this?
>
> This is the code for A (B is configured in the same way):
>
>
> EClass a = EcoreFactory.eINSTANCE.createEClass();
Could the problem be that you don't setInterface(true)?
Hi Eike,
The IMyInterface is properly modeled and works as expected.
I think I am missing something that the code generator does itself but I am missing for my dynamic model.
I.e.: The 'A' EClass should not be an interface but implement IMyInterface which is defined using the ecore model editor and works as expected.
Is IMyInterface an EClass that's wrapping some existing actual Java
interface? Dynamic models can't support that case...
On 01/10/2012 11:50 AM, Erdal Karaca wrote:
> Hi Eike,
> The IMyInterface is properly modeled and works as expected.
> I think I am missing something that the code generator does itself but
> I am missing for my dynamic model.
>
> I.e.: The 'A' EClass should not be an interface but implement
> IMyInterface which is defined using the ecore model editor and works
> as expected.
So what exactly is the problem then? Of course you can't instantiate an
abstract class, but you should be able to instantiate an A or a B.
On 02/10/2012 9:53 AM, Erdal Karaca wrote:
> Hi Ed,
> IMyInterface is defined as interface and has no 'Instance Type Name' set.
> Below is the XMI of that type:
>
>
> <eClassifiers xsi:type="ecore:EClass" name="IMyInterface"
> abstract="true" interface="true">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="id"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
> iD="true">
> </eStructuralFeatures>
> </eClassifiers>
>
>
> Ed Merks wrote on Tue, 02 October 2012 01:23
>> Erdal,
>>
>> Is IMyInterface an EClass that's wrapping some existing actual Java
>> interface? Dynamic models can't support that case...
>
>
If I try to create an instance of A or B using the 'default dynamic EFactory', the ecore internals will delegate to the EFactory of IMyInstance and since that is an interface and cannot be instantiated I will get the invalid classifier.
E.g. 'pak' is the EPackage of the dynamic model:
EClass a = EcoreFactory.eINSTANCE.createEClass();
a.setName("A");
a.getESuperTypes().add(RegularPackage.Literals.IMyInterface);
pak.getEClassifiers().add(a);
pak.getEFactoryInstance().create(A);
Do I miss something else?
Ed Merks wrote on Tue, 02 October 2012 04:15
So what exactly is the problem then? Of course you can't instantiate an
abstract class, but you should be able to instantiate an A or a B.
public EObject create(EClass eClass)
{
if (getEPackage() != eClass.getEPackage() || eClass.isAbstract())
{
throw new IllegalArgumentException("The class '" +
eClass.getName() + "' is not a valid classifier");
}
for (List<EClass> eSuperTypes = eClass.getESuperTypes();
!eSuperTypes.isEmpty(); )
{
EClass eSuperType = eSuperTypes.get(0);
if (eSuperType.getInstanceClass() != null)
{
EObject result =
eSuperType.getEPackage().getEFactoryInstance().create(eSuperType);
((InternalEObject)result).eSetClass(eClass);
return result;
}
eSuperTypes = eSuperType.getESuperTypes();
}
return basicCreate(eClass);
}
So eSuperType.getInstanceClass() != null must be true for you to have a
problem...
If your IMyInstance is in a different package and you're referring to
the generated package instance for this EClass, you won't be able to
create dynamic instances of it. Such a dynamic instance would have to
implement the generated interface, but there exists no implementation
class that does so...
On 02/10/2012 10:25 AM, Erdal Karaca wrote:
> If I try to create an instance of A or B using the 'default dynamic
> EFactory', the ecore internals will delegate to the EFactory of
> IMyInstance and since that is an interface and cannot be instantiated
> I will get the invalid classifier.
>
> E.g. 'pak' is the EPackage of the dynamic model:
>
>
> EClass a = EcoreFactory.eINSTANCE.createEClass();
> a.setName("A");
> a.getESuperTypes().add(RegularPackage.Literals.IMyInterface);
> pak.getEClassifiers().add(a);
>
> pak.getEFactoryInstance().create(A);
>
>
>
> Do I miss something else?
>
> Ed Merks wrote on Tue, 02 October 2012 04:15
>> So what exactly is the problem then? Of course you can't instantiate
>> an abstract class, but you should be able to instantiate an A or a B.
>
>