Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Copy EObject between resources with saving id
Copy EObject between resources with saving id [message #1702133] Mon, 20 July 2015 09:24 Go to next message
Alexander Emelianov is currently offline Alexander EmelianovFriend
Messages: 10
Registered: July 2015
Junior Member
Hi,
How I can copy or move EObject to another resource with saving value of id attribute?
Re: Copy EObject between resources with saving id [message #1702173 is a reply to message #1702133] Mon, 20 July 2015 13:16 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30372
Registered: July 2009
Senior Member
I assume you mean the extrinsic IDs assigned by the resource. Note
that if you directly use EcoreUtil.Copier it's a map from old to new and
that you can use eObject.eResource(), cast it to an XMLResource, and use
getID. If you put the copies into a new resource, you can use that to
assign the same ID as it had in the old resource.

On 20/07/2015 11:24 AM, Alexander Emelianov wrote:
> Hi,
> How I can copy or move EObject to another resource with saving value
> of id attribute?
Re: Copy EObject between resources with saving id [message #1702300 is a reply to message #1702173] Tue, 21 July 2015 12:43 Go to previous message
Alexander Emelianov is currently offline Alexander EmelianovFriend
Messages: 10
Registered: July 2015
Junior Member
This works:
UMLResource res = (UMLResource) resourceSet.getResource(URI.createFileURI("NPModel.uml"), true);
JsonResource resource = (JsonResource) resourceSet.createResource(URI.createURI("generated/diagram.json"));
res.getAllContents().forEachRemaining(eObject -> resource.setID(eObject, res.getID(eObject)));
resource.getContents().addAll(res.getContents());
Previous Topic:Help with installing EMF Feature Model Diagram Editor
Next Topic:Set field value problem
Goto Forum:
  


Current Time: Sun Aug 25 23:10:33 GMT 2019

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

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

Back to the top