EMF resource load - SAXParser reading map twice

71 Views Asked by At

I'm having problems with persistence in EMF. The problem occurs when I add an element to a file that contains a map of elements. The process is:

Load file
Add element
Save file

The first time I add an element, it works fine. But if I try to add another, it reads the list in twice before adding the new element. All subsequent uses also read the list twice.

EXAMPLE

I start with a file that looks like this:

<?xml version="1.0" encoding="ASCII"?>
<org.eclipse.mbt.core:CoreServicesResources xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:org.eclipse.mbt.core="http://org/eclipse/mbt/core">
  <primaryResources>
    <elementsMap key="1">
      <value URI="1">
        <traceabilityProperties traceable="true" derived="true" topLevel="true" />
        <keywords tags="foo" />
      </value>
    </elementsMap>
  </primaryResources>
</org.eclipse.mbt.core:CoreServicesResources>

If I add a new element, I end up with a file that looks like this, which is correct:

<?xml version="1.0" encoding="ASCII"?>
<org.eclipse.mbt.core:CoreServicesResources xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:org.eclipse.mbt.core="http://org/eclipse/mbt/core">
  <primaryResources>
    <elementsMap key="1">
      <value URI="1">
        <traceabilityProperties traceable="true" derived="true" topLevel="true"/>
        <keywords tags="foo"/>
      </value>
    </elementsMap>
    <elementsMap key="2">
      <value URI="2">
        <traceabilityProperties traceable="true" derived="true" topLevel="true"/>
        <keywords tags="bar"/>
      </value>
    </elementsMap>
  </primaryResources>
</org.eclipse.mbt.core:CoreServicesResources>

However, if I then add another element, I get this, which is incorrect:

<?xml version="1.0" encoding="ASCII"?>
<org.eclipse.mbt.core:CoreServicesResources xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:org.eclipse.mbt.core="http://org/eclipse/mbt/core">
  <primaryResources>
    <elementsMap key="1">
      <value URI="1">
        <traceabilityProperties traceable="true" derived="true" topLevel="true"/>
        <keywords tags="foo"/>
      </value>
    </elementsMap>
    <elementsMap key="2">
      <value URI="2">
        <traceabilityProperties traceable="true" derived="true" topLevel="true"/>
        <keywords tags="bar"/>
      </value>
    </elementsMap>
    <elementsMap key="1">
      <value URI="1">
        <traceabilityProperties traceable="true" derived="true" topLevel="true"/>
        <keywords tags="bar"/>
      </value>
    </elementsMap>
    <elementsMap key="2">
      <value URI="2">
        <traceabilityProperties traceable="true" derived="true" topLevel="true"/>
        <keywords tags="foo"/>
      </value>
    </elementsMap>
    <elementsMap key="3">
      <value URI="3">
        <traceabilityProperties traceable="true" derived="true" topLevel="true"/>
        <keywords tags="bar"/>
      </value>
    </elementsMap>
  </primaryResources>
</org.eclipse.mbt.core:CoreServicesResources>

When I debug the code, the problem seems to be happening somewhere in the parser. I'm using the Java SE-11 System library, and the parser is com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl

Has anyone else had problems like this?

0

There are 0 best solutions below