Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [TEXO] Problem with ClassCastException in ModelPackage
[TEXO] Problem with ClassCastException in ModelPackage [message #623210] Wed, 15 September 2010 19:01 Go to next message
Mark Hoffmann is currently offline Mark Hoffmann
Messages: 102
Registered: July 2009
Location: Jena
Senior Member
Hi,

I created a code-gen.annotationsmodel from my ecore to change the package path.
The enums will not saved in the correct folder from the annotionsmodel, but the package definition in the generated code ist correct.

In my model if have a Contact class and an enum called ContactType. If I call ModelPackage.INSTANCE I get the following exception:

Caused by: java.lang.ClassCastException: org.eclipse.emf.ecore.impl.EEnumImpl cannot be cast to org.eclipse.emf.ecore.EClass
at de.sim.texo.model.common.person.PersonModelPackage.getContac tEClass(PersonModelPackage.java:787)
at de.sim.texo.model.common.person.PersonModelPackage.initializ e(PersonModelPackage.java:405)
at de.sim.texo.model.common.person.PersonModelPackage.<clinit>(PersonModelPackage.java:376)
... 31 more


The generated code looks like this:

/**
* Returns the {@link EClass} '<em><b>Contact</b></em>'.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return an instance of the {@link EClass} '<em><b>Contact</b></em>'
* @generated
*/
public EClass getContactEClass() {
return (EClass) getEPackage().getEClassifiers().get(
CONTACT_CLASSIFIER_ID);
}

I debugged a little bit. This method return the ContactType instead of the Contact.

In my ecore looks like this:

<eClassifiers xsi:type="ecore:EClass" name="Contact">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="type" lowerBound="1" eType="#//ContactType"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="context" lowerBound="1"
eType="#//ContactContextType" defaultValueLiteral="PRIVATE"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="value" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="id" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//ELong"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="note" eType="ecore:EClass common.ecore#//Note"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EEnum" name="ContactType">
<eLiterals name="EMAIL"/>
<eLiterals name="PHONE" value="1"/>
<eLiterals name="MOBILE" value="2"/>
<eLiterals name="FAX" value="3"/>
<eLiterals name="WWW" value="4"/>
<eLiterals name="MESSENGER" value="5"/>
<eLiterals name="OTHER" value="6"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EEnum" name="ContactContextType">
<eLiterals name="PRIVATE"/>
<eLiterals name="BUSINESS" value="1"/>
<eLiterals name="OTHER" value="2"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ContactList">
<eStructuralFeatures xsi:type="ecore:EReference" name="contacts" upperBound="-1"
eType="#//Contact"/>
</eClassifiers>


Does anybody know this problem?

Regards,
Mark
Re: [TEXO] Problem with ClassCastException in ModelPackage [message #623214 is a reply to message #623210] Thu, 16 September 2010 02:52 Go to previous message
Martin Taal is currently offline Martin Taal
Messages: 5329
Registered: July 2009
Senior Member
Hi Mark,
Maybe the CONTACT_CLASSIFIER_ID has a wrong value, i.e. the same value as the classifier id of the enum (can you check
this in the generated ModelPackage class?)?

Can you send me the complete ecore and the annotations model? Then I can try to reproduce the problem.

Btw, what do you mean with this:
The enums will not saved in the correct folder from the annotionsmodel, but the package definition in the generated code
ist correct.

The enum classes were not generated you mean?

gr. Martin

On 09/16/2010 01:01 AM, Mark Hoffmann wrote:
>
> <eClassifiers xsi:type="ecore:EClass" name="Contact">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="type"
> lowerBound="1" eType="#//ContactType"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="context"
> lowerBound="1"
> eType="#//ContactContextType" defaultValueLiteral="PRIVATE"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="value"
> lowerBound="1" eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="id"
> lowerBound="1" eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//ELong"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="note"
> eType="ecore:EClass common.ecore#//Note"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EEnum" name="ContactType">
> <eLiterals name="EMAIL"/>
> <eLiterals name="PHONE" value="1"/>
> <eLiterals name="MOBILE" value="2"/>
> <eLiterals name="FAX" value="3"/>
> <eLiterals name="WWW" value="4"/>
> <eLiterals name="MESSENGER" value="5"/>
> <eLiterals name="OTHER" value="6"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EEnum" name="ContactContextType">
> <eLiterals name="PRIVATE"/>
> <eLiterals name="BUSINESS" value="1"/>
> <eLiterals name="OTHER" value="2"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="ContactList">
> <eStructuralFeatures xsi:type="ecore:EReference" name="contacts"
> upperBound="-1"
> eType="#//Contact"/>
> </eClassifiers>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Previous Topic:[MINT] Coloring of Java-Files in Project Explorer
Next Topic:[EEF] Ant task to generate models and code
Goto Forum:
  


Current Time: Thu Aug 21 22:15:26 EDT 2014

Powered by FUDForum. Page generated in 0.02512 seconds