Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 12:01 Go to next message
Peacemoon  is currently offline Peacemoon Friend
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 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6690
Registered: July 2009
Senior Member
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 13:38 Go to previous messageGo to next message
Peacemoon  is currently offline Peacemoon Friend
Messages: 14
Registered: November 2010
Junior Member
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 14:01 Go to previous message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6690
Registered: July 2009
Senior Member
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: Sun Sep 22 00:55:12 GMT 2024

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

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

Back to the top