[CDO] ArrayStoreException on XML imported resource [message #1518454] |
Fri, 19 December 2014 23:05  |
Eclipse User |
|
|
|
Hi,
I'm working with an XSD based ecore model (XSD2Ecore) and managed to build a E4/CDO application around it. The model appears to work fine but when I try to import and load resources from XML I'm running into strange behavior.
The XML is imported to CDO like this
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new MyModelResourceFactoryImpl());
URI uri = URI.createFileURI(fileName);
Resource resource = resourceSet.getResource(uri, true);
if (resource.getContents().get(0) instanceof DocumentRoot) {
transaction = cdoSession.openTransaction();
transaction.getOrCreateResource("/home/Administrator/someResource").getContents().add(resource.getContents().get(0));
transaction.commit();
}
Then I load the resource and work with its content, e.g. creating a copy:
view = cdoSession.openView();
CDOResource resource = view.getResource("/home/Administrator/someResource");
try {
resource.load(null);
} catch (IOException e) {
e.printStackTrace();
}
resource.getResourceSet().getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new MyModelResourceFactoryImpl());
EcoreUtil.copy(resource.getContents().get(0));
This works fine on the first run, directly after importing the XML. However when I restart my application (including the embedded cdo server) and load the resource using the same code, I get an ArrayStoreException from the call to EcoreUtil.copy(). Ok, some model elements can still be copied, others cannot. That's what confuses me even more.
In the CDO Sessions View I can browse the resource without any problems, so it seems to be intact. Also, there is no problem when I import similar resources from standard XMI.
Any idea what could be causing this issue with the XML imported resources? And why only after restart?
Thanks.
[ERROR] org.eclipse.emf.cdo.internal.common.revision.CDOFeatureMapEntryImpl
java.lang.ArrayStoreException: org.eclipse.emf.cdo.internal.common.revision.CDOFeatureMapEntryImpl
at org.eclipse.emf.common.util.BasicEList.assign(BasicEList.java:118)
at org.eclipse.emf.common.util.BasicEList.addUnique(BasicEList.java:442)
at org.eclipse.emf.common.notify.impl.NotifyingListImpl.doAddUnique(NotifyingListImpl.java:387)
at org.eclipse.emf.common.notify.impl.NotifyingListImpl.basicAdd(NotifyingListImpl.java:678)
at org.eclipse.emf.internal.cdo.object.CDOLegacyWrapper.revisionToInstanceFeature(CDOLegacyWrapper.java:622)
at org.eclipse.emf.internal.cdo.object.CDOLegacyWrapper.revisionToInstance(CDOLegacyWrapper.java:492)
at org.eclipse.emf.internal.cdo.object.CDOLegacyWrapper.cdoInternalPostLoad(CDOLegacyWrapper.java:367)
at org.eclipse.emf.internal.cdo.view.AbstractCDOView.cleanObject(AbstractCDOView.java:1254)
at org.eclipse.emf.internal.cdo.view.AbstractCDOView.createObject(AbstractCDOView.java:1170)
at org.eclipse.emf.internal.cdo.view.AbstractCDOView.getObject(AbstractCDOView.java:1055)
at org.eclipse.emf.internal.cdo.view.AbstractCDOView.convertIDToObject(AbstractCDOView.java:1395)
at org.eclipse.emf.internal.cdo.view.CDOStoreImpl.convertIDToObject(CDOStoreImpl.java:679)
at org.eclipse.emf.internal.cdo.view.CDOStoreImpl.convertToEMF(CDOStoreImpl.java:647)
at org.eclipse.emf.internal.cdo.view.CDOStoreImpl.isSet(CDOStoreImpl.java:210)
at org.eclipse.emf.internal.cdo.CDOObjectImpl.eDynamicIsSet(CDOObjectImpl.java:722)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eIsSet(BasicEObjectImpl.java:1253)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eIsSet(BasicEObjectImpl.java:1237)
at org.eclipse.emf.ecore.util.EcoreUtil$Copier.copyContainment(EcoreUtil.java:585)
at org.eclipse.emf.ecore.util.EcoreUtil$Copier.copy(EcoreUtil.java:490)
at org.eclipse.emf.ecore.util.EcoreUtil$Copier.copyContainment(EcoreUtil.java:599)
at org.eclipse.emf.ecore.util.EcoreUtil$Copier.copy(EcoreUtil.java:490)
at org.eclipse.emf.ecore.util.EcoreUtil$Copier.copyAll(EcoreUtil.java:449)
at org.eclipse.emf.ecore.util.EcoreUtil$Copier.copyContainment(EcoreUtil.java:595)
at org.eclipse.emf.ecore.util.EcoreUtil$Copier.copy(EcoreUtil.java:490)
at org.eclipse.emf.ecore.util.EcoreUtil.copy(EcoreUtil.java:357)
[Updated on: Fri, 19 December 2014 23:06] by Moderator
|
|
|
Re: [CDO] ArrayStoreException on XML imported resource [message #1518578 is a reply to message #1518454] |
Sat, 20 December 2014 00:44   |
Eclipse User |
|
|
|
Hi Thorsten,
You should not call resource.load() on a resource provided by a CDOView. Does that already fix your problem?
Oh, and I see that you're using FeatureMaps. That's not very well supported by CDO. I mean I'm sure that there are many
places in CDO where they're not properly considered.
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
Am 20.12.2014 um 05:05 schrieb Thorsten Beck:
> Hi,
> I'm working with an XSD based ecore model (XSD2Ecore) and managed to build a E4/CDO application around it. The model
> appears to work fine but when I try to import and load resources from XML I'm running into strange behavior.
>
> The XML is imported to CDO like this
>
> ResourceSet resourceSet = new ResourceSetImpl();
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION,
> new MyModelResourceFactoryImpl());
> URI uri = URI.createFileURI(fileName);
> Resource resource = resourceSet.getResource(uri, true);
> if (resource.getContents().get(0) instanceof DocumentRoot) {
> transaction = cdoSession.openTransaction();
> transaction.getOrCreateResource("/home/Administrator/someResource").getContents().add(resource.getContents().get(0));
> transaction.commit();
> }
>
> Then I load the resource and work with its content, e.g. creating a copy:
>
> view = cdoSession.openView();
> CDOResource resource = view.getResource("/home/Administrator/someResource");
> try {
> resource.load(null);
> } catch (IOException e) {
> e.printStackTrace();
> }
> resource.getResourceSet().getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION,
> new MyModelResourceFactoryImpl());
> EcoreUtil.copy(resource.getContents().get(0));
>
> This works fine on the first run, directly after importing the XML. However when I restart my application (including
> the embedded cdo server) and load the resource using the same code, I get an ArrayStoreException from the call to
> EcoreUtil.copy(). Ok, some model elements can still be copied, others cannot. That's what confuses me even more.
>
> In the CDO Sessions View I can browse the resource without any problems, so it seems to be intact. Also, there is no
> problem when I import similar resources from standard XMI.
>
> Any idea what could be causing this issue with the XML imported resources? And why only after restart?
> Thanks.
>
>
> [ERROR] org.eclipse.emf.cdo.internal.common.revision.CDOFeatureMapEntryImpl
> java.lang.ArrayStoreException: org.eclipse.emf.cdo.internal.common.revision.CDOFeatureMapEntryImpl
> at org.eclipse.emf.common.util.BasicEList.assign(BasicEList.java:118)
> at org.eclipse.emf.common.util.BasicEList.addUnique(BasicEList.java:442)
> at org.eclipse.emf.common.notify.impl.NotifyingListImpl.doAddUnique(NotifyingListImpl.java:387)
> at org.eclipse.emf.common.notify.impl.NotifyingListImpl.basicAdd(NotifyingListImpl.java:678)
> at org.eclipse.emf.internal.cdo.object.CDOLegacyWrapper.revisionToInstanceFeature(CDOLegacyWrapper.java:622)
> at org.eclipse.emf.internal.cdo.object.CDOLegacyWrapper.revisionToInstance(CDOLegacyWrapper.java:492)
> at org.eclipse.emf.internal.cdo.object.CDOLegacyWrapper.cdoInternalPostLoad(CDOLegacyWrapper.java:367)
> at org.eclipse.emf.internal.cdo.view.AbstractCDOView.cleanObject(AbstractCDOView.java:1254)
> at org.eclipse.emf.internal.cdo.view.AbstractCDOView.createObject(AbstractCDOView.java:1170)
> at org.eclipse.emf.internal.cdo.view.AbstractCDOView.getObject(AbstractCDOView.java:1055)
> at org.eclipse.emf.internal.cdo.view.AbstractCDOView.convertIDToObject(AbstractCDOView.java:1395)
> at org.eclipse.emf.internal.cdo.view.CDOStoreImpl.convertIDToObject(CDOStoreImpl.java:679)
> at org.eclipse.emf.internal.cdo.view.CDOStoreImpl.convertToEMF(CDOStoreImpl.java:647)
> at org.eclipse.emf.internal.cdo.view.CDOStoreImpl.isSet(CDOStoreImpl.java:210)
> at org.eclipse.emf.internal.cdo.CDOObjectImpl.eDynamicIsSet(CDOObjectImpl.java:722)
> at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eIsSet(BasicEObjectImpl.java:1253)
> at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eIsSet(BasicEObjectImpl.java:1237)
> at org.eclipse.emf.ecore.util.EcoreUtil$Copier.copyContainment(EcoreUtil.java:585)
> at org.eclipse.emf.ecore.util.EcoreUtil$Copier.copy(EcoreUtil.java:490)
> at org.eclipse.emf.ecore.util.EcoreUtil$Copier.copyContainment(EcoreUtil.java:599)
> at org.eclipse.emf.ecore.util.EcoreUtil$Copier.copy(EcoreUtil.java:490)
> at org.eclipse.emf.ecore.util.EcoreUtil$Copier.copyAll(EcoreUtil.java:449)
> at org.eclipse.emf.ecore.util.EcoreUtil$Copier.copyContainment(EcoreUtil.java:595)
> at org.eclipse.emf.ecore.util.EcoreUtil$Copier.copy(EcoreUtil.java:490)
> at org.eclipse.emf.ecore.util.EcoreUtil.copy(EcoreUtil.java:357)
>
|
|
|
Re: [CDO] ArrayStoreException on XML imported resource [message #1519791 is a reply to message #1518578] |
Sat, 20 December 2014 17:06  |
Eclipse User |
|
|
|
Hey Eike,
removing resource.load() unfortunately didn't help. But thanks for the hint, I'm still getting CDO and EMF API mixed up..
Your comment about FeatureMaps worries me, since the XML Schema I have to work with relies on feature maps (well, actually the derived ecore model does).
I thought this is a common use case? Are there any workarounds available with CDO?
Anyway, I'm not sure it's the cause of this problem. I took the time to completely dismantle the Schema and believe I found the problematic element. The simplified Schema now looks like this:
<?xml version="1.0"?>
<xs:schema xmlns:xs="w3orgNamespace" xmlns:proc="someNamespace" targetNamespace="someNamespace"
elementFormDefault="qualified" attributeFormDefault="unqualified" version="2.0" id="Schema">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="Product">
<xs:complexType>
<xs:sequence>
<xs:element name="databaseVersion">
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
I regenerated the model and found XMLs containing such elements still show the described behavior, with the same stacktrace. On the other hand, if I remove the Product element from my original XMLs, using the original Schema and code, everything works out fine.
And again, in the first application run the elements can be copied as expected. Also the CDO Session Viewer never has problems viewing the resource.
I really don't understand what's happening here..
|
|
|
Powered by
FUDForum. Page generated in 0.03623 seconds