Problem while loading entities of different type in a XMLResource [message #725665] |
Thu, 15 September 2011 13:47 |
Thomas Ricatte Messages: 3 Registered: September 2011 Location: Paris |
Junior Member |
|
|
Hi,
I a really new to EMF and I have to load some data contained in XML files. I was given the corresponding ecore schema in a xml format but I wasn't able to load it directly in a emf project (some prefix were null).
What I have done so far :
- Created a EMF project in eclipse. Creating a ecore schema for each "branch" of the packages (the original schema contained some packages attached to org.apache.xxx. some others to com.xxx. etc)
- Corrected the null prefix
- Created generators for each "branch" with reference to other generators (because of dependencies)
- Generated the code of the generators
- Try to execute the following code :
XMIResource resource = new XMIResourceImpl(
URI.createURI("file:" + pathOfFile));
resource.load(null);
for (EObject eo : resource.getContents()) {
System.out.println(eo.eClass().getInstanceClassName());
}
When I try this code with a xml file containing only one kind of entities (without external references of course), all works perfectly and I can load my objects.
When I try this code on a complete xml file (containing different kind of objects with references etc...), I get an org.eclipse.emf.ecore.xmi.IllegalValueException caused by a java.lang.ArrayStoreException when it comes to the first line in the file where the kind of entity changes.
Caused by: org.eclipse.emf.ecore.xmi.IllegalValueException: Value 'org.apache.uima.tika.impl.AttributeFSImpl@15b1773 (localName: xxx, qualifiedName: xxx, uri: , value: xxx)' is not legal. (file:xxx.xml, -1, -1)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.setFeatureValue(XMLHandler.java:2663)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleForwardReferences(XMLHandler.java:1149)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.endDocument(XMLHandler.java:1228)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endDocument(AbstractSAXParser.java:737)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:516)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:181)
... 20 more
Caused by: java.lang.ArrayStoreException
at org.eclipse.emf.common.util.BasicEList.assign(BasicEList.java:124)
at org.eclipse.emf.common.util.BasicEList.addUnique(BasicEList.java:448)
at org.eclipse.emf.common.notify.impl.NotifyingListImpl.doAddUnique(NotifyingListImpl.java:393)
at org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUnique(NotifyingListImpl.java:377)
at org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.setValue(XMLHelperImpl.java:1200)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.setFeatureValue(XMLHandler.java:2658)
... 31 more
Actually, the new entity mentioned at this line is also coming from an other package but I don't know if the error comes from the new kind of entity or of the difference of package. I was unable to test because of the huge number of references between entities (I was only able to find a small group of the same type without references to make the first test). The ArrayStore Excerption make me think that the loader can't store in the same array different kinds of entities but it seems a bit strange to me (I thought it was using arrays of EObject that are quite general to store all the entities loaded from the xml resource).
Do you have any idea to help me at this point ?
Thanks very much in advance.
[Updated on: Thu, 15 September 2011 14:01] Report message to a moderator
|
|
|
Re: Problem while loading entities of different type in a XMLResource [message #725687 is a reply to message #725665] |
Thu, 15 September 2011 14:01 |
Ed Merks Messages: 33217 Registered: July 2009 |
Senior Member |
|
|
Thomas,
Comments below.
On 15/09/2011 6:47 AM, Thomas Ricatte wrote:
> Hi,
>
> I a really new to EMF and I have to load some data contained in XML
> files. I was given the corresponding ecore schema in a xml format but
> I wasn't able to load it directly in a emf project (some prefix were
> null).
>
> What I have done so far :
>
> - Created a EMF project in eclipse. Creating a ecore schema for each
> "branch" of the packages (the original schema contained some packages
> attached to org.apache.xxx. some others to com.xxx. etc)
> - Corrected the null prefix
> - Created generators for each "branch" with reference to other
> generators (because of dependencies)
> - Generated the code of the generators
> - Try to execute the following code :
>
> XMIResource resource = new XMIResourceImpl(
> URI.createURI("file:" + pathOfFile));
> resource.load(null);
Normally you load using a resource set. If you use Generate Test Code
in the Generator you'll see an XyzExample.java in the *.tests project
that shows how you should be loading.
> for (EObject eo : resource.getContents()) {
> System.out.println(eo.eClass().getInstanceClassName());
> }
>
> When I try this code with a xml file containing only one kind of
> entities (without external references of course), all works perfectly
> and I can load my objects.
>
> When I try this code on a complete xml file (containing different kind
> of objects with references etc...), I get an
> org.eclipse.emf.ecore.xmi.IllegalValueException caused by a
> java.lang.ArrayStoreException when it comes to the first line in the
> file where the kind of entity changes.
>
>
>
> Caused by: org.eclipse.emf.ecore.xmi.IllegalValueException: Value
> 'org.apache.uima.tika.impl.AttributeFSImpl@15b1773 (localName: xxx,
> qualifiedName: xxx, uri: , value: xxx)' is not legal. (file:xxx.xml,
> -1, -1)
So it sounds like there is an ID-based reference to some other object in
the file, but that type of object is not allowed by the feature doing
the referencing. It's impossible to say more...
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.setFeatureValue(XMLHandler.java:2663)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleForwardReferences(XMLHandler.java:1149)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.endDocument(XMLHandler.java:1228)
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endDocument(AbstractSAXParser.java:737)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:516)
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
> at
> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
> at
> com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
> at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:181)
> ... 20 more
> Caused by: java.lang.ArrayStoreException
> at org.eclipse.emf.common.util.BasicEList.assign(BasicEList.java:124)
> at
> org.eclipse.emf.common.util.BasicEList.addUnique(BasicEList.java:448)
> at
> org.eclipse.emf.common.notify.impl.NotifyingListImpl.doAddUnique(NotifyingListImpl.java:393)
> at
> org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUnique(NotifyingListImpl.java:377)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.setValue(XMLHelperImpl.java:1200)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.setFeatureValue(XMLHandler.java:2658)
> ... 31 more
>
> Actually, the new entity mentioned at this line is also coming from an
> other package but I don't know if the error comes from the new kind of
> entity or of the difference of package.
It sounds like a same document reference.
> I was unable to test because of the huge number of references between
> entities (I was only able to find a small group of the same type
> without references to make the first test).
You've set a breakpoint to determine which particular reference is
causing the problem?
>
>
> Do you have any idea to help me at this point ?
The debugger will need to be consulted. You're going to have to figure
out which reference is causing the problem. It might well be the case
that the serialization is simply invalid and your not doing anything
wrong in the code. So, set an exception breakpoint on
ArrayStoreException; in the breakpoint view's toolbar you'll see a
button for doing that. No doubt an instance of AttributeFS is
involved. From the stack you'll be able to determine which ID value is
being resolved and which feature is being assigned.
>
> Thanks very much in advance.
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.04476 seconds