Skip to main content


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 13:43 Go to next message
Greg Babcock is currently offline Greg BabcockFriend
Messages: 41
Registered: October 2012
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 15:43 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
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 15:49 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
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...


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Copying contained objects [message #997720 is a reply to message #997655] Tue, 08 January 2013 15:50 Go to previous message
Greg Babcock is currently offline Greg BabcockFriend
Messages: 41
Registered: October 2012
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: Fri Apr 26 18:14:29 GMT 2024

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

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

Back to the top