org.eclipse.emf.ecore.impl.DynamicEObjectImpl cannot be cast XXX [message #651212] |
Fri, 28 January 2011 12:01 |
Peacemoon Messages: 14 Registered: November 2010 |
Junior Member |
|
|
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 12:03] Report message to a moderator
|
|
|
Re: org.eclipse.emf.ecore.impl.DynamicEObjectImpl cannot be cast XXX [message #651224 is a reply to message #651212] |
Fri, 28 January 2011 13:02 |
|
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
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03528 seconds