Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » ClassCastException on.DynamicEObjectImpl
ClassCastException on.DynamicEObjectImpl [message #655572] Mon, 21 February 2011 14:24 Go to next message
El Arbi Aboussoror is currently offline El Arbi Aboussoror
Messages: 88
Registered: June 2010
Member
Hello,

I have the follwing error when trying to cast an EObject to one of my generated EMF model element. This is the complete error trace:

Quote:


!SESSION 2011-02-21 20:14:21.108 -----------------------------------------------
eclipse.buildId=M20100909-0800
java.version=1.6.0_23
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=fr_FR
Framework arguments: -product org.eclipse.platform.ide
Command-line arguments: -product org.eclipse.platform.ide -data D:\workspaces\wp_irit_ifgui/../runtime-EclipseApplication -dev file:D:/workspaces/wp_irit_ifgui/.metadata/.plugins/org.ecli pse.pde.core/Eclipse Application/dev.properties -os win32 -ws win32 -arch x86_64 -consoleLog

!ENTRY org.eclipse.emf.ecore 2 0 2011-02-21 20:14:26.753
!MESSAGE Both 'org.eclipse.gmf.bridge.trace' and 'org.eclipse.xpand.incremental' register an extension parser for 'trace'
sEltVar: IN!var
instance_var: IN!server_var

!ENTRY org.eclipse.ui.workbench 4 0 2011-02-21 20:14:27.445
!MESSAGE Unable to create view ID fr.irit.ifclipse.views.IFConfigurationView: org.eclipse.emf.ecore.impl.DynamicEObjectImpl cannot be cast to fr.irit.ifclipse.metamodel.IFConfig.IFConfig
!STACK 0
java.lang.ClassCastException: org.eclipse.emf.ecore.impl.DynamicEObjectImpl cannot be cast to fr.irit.ifclipse.metamodel.IFConfig.IFConfig
at fr.irit.ifclipse.views.IFConfigurationView$ViewContentProvid er.initialize(IFConfigurationView.java:233)
at fr.irit.ifclipse.views.IFConfigurationView$ViewContentProvid er.getElements(IFConfigurationView.java:158)
at org.eclipse.jface.viewers.StructuredViewer.getRawChildren(St ructuredViewer.java:989)
at org.eclipse.jface.viewers.ColumnViewer.getRawChildren(Column Viewer.java:703)
at org.eclipse.jface.viewers.AbstractTreeViewer.getRawChildren( AbstractTreeViewer.java:1332)
at org.eclipse.jface.viewers.TreeViewer.getRawChildren(TreeView er.java:391)
at org.eclipse.jface.viewers.StructuredViewer.getFilteredChildr en(StructuredViewer.java:896)
at org.eclipse.jface.viewers.AbstractTreeViewer.getSortedChildr en(AbstractTreeViewer.java:601)
at org.eclipse.jface.viewers.AbstractTreeViewer$1.run(AbstractT reeViewer.java:801)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator .java:70)
at org.eclipse.jface.viewers.AbstractTreeViewer.createChildren( AbstractTreeViewer.java:778)
at org.eclipse.jface.viewers.TreeViewer.createChildren(TreeView er.java:644)
at org.eclipse.jface.viewers.AbstractTreeViewer.createChildren( AbstractTreeViewer.java:749)
at org.eclipse.jface.viewers.AbstractTreeViewer.internalInitial izeTree(AbstractTreeViewer.java:1492)
at org.eclipse.jface.viewers.TreeViewer.internalInitializeTree( TreeViewer.java:833)
at org.eclipse.jface.viewers.AbstractTreeViewer$5.run(AbstractT reeViewer.java:1476)
at org.eclipse.jface.viewers.StructuredViewer.preservingSelecti on(StructuredViewer.java:1422)
at org.eclipse.jface.viewers.TreeViewer.preservingSelection(Tre eViewer.java:403)
at org.eclipse.jface.viewers.StructuredViewer.preservingSelecti on(StructuredViewer.java:1383)
at org.eclipse.jface.viewers.AbstractTreeViewer.inputChanged(Ab stractTreeViewer.java:1469)
at org.eclipse.jface.viewers.ContentViewer.setInput(ContentView er.java:274)
at org.eclipse.jface.viewers.StructuredViewer.setInput(Structur edViewer.java:1664)
at fr.irit.ifclipse.views.IFConfigurationView.createPartControl (IFConfigurationView.java:303)
at org.eclipse.ui.internal.ViewReference.createPartHelper(ViewR eference.java:375)
at org.eclipse.ui.internal.ViewReference.createPart(ViewReferen ce.java:229)
at org.eclipse.ui.internal.WorkbenchPartReference.getPart(Workb enchPartReference.java:595)
at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:31 3)
at org.eclipse.ui.internal.ViewPane.setVisible(ViewPane.java:52 9)
at org.eclipse.ui.internal.presentations.PresentablePart.setVis ible(PresentablePart.java:180)
at org.eclipse.ui.internal.presentations.util.PresentablePartFo lder.select(PresentablePartFolder.java:270)
at org.eclipse.ui.internal.presentations.util.LeftToRightTabOrd er.select(LeftToRightTabOrder.java:65)
at org.eclipse.ui.internal.presentations.util.TabbedStackPresen tation.selectPart(TabbedStackPresentation.java:473)
at org.eclipse.ui.internal.PartStack.refreshPresentationSelecti on(PartStack.java:1254)
at org.eclipse.ui.internal.PartStack.createControl(PartStack.ja va:666)
at org.eclipse.ui.internal.PartStack.createControl(PartStack.ja va:574)
at org.eclipse.ui.internal.PartSashContainer.createControl(Part SashContainer.java:568)
at org.eclipse.ui.internal.PerspectiveHelper.activate(Perspecti veHelper.java:272)
at org.eclipse.ui.internal.Perspective.onActivate(Perspective.j ava:981)
at org.eclipse.ui.internal.WorkbenchPage.onActivate(WorkbenchPa ge.java:2632)
at org.eclipse.ui.internal.WorkbenchWindow$27.run(WorkbenchWind ow.java:2986)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator .java:70)
at org.eclipse.ui.internal.WorkbenchWindow.setActivePage(Workbe nchWindow.java:2967)
at org.eclipse.ui.internal.WorkbenchWindow$21.runWithException( WorkbenchWindow.java:2284)
at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run (StartupThreading.java:31)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:3 5)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchr onizer.java:134)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.jav a:4041)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3660)
at org.eclipse.ui.application.WorkbenchAdvisor.openWindows(Work benchAdvisor.java:803)
at org.eclipse.ui.internal.Workbench$31.runWithException(Workbe nch.java:1567)
at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run (StartupThreading.java:31)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:3 5)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchr onizer.java:134)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.jav a:4041)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3660)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2548)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:24 38)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
at org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:664)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start (IDEApplication.java:115)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 619)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
at org.eclipse.equinox.launcher.Main.main(Main.java:1383)





And this is the code (the problem is in the 'initialize' method when I try to cast the eObject "IFConfig config = (IFConfig) eObject;"):

class ViewContentProvider implements IStructuredContentProvider,
			ITreeContentProvider {
		private TreeParent invisibleRoot;
		private IFConfigurationXMLInjectorImpl ifConfigXMLInjector;

		public void inputChanged(Viewer v, Object oldInput, Object newInput) {
		}

		public void dispose() {
		}

		public Object[] getElements(Object parent) {
			if (parent.equals(getViewSite())) {
				if (invisibleRoot == null)
					initialize();
				return getChildren(invisibleRoot);
			}
			return getChildren(parent);
		}

		public Object getParent(Object child) {
			if (child instanceof TreeObject) {
				return ((TreeObject) child).getParent();
			}
			return null;
		}

		public Object[] getChildren(Object parent) {
			if (parent instanceof TreeParent) {
				return ((TreeParent) parent).getChildren();
			}
			return new Object[0];
		}

		public boolean hasChildren(Object parent) {
			if (parent instanceof TreeParent)
				return ((TreeParent) parent).hasChildren();
			return false;
		}

		private void initialize() {
			// TODO: get the tree parent from emf model element of type
			// IFInstance
			ResourceSet resourceSet = new ResourceSetImpl();
			// Register the appropriate resource factory to handle all file
			// extensions.
			//
			resourceSet
					.getResourceFactoryRegistry()
					.getExtensionToFactoryMap()
					.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
							new XMIResourceFactoryImpl());
			// Register the package to ensure it is available during loading.
			//
			Registry packageRegistry = resourceSet.getPackageRegistry();
			packageRegistry.put(IFConfigPackage.eNS_URI,
					IFConfigPackage.eINSTANCE);

			URI uri = URI
					.createFileURI("d:/workspaces/wp_irit_ifgui/fr.irit.ifclipse/src/fr/irit/ifclipse/xml/savedIFConfig2.ifconfig.xmi");
			Resource resource = resourceSet.createResource(uri);

			if (resource != null) {

				URI sourceXML = URI
						.createFileURI("d:/workspaces/wp_irit_ifgui/fr.irit.ifclipse/src/fr/irit/ifclipse/xml/step_1.xml");
				try {
					InputStream inputStrSourceXML = (new ExtensibleURIConverterImpl())
							.createInputStream(sourceXML);

					ifConfigXMLInjector = new IFConfigurationXMLInjectorImpl();

					resource = ifConfigXMLInjector.inject(inputStrSourceXML);
					
					resource.setURI(uri);
					resource.save(Collections.EMPTY_MAP);
					
				} catch (IOException e) {
					System.out.println("injection problem !");
					e.printStackTrace();
				}
	

				// 
				EList<EObject> contents = resource.getContents();
				EObject eObject = contents.get(0);
				if (eObject instanceof IFConfig)
					System.out.println("it's an IFConfig");

				IFConfig config = (IFConfig) eObject;

				TreeParent root = new TreeParent("Configuration: "
						+ config.getName());
				TreeParent p1 = new TreeParent("instances");
				root.addChild(p1);

				for (Instance instance : config.getInstances()) {
					p1.addChild(new TreeObject(instance.getPid().getName()));
				}

				invisibleRoot = new TreeParent("");
				invisibleRoot.addChild(root);

			}

		}
	}


I think that the pacckage is not registred, but when I look to my metamodel plugin, the plugin.xml is the following:

<plugin>

   <extension point="org.eclipse.emf.ecore.generated_package">
      <package
            uri="http://irit.fr/ifconfiguration"
            class="fr.irit.ifclipse.metamodel.IFConfig.IFConfigPackage"
            genModel="src/fr/irit/ifclipse/metamodel/metamodel/IFConfiguration.genmodel"/>
   </extension>

</plugin>


And my view plugin has a dependency on this metamodel plugin, so I don't see the problem.
Any clue ?



Re: ClassCastException on.DynamicEObjectImpl [message #655588 is a reply to message #655572] Mon, 21 February 2011 15:00 Go to previous messageGo to next message
Eike Stepper is currently offline Eike Stepper
Messages: 5446
Registered: July 2009
Senior Member
Am 21.02.2011 20:24, schrieb ElArbi:
> Hello,
>
> I have the follwing error when trying to cast an EObject to one of my generated EMF model element.

The model used is definitely not a generated model. Please check that your model plugins are properly deployed. Also check that the nsURIs in the plugin.xml files are complete and match the eNS_URI constants in the correcponding generated package interfaces (EMF does not regenerate/merge the plugin.xml after model changes).

Cheers
/Eike

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



> This is the complete error trace:
>
> Quote:
>> !SESSION 2011-02-21 20:14:21.108 -----------------------------------------------
>> eclipse.buildId=M20100909-0800
>> java.version=1.6.0_23
>> java.vendor=Sun Microsystems Inc.
>> BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=fr_FR
>> Framework arguments: -product org.eclipse.platform.ide
>> Command-line arguments: -product org.eclipse.platform.ide -data D:\workspaces\wp_irit_ifgui/../runtime-EclipseApplication -dev file:D:/workspaces/wp_irit_ifgui/.metadata/.plugins/org.ecli pse.pde.core/Eclipse Application/dev.properties -os win32 -ws win32 -arch x86_64 -consoleLog
>>
>> !ENTRY org.eclipse.emf.ecore 2 0 2011-02-21 20:14:26.753
>> !MESSAGE Both 'org.eclipse.gmf.bridge.trace' and 'org.eclipse.xpand.incremental' register an extension parser for 'trace'
>> sEltVar: IN!var
>> instance_var: IN!server_var
>>
>> !ENTRY org.eclipse.ui.workbench 4 0 2011-02-21 20:14:27.445
>> !MESSAGE Unable to create view ID fr.irit.ifclipse.views.IFConfigurationView: org.eclipse.emf.ecore.impl.DynamicEObjectImpl cannot be cast to fr.irit.ifclipse.metamodel.IFConfig.IFConfig
>> !STACK 0
>> java.lang.ClassCastException: org.eclipse.emf.ecore.impl.DynamicEObjectImpl cannot be cast to fr.irit.ifclipse.metamodel.IFConfig.IFConfig
>> at fr.irit.ifclipse.views.IFConfigurationView$ViewContentProvid er.initialize(IFConfigurationView.java:233)
>> at fr.irit.ifclipse.views.IFConfigurationView$ViewContentProvid er.getElements(IFConfigurationView.java:158)
>> at org.eclipse.jface.viewers.StructuredViewer.getRawChildren(St ructuredViewer.java:989)
>> at org.eclipse.jface.viewers.ColumnViewer.getRawChildren(Column Viewer.java:703)
>> at org.eclipse.jface.viewers.AbstractTreeViewer.getRawChildren( AbstractTreeViewer.java:1332)
>> at org.eclipse.jface.viewers.TreeViewer.getRawChildren(TreeView er.java:391)
>> at org.eclipse.jface.viewers.StructuredViewer.getFilteredChildr en(StructuredViewer.java:896)
>> at org.eclipse.jface.viewers.AbstractTreeViewer.getSortedChildr en(AbstractTreeViewer.java:601)
>> at org.eclipse.jface.viewers.AbstractTreeViewer$1.run(AbstractT reeViewer.java:801)
>> at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator .java:70)
>> at org.eclipse.jface.viewers.AbstractTreeViewer.createChildren( AbstractTreeViewer.java:778)
>> at org.eclipse.jface.viewers.TreeViewer.createChildren(TreeView er.java:644)
>> at org.eclipse.jface.viewers.AbstractTreeViewer.createChildren( AbstractTreeViewer.java:749)
>> at org.eclipse.jface.viewers.AbstractTreeViewer.internalInitial izeTree(AbstractTreeViewer.java:1492)
>> at org.eclipse.jface.viewers.TreeViewer.internalInitializeTree( TreeViewer.java:833)
>> at org.eclipse.jface.viewers.AbstractTreeViewer$5.run(AbstractT reeViewer.java:1476)
>> at org.eclipse.jface.viewers.StructuredViewer.preservingSelecti on(StructuredViewer.java:1422)
>> at org.eclipse.jface.viewers.TreeViewer.preservingSelection(Tre eViewer.java:403)
>> at org.eclipse.jface.viewers.StructuredViewer.preservingSelecti on(StructuredViewer.java:1383)
>> at org.eclipse.jface.viewers.AbstractTreeViewer.inputChanged(Ab stractTreeViewer.java:1469)
>> at org.eclipse.jface.viewers.ContentViewer.setInput(ContentView er.java:274)
>> at org.eclipse.jface.viewers.StructuredViewer.setInput(Structur edViewer.java:1664)
>> at fr.irit.ifclipse.views.IFConfigurationView.createPartControl (IFConfigurationView.java:303)
>> at org.eclipse.ui.internal.ViewReference.createPartHelper(ViewR eference.java:375)
>> at org.eclipse.ui.internal.ViewReference.createPart(ViewReferen ce.java:229)
>> at org.eclipse.ui.internal.WorkbenchPartReference.getPart(Workb enchPartReference.java:595)
>> at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:31 3)
>> at org.eclipse.ui.internal.ViewPane.setVisible(ViewPane.java:52 9)
>> at org.eclipse.ui.internal.presentations.PresentablePart.setVis ible(PresentablePart.java:180)
>> at org.eclipse.ui.internal.presentations.util.PresentablePartFo lder.select(PresentablePartFolder.java:270)
>> at org.eclipse.ui.internal.presentations.util.LeftToRightTabOrd er.select(LeftToRightTabOrder.java:65)
>> at org.eclipse.ui.internal.presentations.util.TabbedStackPresen tation.selectPart(TabbedStackPresentation.java:473)
>> at org.eclipse.ui.internal.PartStack.refreshPresentationSelecti on(PartStack.java:1254)
>> at org.eclipse.ui.internal.PartStack.createControl(PartStack.ja va:666)
>> at org.eclipse.ui.internal.PartStack.createControl(PartStack.ja va:574)
>> at org.eclipse.ui.internal.PartSashContainer.createControl(Part SashContainer.java:568)
>> at org.eclipse.ui.internal.PerspectiveHelper.activate(Perspecti veHelper.java:272)
>> at org.eclipse.ui.internal.Perspective.onActivate(Perspective.j ava:981)
>> at org.eclipse.ui.internal.WorkbenchPage.onActivate(WorkbenchPa ge.java:2632)
>> at org.eclipse.ui.internal.WorkbenchWindow$27.run(WorkbenchWind ow.java:2986)
>> at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator .java:70)
>> at org.eclipse.ui.internal.WorkbenchWindow.setActivePage(Workbe nchWindow.java:2967)
>> at org.eclipse.ui.internal.WorkbenchWindow$21.runWithException( WorkbenchWindow.java:2284)
>> at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run (StartupThreading.java:31)
>> at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:3 5)
>> at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchr onizer.java:134)
>> at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.jav a:4041)
>> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3660)
>> at org.eclipse.ui.application.WorkbenchAdvisor.openWindows(Work benchAdvisor.java:803)
>> at org.eclipse.ui.internal.Workbench$31.runWithException(Workbe nch.java:1567)
>> at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run (StartupThreading.java:31)
>> at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:3 5)
>> at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchr onizer.java:134)
>> at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.jav a:4041)
>> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3660)
>> at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2548)
>> at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:24 38)
>> at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
>> at org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:332)
>> at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:664)
>> at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
>> at org.eclipse.ui.internal.ide.application.IDEApplication.start (IDEApplication.java:115)
>> at org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:196)
>> at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
>> at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
>> at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:369)
>> at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
>> at java.lang.reflect.Method.invoke(Method.java:597)
>> at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 619)
>> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
>> at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
>> at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
>
>
> And this is the code (the problem is in the 'initialize' method when I try to cast the eObject "IFConfig config = (IFConfig) eObject;"):
>
> class ViewContentProvider implements IStructuredContentProvider,
> ITreeContentProvider {
> private TreeParent invisibleRoot;
> private IFConfigurationXMLInjectorImpl ifConfigXMLInjector;
>
> public void inputChanged(Viewer v, Object oldInput, Object newInput) {
> }
>
> public void dispose() {
> }
>
> public Object[] getElements(Object parent) {
> if (parent.equals(getViewSite())) {
> if (invisibleRoot == null)
> initialize();
> return getChildren(invisibleRoot);
> }
> return getChildren(parent);
> }
>
> public Object getParent(Object child) {
> if (child instanceof TreeObject) {
> return ((TreeObject) child).getParent();
> }
> return null;
> }
>
> public Object[] getChildren(Object parent) {
> if (parent instanceof TreeParent) {
> return ((TreeParent) parent).getChildren();
> }
> return new Object[0];
> }
>
> public boolean hasChildren(Object parent) {
> if (parent instanceof TreeParent)
> return ((TreeParent) parent).hasChildren();
> return false;
> }
>
> private void initialize() {
> // TODO: get the tree parent from emf model element of type
> // IFInstance
> ResourceSet resourceSet = new ResourceSetImpl();
> // Register the appropriate resource factory to handle all file
> // extensions.
> //
> resourceSet
> .getResourceFactoryRegistry()
> .getExtensionToFactoryMap()
> .put(Resource.Factory.Registry.DEFAULT_EXTENSION,
> new XMIResourceFactoryImpl());
> // Register the package to ensure it is available during loading.
> //
> Registry packageRegistry = resourceSet.getPackageRegistry();
> packageRegistry.put(IFConfigPackage.eNS_URI,
> IFConfigPackage.eINSTANCE);
>
> URI uri = URI
> .createFileURI(" d:/workspaces/wp_irit_ifgui/fr.irit.ifclipse/src/fr/irit/ifc lipse/xml/savedIFConfig2.ifconfig.xmi ");
> Resource resource = resourceSet.createResource(uri);
>
> if (resource != null) {
>
> URI sourceXML = URI
> .createFileURI(" d:/workspaces/wp_irit_ifgui/fr.irit.ifclipse/src/fr/irit/ifc lipse/xml/step_1.xml ");
> try {
> InputStream inputStrSourceXML = (new ExtensibleURIConverterImpl())
> .createInputStream(sourceXML);
>
> ifConfigXMLInjector = new IFConfigurationXMLInjectorImpl();
>
> resource = ifConfigXMLInjector.inject(inputStrSourceXML);
>
> resource.setURI(uri);
> resource.save(Collections.EMPTY_MAP);
>
> } catch (IOException e) {
> System.out.println("injection problem !");
> e.printStackTrace();
> }
>
>
> // EList<EObject> contents = resource.getContents();
> EObject eObject = contents.get(0);
> if (eObject instanceof IFConfig)
> System.out.println("it's an IFConfig");
>
> IFConfig config = (IFConfig) eObject;
>
> TreeParent root = new TreeParent("Configuration: "
> + config.getName());
> TreeParent p1 = new TreeParent("instances");
> root.addChild(p1);
>
> for (Instance instance : config.getInstances()) {
> p1.addChild(new TreeObject(instance.getPid().getName()));
> }
>
> invisibleRoot = new TreeParent("");
> invisibleRoot.addChild(root);
>
> }
>
> }
> }
>
> I think that the pacckage is not registred, but when I look to my metamodel plugin, the plugin.xml is the following:
>
> <plugin>
>
> <extension point="org.eclipse.emf.ecore.generated_package">
> <package
> uri="http://irit.fr/ifconfiguration"
> class="fr.irit.ifclipse.metamodel.IFConfig.IFConfigPackage"
> genModel=" src/fr/irit/ifclipse/metamodel/metamodel/IFConfiguration.gen model "/>
> </extension>
>
> </plugin>
>
> And my view plugin has a dependency on this metamodel plugin, so I don't see the problem.
> Any clue ?
>
>
>
>
Re: ClassCastException on.DynamicEObjectImpl [message #655651 is a reply to message #655588] Tue, 22 February 2011 02:10 Go to previous messageGo to next message
El Arbi Aboussoror is currently offline El Arbi Aboussoror
Messages: 88
Registered: June 2010
Member
Quote:
The model used is definitely not a generated model


How do you see this ? from the "org.eclipse.emf.ecore.impl.DynamicEObjectImp" ?

The model plugins are deployed to the runtime eclipse instance and the nsURIs in the plugin.xml files are complete and match the eNS_URI constants:

<plugin>

   <extension point="org.eclipse.emf.ecore.generated_package">
      <package
            uri="http://irit.fr/ifconfiguration"
            class="fr.irit.ifclipse.metamodel.IFConfig.IFConfigPackage"
            genModel="src/fr/irit/ifclipse/metamodel/metamodel/IFConfiguration.genmodel"/>
   </extension>

</plugin>


	String eNS_URI = "http://irit.fr/ifconfiguration";
Re: ClassCastException on.DynamicEObjectImpl [message #655654 is a reply to message #655651] Tue, 22 February 2011 02:42 Go to previous messageGo to next message
Eike Stepper is currently offline Eike Stepper
Messages: 5446
Registered: July 2009
Senior Member
Am 22.02.2011 08:10, schrieb ElArbi:
> Quote:
>> The model used is definitely not a generated model
>
>
> How do you see this ? from the "org.eclipse.emf.ecore.impl.DynamicEObjectImp" ?

Yes.

> The model plugins are deployed to the runtime eclipse instance

Please check that they're properly started by OSGi. One way is to type "ss" into the OSGi console.

> and the nsURIs in the plugin.xml files are complete and match the eNS_URI constants:
>
> <plugin>
>
> <extension point="org.eclipse.emf.ecore.generated_package">
> <package
> uri="http://irit.fr/ifconfiguration"
> class="fr.irit.ifclipse.metamodel.IFConfig.IFConfigPackage"
> genModel=" src/fr/irit/ifclipse/metamodel/metamodel/IFConfiguration.gen model "/>

That looks a bit strange. I use to store the ecore and the genmodel file in the model/ folder. Not sure if that's related.

Cheers
/Eike

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


> </extension>
>
> </plugin>
>
> String eNS_URI = "http://irit.fr/ifconfiguration";
Re: ClassCastException on.DynamicEObjectImpl [message #655759 is a reply to message #655654] Tue, 22 February 2011 10:05 Go to previous messageGo to next message
El Arbi Aboussoror is currently offline El Arbi Aboussoror
Messages: 88
Registered: June 2010
Member
The 2 plugins are properly started:

Quote:
osgi> ss fr

Framework is launched.

id State Bundle
9 ACTIVE fr.irit.ifclipse_1.0.0.20100125
10 ACTIVE fr.irit.ifclipse.metamodel_1.0.0
11 <<LAZY>> fr.irit.ifclipse.metamodel.edit_1.0.0
12 <<LAZY>> fr.irit.ifclipse.metamodel.editor_1.0.0
13 <<LAZY>> fr.irit.ifclipse.metamodel.tests_1.0.0
236 ACTIVE org.eclipse.equinox.frameworkadmin_2.0.0.v20100503
237 <<LAZY>> org.eclipse.equinox.frameworkadmin.equinox_1.0.200.v20100505
578 <<LAZY>> org.eclipse.wst.common.frameworks_1.2.0.v201003040800



The fr.irit.ifclipse.metamodel_1.0.0 contains my EMF model.
And I launch the fr.irit.ifclipse_1.0.0.20100125 that has a dependency on the first EMF model plugin.
Re: ClassCastException on.DynamicEObjectImpl [message #655772 is a reply to message #655759] Tue, 22 February 2011 10:35 Go to previous messageGo to next message
Eike Stepper is currently offline Eike Stepper
Messages: 5446
Registered: July 2009
Senior Member
Am 22.02.2011 16:05, schrieb ElArbi:
> The 2 plugins are properly started:
>
> Quote:
>> osgi> ss fr
>>
>> Framework is launched.
>>
>> id State Bundle
>> 9 ACTIVE fr.irit.ifclipse_1.0.0.20100125
>> 10 ACTIVE fr.irit.ifclipse.metamodel_1.0.0
>> 11 <<LAZY>> fr.irit.ifclipse.metamodel.edit_1.0.0
>> 12 <<LAZY>> fr.irit.ifclipse.metamodel.editor_1.0.0
>> 13 <<LAZY>> fr.irit.ifclipse.metamodel.tests_1.0.0
>> 236 ACTIVE org.eclipse.equinox.frameworkadmin_2.0.0.v20100503
>> 237 <<LAZY>> org.eclipse.equinox.frameworkadmin.equinox_1.0.200.v20100505
>> 578 <<LAZY>> org.eclipse.wst.common.frameworks_1.2.0.v201003040800
>
>
> The fr.irit.ifclipse.metamodel_1.0.0 contains my EMF model.
> And I launch the fr.irit.ifclipse_1.0.0.20100125 that has a dependency on the first EMF model plugin.

I seem to run out of ideas ;-(

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
Re: ClassCastException on.DynamicEObjectImpl [message #655880 is a reply to message #655759] Tue, 22 February 2011 19:51 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25744
Registered: July 2009
Senior Member
Set a breakpoint in the constructor for EDynamicObjectImpl and use that
to determine why your generated model isn't being used there instead.
I.e., someone must be registering a dynamic model that's being used
instead of your static one, but only you're in a position to determine
why that's the case.


ElArbi wrote:
> The 2 plugins are properly started:
>
> Quote:
>> osgi> ss fr
>>
>> Framework is launched.
>>
>> id State Bundle
>> 9 ACTIVE fr.irit.ifclipse_1.0.0.20100125
>> 10 ACTIVE fr.irit.ifclipse.metamodel_1.0.0
>> 11 <<LAZY>> fr.irit.ifclipse.metamodel.edit_1.0.0
>> 12 <<LAZY>> fr.irit.ifclipse.metamodel.editor_1.0.0
>> 13 <<LAZY>> fr.irit.ifclipse.metamodel.tests_1.0.0
>> 236 ACTIVE org.eclipse.equinox.frameworkadmin_2.0.0.v20100503
>> 237 <<LAZY>>
>> org.eclipse.equinox.frameworkadmin.equinox_1.0.200.v20100505
>> 578 <<LAZY>> org.eclipse.wst.common.frameworks_1.2.0.v201003040800
>
>
> The fr.irit.ifclipse.metamodel_1.0.0 contains my EMF model.
> And I launch the fr.irit.ifclipse_1.0.0.20100125 that has a dependency
> on the first EMF model plugin.
>
Re: ClassCastException on.DynamicEObjectImpl [message #656237 is a reply to message #655880] Thu, 24 February 2011 11:24 Go to previous message
El Arbi Aboussoror is currently offline El Arbi Aboussoror
Messages: 88
Registered: June 2010
Member
Thanks!
I found my error:

I was loading the package from it's serialized form => it's factory will instantiate the dynamic EObject implementation (see EMF book section 15.3.2 Deserialization).

code details on:
http://www.eclipse.org/forums/index.php?t=msg&goto=65623 6&S=a7d205e34641ab0ad9d9c9d2f8c1cac2#msg_656236
Previous Topic:Altering XMLResource to create inter-EObject links bottom-up
Next Topic:Turn of generatation of PDE artifacts?
Goto Forum:
  


Current Time: Fri Apr 18 10:19:40 EDT 2014

Powered by FUDForum. Page generated in 0.08236 seconds