EMF resource load - SAXParser loading map twice [message #1826275] |
Wed, 22 April 2020 14:52  |
Paul Hennessey Messages: 9 Registered: April 2020 |
Junior Member |
|
|
Question copied over from Stack Overflow:
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 duplicates the list before adding the new element. All subsequent uses also duplicate the list.
EXAMPLE
I start with a file that looks like this. (The XML is simplified - as a new user, I can't embed links in posts, and it interprets my full XML as links :)
<primary resources>
<elements map key="1">
<value id ="1">
<keywords tags="foo">
</value>
</elements map>
</primary resources>
If I add a new element, I end up with a file that looks like this, which is correct:
<primary resources>
<elements map key="1">
<value id ="1">
<keywords tags="foo">
</value>
</elements map>
<elements map key="2">
<value id ="2">
<keywords tags="bar">
</value>
</elements map>
</primary resources>
However, if I then add another element, I get this, which is incorrect:
<primary resources>
<elements map key="1">
<value id ="1">
<keywords tags="foo">
</value>
</elements map>
<elements map key="2">
<value id ="2">
<keywords tags="bar">
</value>
</elements map>
<elements map key="1">
<value id ="1">
<keywords tags="foo">
</value>
</elements map>
<elements map key="2">
<value id ="2">
<keywords tags="bar">
</value>
</elements map>
<elements map key="3">
<value id ="3">
<keywords tags="foo">
</value>
</elements map>
</primary resources>
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?
|
|
|
|
|
|
|
|
|
|
Re: EMF resource load - SAXParser loading map twice [message #1826307 is a reply to message #1826300] |
Thu, 23 April 2020 08:50   |
German Vega Messages: 104 Registered: December 2015 Location: Grenoble, France |
Senior Member |
|
|
Hello,
Well, I have two comments, but they do not seem to be in anyway related to the problem at hand :
1) You seems to be running your code inside an eclipse plugin, why are you registering manually the XMI resource factory in your resource set? Normally the generated factory should be automatically registered in the global registry.
2) why are you using file URIs, instead of platform resources URIs ?. Your model seems to be located in the workspace.
Coming back to the duplicates problem, if the problem doesn't come from the way you load the resource, maybe it is the way you add the elements. I am not familiar with the use of maps in emf models (I personally have never used) but if you want to share your code perhaps a second pair of eyes may help spot some problem.
Otherwise, we better wait for Ed's reactions
|
|
|
Re: EMF resource load - SAXParser loading map twice [message #1826312 is a reply to message #1826304] |
Thu, 23 April 2020 10:54   |
Paul Hennessey Messages: 9 Registered: April 2020 |
Junior Member |
|
|
Here are the results of another debugging session, this time with a breakpoint in the StringToElementMapImpl constructor, as Ed suggested.
The file contains one element e1.
I load the file, and add element e2. At this point the model in memory looks like this:

I save the model to file, and then load the file again.
I have a breakpoint inside the StringToElementMapImpl ctor, so I can check to see how the map is looking at this stage. It should be empty, but it is not:

Interestingly, as German pointed out earlier, although the coreResources object is new, the primaryResources (and the elementsMap inside) have the same id. I don't know why that is - in our model coreResources has an EReference to primaryResources, and the Containment property is set to true.
Attachment: snip1.PNG
(Size: 68.04KB, Downloaded 230 times)
Attachment: snip2.PNG
(Size: 100.41KB, Downloaded 238 times)
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02375 seconds