Skip to main content



      Home
Home » Modeling » EMF » DynamicEObjectImpl instead of EObject?
DynamicEObjectImpl instead of EObject? [message #1229892] Fri, 10 January 2014 08:21 Go to next message
Eclipse UserFriend
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 09:35 Go to previous messageGo to next message
Eclipse UserFriend
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 10:15 Go to previous messageGo to next message
Eclipse UserFriend
I also register the package - still same exception though:

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

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

Re: DynamicEObjectImpl instead of EObject? [message #1229930 is a reply to message #1229917] Fri, 10 January 2014 10:19 Go to previous messageGo to next message
Eclipse UserFriend
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 11:40 Go to previous message
Eclipse UserFriend
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: Mon Jun 16 13:24:53 EDT 2025

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

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

Back to the top