Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Load model by DOM Node
Load model by DOM Node [message #1745233] Thu, 06 October 2016 18:24 Go to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 853
Registered: July 2009
Senior Member
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 #1745257 is a reply to message #1745233] Fri, 07 October 2016 04:45 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 31923
Registered: July 2009
Senior Member
I can't really guess what's wrong without knowing what the XML looks like. Perhaps a missing xmi:type in a place where it's needed, i.e., the proxies of an cross reference of type CommonObject will need an xsi/xmi:type. Note that not specifying a URI on the resource being loaded could lead to problems as well with cross references. Use at least something like dummy:/input.xmi.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Load model by DOM Node [message #1745260 is a reply to message #1745257] Fri, 07 October 2016 06:12 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 853
Registered: July 2009
Senior Member
Ed, this is how the XMI look like:

<common:CommonObject xmlns:common="http://example.com/common-v1.0" xmlns:xmi="http://www.omg.org/XMI" xmi:version="2.0" id="a8893768-c2ab-43ea-bdd9-a4278d2341ea"/>


You are right, the xmi:type attribute is missing, but I have no cross refs here.

Ed Merks wrote on Fri, 07 October 2016 06:45
I can't really guess what's wrong without knowing what the XML looks like. Perhaps a missing xmi:type in a place where it's needed, i.e., the proxies of an cross reference of type CommonObject will need an xsi/xmi:type. Note that not specifying a URI on the resource being loaded could lead to problems as well with cross references. Use at least something like dummy:/input.xmi.

Re: Load model by DOM Node [message #1745277 is a reply to message #1745260] Fri, 07 October 2016 08:20 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 31923
Registered: July 2009
Senior Member
This 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.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Load model by DOM Node [message #1745352 is a reply to message #1745277] Fri, 07 October 2016 17:57 Go to previous message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 853
Registered: July 2009
Senior Member
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:20
This 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.

Previous Topic:[CDO] CDOSession Concurreny Problems
Next Topic:[EMF] Lower bound 0 vs lower bound 1 of Reference
Goto Forum:
  


Current Time: Fri Jun 25 11:32:17 GMT 2021

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

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

Back to the top