Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Dynamic Model: invalid classifier
Dynamic Model: invalid classifier [message #929178] Mon, 01 October 2012 09:25 Go to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 756
Registered: July 2009
Senior Member
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);
Re: Dynamic Model: invalid classifier [message #929199 is a reply to message #929178] Mon, 01 October 2012 09:37 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 5590
Registered: July 2009
Senior Member
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)?

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


> a.setName("A");
> a.getESuperTypes().add(RegularPackage.Literals.IMyInterface);
> pak.getEClassifiers().add(a);
>
Re: Dynamic Model: invalid classifier [message #929216 is a reply to message #929199] Mon, 01 October 2012 09:50 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 756
Registered: July 2009
Senior Member
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.
Re: Dynamic Model: invalid classifier [message #930204 is a reply to message #929216] Tue, 02 October 2012 05:23 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26285
Registered: July 2009
Senior Member
Erdal,

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.
Re: Dynamic Model: invalid classifier [message #930321 is a reply to message #930204] Tue, 02 October 2012 07:53 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 756
Registered: July 2009
Senior Member
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...

Re: Dynamic Model: invalid classifier [message #930341 is a reply to message #930321] Tue, 02 October 2012 08:15 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26285
Registered: July 2009
Senior Member
Erdal,

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...
>
>
Re: Dynamic Model: invalid classifier [message #930349 is a reply to message #930341] Tue, 02 October 2012 08:25 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 756
Registered: July 2009
Senior Member
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.

Re: Dynamic Model: invalid classifier [message #930371 is a reply to message #930349] Tue, 02 October 2012 08:50 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26285
Registered: July 2009
Senior Member
Erdal,

That code looks like this:

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.
>
>
Previous Topic:Error: "annotations are only available if source level is 1.5"
Next Topic:[CDO] NPE when requesting an EObject from a different view that is TRANSIENT
Goto Forum:
  


Current Time: Sun Dec 21 07:07:57 GMT 2014

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

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