Load model by DOM Node [message #1745233] |
Thu, 06 October 2016 14:24  |
Eclipse User |
|
|
|
I have serialized an ecore model to an XML database. Now, I would like to deserialize the model. The database already returns the model root as a DOM Node/Element.
Now, I tried to convert the DOM Node back to a model instance:
XMIResource xr = new XMIResourceImpl();
xr.load(domNode, Collections.empty());
Unfortunately, I get this error message:
org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Class 'CommonObject' is not found or is abstract. (, -1, -1)
CommonObject is the generated interface, so, the message is right. But shouldn't the XMI resource automatically detect/use its factory?
Note: I have disabled EMF types in the genmodel, i.e. CommonObject does not extend EObject.
What do I miss here?
Thanks.
|
|
|
|
|
|
Re: Load model by DOM Node [message #1745352 is a reply to message #1745277] |
Fri, 07 October 2016 13:57  |
Eclipse User |
|
|
|
CommonObject is the generated interface of CommonObjectImpl.
The problem was that the DOM Element (returned by the XML backend/database) did not report the XML NS declarations as part of its attributes map, so the XMI resource could not resolve the EPackage.
Maybe, this option would have helped:
org.eclipse.emf.ecore.xmi.XMLResource.OPTION_DOM_USE_NAMESPACES_IN_SCOPE
But it seems it would have traversed the Element's parent hierarchy (which I want to avoid for performance reasons).
So, I ended up in overriding
org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getURI(String)
to manually map the prefix to its (known) package URI.
Thanks for your support, Ed!
Ed Merks wrote on Fri, 07 October 2016 10:20This definitely looks bogus. The root object would never have an xmi:type; it must name a concrete type that can be instantiated. There's nothing you could have ever serialized that would have produced this XMI, given that you say CommonObject is abstract.
|
|
|
Powered by
FUDForum. Page generated in 0.04870 seconds