|Re: EMF complete model [message #1429437 is a reply to message #1429414]
||Tue, 23 September 2014 08:24
| Ed Merks
Registered: July 2009
On 23/09/2014 9:49 AM, Anthony Garmendia wrote:
> 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);
This is the same as just using EcoreUtil.copy.
> The thing is, that this code copy the references and not the object
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.
|Re: EMF complete model [message #1429563 is a reply to message #1429465]
||Tue, 23 September 2014 12:03
| Ed Merks
Registered: July 2009
On 23/09/2014 11:05 AM, Anthony Garmendia wrote:
> 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.
Powered by FUDForum
. Page generated in 0.01487 seconds