Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Merging resources that share the same root node.(Can resources be merged to not include duplicates of the parent node and keep the parent/child structure?)
Merging resources that share the same root node. [message #1802945] Tue, 19 February 2019 12:18 Go to next message
Tobias Fox is currently offline Tobias FoxFriend
Messages: 10
Registered: February 2019
Junior Member
Hi,

I have several XMI files that are parsed into separate Resources as follows. Is there any way the loaded resources can be merged, ignoring the root node that is common to all the resources?

eg I have 2 XMI models:
<root><child1 /></root> and <root><child2 /></root>

And after loading both of them into Resources I would like the resource that represents:
<root><child1 /><child2 /></root>

Any and all help will be appreciated as I'm new to both EMF and eclipse.
Thanks
Re: Merging resources that share the same root node. [message #1802976 is a reply to message #1802945] Wed, 20 February 2019 04:04 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30688
Registered: July 2009
Senior Member
An XMIResourceImpl can serialize multiple root objects in a single resource. But I don't what model you have that serializes as <root> and whether that modeled instance can contain both child1 and a child2. If so, must call root.setChild2(...) with the child from the second resource.
Re: Merging resources that share the same root node. [message #1803005 is a reply to message #1802976] Wed, 20 February 2019 16:21 Go to previous messageGo to next message
Tobias Fox is currently offline Tobias FoxFriend
Messages: 10
Registered: February 2019
Junior Member
Hi Ed.

Thank you for your reply, it is appreciated. I'm reading your book on EMF now and I'm trying to understand the relationship between the contents of a resource and that contents' contents, as is plainly visible in XML.
Supposing my XMI loaded into two resources is

<Model ..... >
<javaProjects ...> ... </javaProjects>
</Model>

<Model ...>
<cProjects> ... </cProjects>
</Model>

how could this become the object representing the following?

<Model ...>
<javaProjects ...> ... </javaProjects>
<cProjects ...> ... </cProjects>
</Model>

The resource holding the first instance of Model has no specific method for setting children, I was hoping there would be a way around it by doing something like

resource1.contents[0].eContents.add(resource2.contents[0].eContents)

If it is possible to do such a thing in a generic way.

Thanks again,
Tobias

[Updated on: Wed, 20 February 2019 16:47]

Report message to a moderator

Re: Merging resources that share the same root node. [message #1803018 is a reply to message #1803005] Thu, 21 February 2019 04:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30688
Registered: July 2009
Senior Member
The list returned by eObject.eContents() is not modifiable, so add will throw an UnsupportedOperationException. You'd need to do ((Model)resource1.getContents().get(0)).getProjects().addAll(((Model)resource2.getContents().get(0)).getProjects()) to move the projects contained by resource2's Model to the Model in resource1. Because projects is a containment reference the projects will be removed from resource2's Model and added to resource1's Model. There are generic ways to do this, but there are many cases to consider, i.e., do resource1 and resource2 contain the same type of object? If so you could iterate over root1.eClass().getEAllContainments() and do either an root1.eSet(feature, root2.eGet(feature)), or a ((List<EObject)root1.eGet(feature)).addAll((List<EObject>)root2.eGet(feature)) depending on whether feature.isMany is false or true. That would move all the contained objects from root2 to root1.
Re: Merging resources that share the same root node. [message #1803069 is a reply to message #1803018] Thu, 21 February 2019 19:03 Go to previous message
Tobias Fox is currently offline Tobias FoxFriend
Messages: 10
Registered: February 2019
Junior Member
eClass().getEAllContainments() is exactly what I was needing.
Thanks Ed.
Previous Topic:How to use an Adapter to get all the notifications in a EMF model?
Next Topic:[CDO] TimeoutRuntimeException -> how to avoid them???
Goto Forum:
  


Current Time: Wed Dec 11 00:58:46 GMT 2019

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

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

Back to the top