Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » DynamicEObjectImpl instead of EObject?
DynamicEObjectImpl instead of EObject? [message #1229892] Fri, 10 January 2014 13:21 Go to next message
Peter Johnsen is currently offline Peter JohnsenFriend
Messages: 60
Registered: January 2012
Member
Hi,

I've a simple Ecore model of one class: A, and I've some code that reads an xmi-model that conforms to the Ecore model:

ResourceSet rs = new ResourceSetImpl();
rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put
  Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl() );
    
URI uri = URI.createFileURI( new File( "model.xmi" ).getAbsolutePath() );
Resource r = rs.getResource( uri, true );

A a = (A)r.getContents().get( 0 );


What I get is this:

java.lang.ClassCastException: org.eclipse.emf.ecore.impl.DynamicEObjectImpl cannot be cast to test.A

Why is that? I know it should be possible to do this somehow? Smile

Thanks for any help!
Re: DynamicEObjectImpl instead of EObject? [message #1229917 is a reply to message #1229892] Fri, 10 January 2014 14:35 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30692
Registered: July 2009
Senior Member
Peter,

Comments below.


On 10/01/2014 2:21 PM, Peter Johnsen wrote:
> Hi,
>
> I've a simple Ecore model of one class: A, and I've some code that
> reads an xmi-model that conforms to the Ecore model:
>
>
> ResourceSet rs = new ResourceSetImpl();
> rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put
> Resource.Factory.Registry.DEFAULT_EXTENSION, new
> XMIResourceFactoryImpl() );
> URI uri = URI.createFileURI( new File( "model.xmi"
> ).getAbsolutePath() );
> Resource r = rs.getResource( uri, true );
>
> A a = (A)r.getContents().get( 0 );
>
>
> What I get is this:
>
> java.lang.ClassCastException:
> org.eclipse.emf.ecore.impl.DynamicEObjectImpl cannot be cast to test.A
Did you do something that register your dynamic model? Is this running
in a context where your generated model is registered?
>
> Why is that? I know it should be possible to do this somehow? :)
>
> Thanks for any help!
Re: DynamicEObjectImpl instead of EObject? [message #1229929 is a reply to message #1229892] Fri, 10 January 2014 15:15 Go to previous messageGo to next message
Peter Johnsen is currently offline Peter JohnsenFriend
Messages: 60
Registered: January 2012
Member
I also register the package - still same exception though:

rs.getPackageRegistry().put( APackage.eNS_URI, APackage.eINSTANCE );

[Updated on: Fri, 10 January 2014 15:15]

Report message to a moderator

Re: DynamicEObjectImpl instead of EObject? [message #1229930 is a reply to message #1229917] Fri, 10 January 2014 15:19 Go to previous messageGo to next message
Peter Johnsen is currently offline Peter JohnsenFriend
Messages: 60
Registered: January 2012
Member
Ed Merks wrote on Fri, 10 January 2014 09:35

Did you do something that register your dynamic model? Is this running
in a context where your generated model is registered?


Thanks!

It's a very basic test - everything runs within the same EMF project.
Re: DynamicEObjectImpl instead of EObject? [message #1229955 is a reply to message #1229892] Fri, 10 January 2014 16:40 Go to previous message
Peter Johnsen is currently offline Peter JohnsenFriend
Messages: 60
Registered: January 2012
Member
I located the error. The reason for this error was because the model (.xmi) was not consistent any more with the Ecore model. That is, the Ecore model had been updated after the model was created.
Previous Topic:Design application with EMF and EclipseLink
Next Topic:Model version compatibility with serialized data
Goto Forum:
  


Current Time: Thu Dec 12 19:41:58 GMT 2019

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

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

Back to the top