Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Copying contained objects(Copying contained objects)
Copying contained objects [message #997433] Mon, 07 January 2013 08:43 Go to next message
Greg Babcock is currently offline Greg Babcock
Messages: 24
Registered: October 2012
Junior Member
My application makes a copy of a contained object for editing, and then replaces the original on save. ECoreUtil.copy reassigns the containment reference to the copy, is there an easy way to made a copy of a contained object without modifying the original?
Re: Copying contained objects [message #997456 is a reply to message #997433] Mon, 07 January 2013 10:43 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe Bouhier
Messages: 867
Registered: July 2009
Senior Member
Yes, you should customize the copy method in ECoreUtil. You see the copying of references can be isolated see the code:

public static <T extends EObject> T copy(T eObject)
{
Copier copier = new Copier();
EObject result = copier.copy(eObject);
copier.copyReferences();

@SuppressWarnings("unchecked")T t = (T)result;
return t;
}


also see Javadoc for the Copier class:

* The copier delegates to {@link #copyContainment copyContainment}, {@link #copyAttribute copyAttribute} during the copy phase
* and to {@link #copyReference copyReference}, during the cross reference phase.
* This allows tailored handling through derivation.
Re: Copying contained objects [message #997655 is a reply to message #997433] Mon, 07 January 2013 10:49 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25750
Registered: July 2009
Senior Member
Greg,

Comments below.

On 07/01/2013 2:43 PM, Greg Babcock wrote:
> My application makes a copy of a contained object for editing, and
> then replaces the original on save. ECoreUtil.copy reassigns the
> containment reference to the copy,
This sounds like a false statement...
> is there an easy way to made a copy of a contained object without
> modifying the original?
Copying never modifies the original...

As Christophe suggested, you can specialized EcoreUtil.Copier, but I'm
concerned that your assertion above appear false...
Re: Copying contained objects [message #997720 is a reply to message #997655] Tue, 08 January 2013 10:50 Go to previous message
Greg Babcock is currently offline Greg Babcock
Messages: 24
Registered: October 2012
Junior Member
Ed,

You are correct, I can't reproduce it. It only makes me wonder I misinterpreted the problem I was experiencing.
Previous Topic:[CDO] CDOResource path
Next Topic:XMLResource only persists one root object
Goto Forum:
  


Current Time: Thu Apr 24 06:35:25 EDT 2014

Powered by FUDForum. Page generated in 0.02840 seconds