Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Re: How to create a copy of an EObject with non-null Resource
Re: How to create a copy of an EObject with non-null Resource [message #419490] Sat, 24 May 2008 16:28 Go to next message
Lars Schneider is currently offline Lars SchneiderFriend
Messages: 50
Registered: July 2009
Member
I think this problem is better of in this newsgroup.

> Hi,
> I have a little problem using EcoreUtil.copy(EObject) because the
> eResource() of that copy returns null.
>
> More precisely I want to copy the root of a model, change it and compare
> it to the original with EMF Compare. I think the following code snippet
> explains it best:
>
> //...
> EObject copy = EcoreUtil.copy(original);
> Transformation trans = new Transformation(copy);
> trans.transform(); // changes copy
> MatchModel match = null;
> try {
> match = MatchService.doMatch(original, copy
> Collections.<String, Object> emptyMap());
> } catch (InterruptedException e) {
> e.printStackTrace();
> }
> //...
>
> The problem is that doMatch(...) ends up in a NullPointerException
> because the resource of copy is null. Does anyone have an idea how to
> solve this problem? I think I can either set the resource manually or
> get another IMatchEngine implementation. But I don't know how to.
> Lars
Re: How to create a copy of an EObject with non-null Resource [message #419491 is a reply to message #419490] Sat, 24 May 2008 16:39 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
Lars,

Ideally it would be tolerant of a null resource. You'd need to access
the resource set and create a new resource of the appropriate type to
contain the copy, i.e.,
original.eResource().getResourceSet().createResource(...).ge tContents().add(copy)...


Lars Schneider wrote:
> I think this problem is better of in this newsgroup.
>
>> Hi,
>> I have a little problem using EcoreUtil.copy(EObject) because the
>> eResource() of that copy returns null.
>>
>> More precisely I want to copy the root of a model, change it and
>> compare it to the original with EMF Compare. I think the following
>> code snippet explains it best:
>>
>> //...
>> EObject copy = EcoreUtil.copy(original);
>> Transformation trans = new Transformation(copy);
>> trans.transform(); // changes copy
>> MatchModel match = null;
>> try {
>> match = MatchService.doMatch(original, copy
>> Collections.<String, Object> emptyMap());
>> } catch (InterruptedException e) {
>> e.printStackTrace();
>> }
>> //...
>>
>> The problem is that doMatch(...) ends up in a NullPointerException
>> because the resource of copy is null. Does anyone have an idea how to
>> solve this problem? I think I can either set the resource manually or
>> get another IMatchEngine implementation. But I don't know how to.
>> Lars


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to create a copy of an EObject with non-null Resource [message #419507 is a reply to message #419490] Sun, 25 May 2008 18:23 Go to previous message
Cedric Brun is currently offline Cedric BrunFriend
Messages: 431
Registered: July 2009
Senior Member
Hi Lars,

What EMF Compare build are you using ? The RC1 build should have fixed this
NPE (bug 230347 - see the release
notes :http://www.eclipse.org/modeling/emft/news/relnotes.php?proj ect=compare&version=0.8.0RC1 )

You should not have to provide your own match engine for such a thing :)

Cédric


Lars Schneider wrote:

> I think this problem is better of in this newsgroup.
>
>> Hi,
>> I have a little problem using EcoreUtil.copy(EObject) because the
>> eResource() of that copy returns null.
>>
>> More precisely I want to copy the root of a model, change it and compare
>> it to the original with EMF Compare. I think the following code snippet
>> explains it best:
>>
>> //...
>> EObject copy = EcoreUtil.copy(original);
>> Transformation trans = new Transformation(copy);
>> trans.transform(); // changes copy
>> MatchModel match = null;
>> try {
>> match = MatchService.doMatch(original, copy
>> Collections.<String, Object> emptyMap());
>> } catch (InterruptedException e) {
>> e.printStackTrace();
>> }
>> //...
>>
>> The problem is that doMatch(...) ends up in a NullPointerException
>> because the resource of copy is null. Does anyone have an idea how to
>> solve this problem? I think I can either set the resource manually or
>> get another IMatchEngine implementation. But I don't know how to.
>> Lars


http://cedric.brun.io news and articles on eclipse and eclipse modeling.
Previous Topic:Generated Code in eGet-inefficient for primitive-integer values?
Next Topic:EMF rcp changes in Ganymede M7?
Goto Forum:
  


Current Time: Thu Sep 26 03:09:00 GMT 2024

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

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

Back to the top