org.eclipse.emf.ecore.impl.DynamicEObjectImpl cannot be cast XXX [message #651212] |
Fri, 28 January 2011 07:01  |
Eclipse User |
|
|
|
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
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07723 seconds