Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF complete model
EMF complete model [message #1429414] Tue, 23 September 2014 07:49 Go to next message
Anthony Garmendia is currently offline Anthony GarmendiaFriend
Messages: 46
Registered: May 2014
Member
Hi,

I have .xmi hierarchy using cross document references. I also have an xmi root that contains the other xmi files. I'll try to copy to another xmi file using this code.

EObject obj = file_xmi.Get_Root();
Copier copier = new Copier();
EObject result = copier.copy(obj);
copier.copyReferences();
diagram.getFile_res().getContents().add(result);
diagram.Save_XMI();

The thing is, that this code copy the references and not the object itself.I would like to copy all objects and recursively. The question is, what configuration I need to do to achieve this using copier? or there is another way?

I'm using Eclipse Luna, 64 bit, EMF 2.10.0v20140519. Thanks for any help.

Cheers,
Anthony
Re: EMF complete model [message #1429437 is a reply to message #1429414] Tue, 23 September 2014 08:24 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30354
Registered: July 2009
Senior Member
Anthony,

Comments below.

On 23/09/2014 9:49 AM, Anthony Garmendia wrote:
> Hi,
>
> I have .xmi hierarchy using cross document references. I also have an
> xmi root that contains the other xmi files.
The terminology here is a little confusing. I think you mean you have
an XMI file and that file contains objects that reference other XMI files...
> I'll try to copy to another xmi file using this code.
>
> EObject obj = file_xmi.Get_Root();
This is pseudo code I assume? Or just very odd naming conventions?
> Copier copier = new Copier();
> EObject result = copier.copy(obj);
> copier.copyReferences();
This is the same as just using EcoreUtil.copy.
> diagram.getFile_res().getContents().add(result);
> diagram.Save_XMI();
>
> The thing is, that this code copy the references and not the object
> itself.
The "result" object is definitely a copy of the object. You mean you're
expecting the referenced objects to also be copies of the original
reference I guess...
> I would like to copy all objects and recursively. The question is,
> what configuration I need to do to achieve this using copier? or there
> is another way?
EcoreUtil.copyAll called with all root objects would do the trick. So
the question is, how to get all the root objects so you can copy them
all at once...

But before I explain various approaches (mostly some type of visitor
pattern using things like eObject.eAllContents and
eObject.eCrossReferences), I need to understand what your plan to do
with all these other copied objects. For example, if you have a
resource X that contains at some deeper nesting level an object x, and x
has a reference to y which is in some other resource Y, again at some
very deep nesting level, do you expect all the objects in Y to be
copied, or only y and the objects contained by y?
> I'm using Eclipse Luna, 64 bit, EMF 2.10.0v20140519. Thanks for any help.
>
> Cheers,
> Anthony
>
Re: EMF complete model [message #1429441 is a reply to message #1429414] Tue, 23 September 2014 08:27 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
On 23/09/2014 09:49, Anthony Garmendia wrote:
> Hi,
>
> I have .xmi hierarchy using cross document references. I also have an
> xmi root that contains the other xmi files. I'll try to copy to another
> xmi file using this code.
>
> EObject obj = file_xmi.Get_Root();
> Copier copier = new Copier();
> EObject result = copier.copy(obj);
> copier.copyReferences();
> diagram.getFile_res().getContents().add(result);
> diagram.Save_XMI();
>
> The thing is, that this code copy the references and not the object
> itself.I would like to copy all objects and recursively. The question
> is, what configuration I need to do to achieve this using copier? or
> there is another way?

If you want a 'self-contained' copy, you need to make sure that
referenced elements are in the content tree of the argument passed to
copy(). I think you can call copy() more than once (e.g. one for each
root). Then, copyReferences() will work as you expect.

Felix
Re: EMF complete model [message #1429465 is a reply to message #1429437] Tue, 23 September 2014 09:04 Go to previous messageGo to next message
Anthony Garmendia is currently offline Anthony GarmendiaFriend
Messages: 46
Registered: May 2014
Member
Hi,

Thanks for the replies. The thing is that I expect that all objects being copied in a single .xmi file without cross document references. I think that i don't want all the resources in Y, only y and the objects contained by y.
What would be the best way? Thanks in advance.

Cheers,
Anthony
Re: EMF complete model [message #1429563 is a reply to message #1429465] Tue, 23 September 2014 12:03 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30354
Registered: July 2009
Senior Member
Anthony,

Comments below.

On 23/09/2014 11:05 AM, Anthony Garmendia wrote:
> Hi,
>
> Thanks for the replies. The thing is that I expect that all objects
> being copied in a single .xmi file without cross document references.
So it's not working as you expected.

> I think that i don't want all the resources in Y, only y and the
> objects contained by y.
Unless of course y in turn references something else, and that something
else could be an object that contains y. This is why I ask what
exactly you're expecting...
> What would be the best way?
That depends on what you're hoping to achieve. These other referenced
objects that aren't copied currently, you wan them copied as well, but
those copies too will need to be contained by a resource in the end, in
order to save the resource, otherwise you'll get dangling reference
exceptions when you save.

Suppose you maintained a set of EObjects s, initially empty, and you
start visiting your initial EObject o, you can guard the visit call
with s.add(o) to avoid visiting the same object more than once. In your
visitor method, you can visit o.eContents() and o.eCrossReferences().
When you're done, you'll have all objects reachable via containment and
cross references. From this set, you need to boil it down to "root"
objects. You could do that by building a new set r. I.e., for each
object p from s, add it to r only if s.contains(p.eContainer()) is
false. The you can use EcoreUtil.copyAll for this final set and you'll
have a self contained copy, all of which you must put in a resource.
> Thanks in advance.
>
> Cheers,
> Anthony
Previous Topic:[CDO] Improve performance during loading
Next Topic:[XCore] Can I reference a EAtribute of a Xcore model on another Xcore model (within the same package
Goto Forum:
  


Current Time: Thu Aug 22 00:17:12 GMT 2019

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

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

Back to the top