Skip to main content



      Home
Home » Modeling » EMF » org.eclipse.emf.ecore.impl.DynamicEObjectImpl cannot be cast XXX
org.eclipse.emf.ecore.impl.DynamicEObjectImpl cannot be cast XXX [message #651212] Fri, 28 January 2011 07:01 Go to next message
Eclipse UserFriend
I have problem to load a persited XMI file.

Here is my XMI File

<?xml version="1.0" encoding="ASCII"?>
<fta:FTASystem xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:fta="http://ftos.in.tum.de/fta" xsi:schemaLocation="http://ftos.in.tum.de/fta ../metamodel/fta.ecore" topEvent="//@element.0">
  <element xsi:type="fta:TopEvent" name="Top Event" subevents="//@element.1">
    <gate xsi:type="fta:OrGate"/>
  </element>
</fta:FTASystem>


And here the code i used to load the XMI file

public static EObject loadModel(String modelFile) throws IOException {	
Resource r; //Resource for model file

    	//Create resource for model file
	    Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
        r = new ResourceSetImpl().createResource(URI.createFileURI(new File(modelFile).getAbsolutePath()));
        
        //Load model file
        r.load(null);

        //Return content of model file
        return r.getContents().get(0);
}


modelFile is just the path to the XMI file.

Everthing works ok until here.

But when i try to cast the returned Package from the loading function to FTASystem,

EObject ftaModel = EcoreLibrary.loadModel2("src/model/control_hardware_faulttree.xmi");
System.out.println((FTASystem)ftaModel);


i received ClassCastException

Exception in thread "main" java.lang.ClassCastException: org.eclipse.emf.ecore.impl.DynamicEObjectImpl cannot be cast to fta.FTASystem


I have googled the problem, but somehow can not find the solution for that.

Really appreciate, when someone points me to the right direction

Thanks

[Updated on: Fri, 28 January 2011 07:03] by Moderator

Re: org.eclipse.emf.ecore.impl.DynamicEObjectImpl cannot be cast XXX [message #651224 is a reply to message #651212] Fri, 28 January 2011 08:02 Go to previous messageGo to next message
Eclipse UserFriend
Please always show us the complete stack trace when you report an exception.

Cheers
/Eike

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



Am 28.01.2011 13:01, schrieb Peacemoon:
> I have problem to load a persited XMI file.
>
> Here is my XMI File
>
> <?xml version="1.0" encoding="ASCII"?>
> <fta:FTASystem xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:fta="http://ftos.in.tum.de/fta" xsi:schemaLocation="http://ftos.in.tum.de/fta ../metamodel/fta.ecore" topEvent="//@element.0">
> <element xsi:type="fta:TopEvent" name="Top Event" subevents="//@element.1">
> <gate xsi:type="fta:OrGate"/>
> </element>
> </fta:FTASystem>
>
>
> And here the code i used to load the XMI file
>
> Resource r; //Resource for model file
>
> //Create resource for model file
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*", new XMIResourceFactoryImpl());
> r = new ResourceSetImpl().createResource(URI.createFileURI(new File(modelFile).getAbsolutePath()));
> //Load model file
> r.load(null);
>
> //Return content of model file
> return r.getContents().get(0);
>
>
> modelFile is just the path to the XMI file.
>
> Everthing works ok until here.
>
> But when i try to cast the returned Package from the loading function to FTASystem,
> System.out.println((FTASystem)ftaModel);
>
> i received ClassCastException
>
> Exception in thread "main" java.lang.ClassCastException: org.eclipse.emf.ecore.impl.DynamicEObjectImpl cannot be cast to fta.FTASystem
>
> I have google the problem, but somehow can not find the solution for that.
>
> Really appreciate, when someone points me to the right direction
>
> Thanks
Re: org.eclipse.emf.ecore.impl.DynamicEObjectImpl cannot be cast XXX [message #651233 is a reply to message #651212] Fri, 28 January 2011 08:38 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

the stack trace is not so special
Exception in thread "main" java.lang.ClassCastException: org.eclipse.emf.ecore.impl.DynamicEObjectImpl cannot be cast to fta.FTASystem
	at javaExt.ShapreGenerator.main(ShapreGenerator.java:24)


ShapreGenerator is my main class.
Re: org.eclipse.emf.ecore.impl.DynamicEObjectImpl cannot be cast XXX [message #651242 is a reply to message #651233] Fri, 28 January 2011 09:01 Go to previous message
Eclipse UserFriend
Am 28.01.2011 14:38, schrieb Peacemoon:
> Hi,
>
> the stack trace is not so special
> Exception in thread "main" java.lang.ClassCastException: org.eclipse.emf.ecore.impl.DynamicEObjectImpl cannot be cast to fta.FTASystem
> at javaExt.ShapreGenerator.main(ShapreGenerator.java:24)
>
> ShapreGenerator is my main class.
So you're not running in OSGi, have no extension registry that registers your package with the global EMF package registry. Please call FTAPackage.eINSTANCE.getClass() at the beginning to trigger initialization and registration of your package.

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
Previous Topic:[CDO] 1 transaction vs N transactions
Next Topic:tooltips in properties view
Goto Forum:
  


Current Time: Wed Jul 09 22:30:21 EDT 2025

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

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

Back to the top