Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Is it possible that ECoreUtil.Copy() changes an EObject?
Is it possible that ECoreUtil.Copy() changes an EObject? [message #423992] Mon, 13 October 2008 16:32 Go to next message
Eclipse UserFriend
Originally posted by: zhodaie.gmail.com

Hi all,

I encountered a problem using ECoreUtil.Copy() method. Here are the
steps I did:

1. create objA (it contains a hierarchy of containments and EObjects
referencing each other)
2. copy to create objB (objB = (cast)ECoreUtil.Copy(objA))
3. serialize both objects to separate files

Now i expect that the two files have exactly identical contents. But
they differ in just one line, in which two references of an ordered
containment are output vice versa.
I am sure that no problem occurs during serialization as i checked the
serialization routine with the same object (i.e. serialize(objA, objA))
and both files were identical. That is, EcoreUtil.Copy() changes
contents of objA as its being copied to objB.

Can someone please explain what is the possible problem?

Thanks in advance,
Zardosht
Re: Is it possible that ECoreUtil.Copy() changes an EObject? [message #423993 is a reply to message #423992] Mon, 13 October 2008 16:49 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Zardosht,

This should not be possible. You could add an adapter to listen for
any changes. E.g., you might use an EContentAdapter on the original
object to monitor any notifications that changes would produce...



Zardosht Hodaie wrote:
> Hi all,
>
> I encountered a problem using ECoreUtil.Copy() method. Here are the
> steps I did:
>
> 1. create objA (it contains a hierarchy of containments and EObjects
> referencing each other)
> 2. copy to create objB (objB = (cast)ECoreUtil.Copy(objA))
> 3. serialize both objects to separate files
>
> Now i expect that the two files have exactly identical contents. But
> they differ in just one line, in which two references of an ordered
> containment are output vice versa.
> I am sure that no problem occurs during serialization as i checked the
> serialization routine with the same object (i.e. serialize(objA,
> objA)) and both files were identical. That is, EcoreUtil.Copy()
> changes contents of objA as its being copied to objB.
>
> Can someone please explain what is the possible problem?
>
> Thanks in advance,
> Zardosht


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Is it possible that ECoreUtil.Copy() changes an EObject? [message #424010 is a reply to message #423993] Tue, 14 October 2008 10:04 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: zhodaie.gmail.com

thank you Ed for your fast reply. The problem was in model. An Attribute
of one of containments had its derived value set to true. I don't how
it fixed the problem, but it was the cause.


Ed Merks schrieb:
> Zardosht,
>
> This should not be possible. You could add an adapter to listen for
> any changes. E.g., you might use an EContentAdapter on the original
> object to monitor any notifications that changes would produce...
>
>
>
> Zardosht Hodaie wrote:
>> Hi all,
>>
>> I encountered a problem using ECoreUtil.Copy() method. Here are the
>> steps I did:
>>
>> 1. create objA (it contains a hierarchy of containments and EObjects
>> referencing each other)
>> 2. copy to create objB (objB = (cast)ECoreUtil.Copy(objA))
>> 3. serialize both objects to separate files
>>
>> Now i expect that the two files have exactly identical contents. But
>> they differ in just one line, in which two references of an ordered
>> containment are output vice versa.
>> I am sure that no problem occurs during serialization as i checked the
>> serialization routine with the same object (i.e. serialize(objA,
>> objA)) and both files were identical. That is, EcoreUtil.Copy()
>> changes contents of objA as its being copied to objB.
>>
>> Can someone please explain what is the possible problem?
>>
>> Thanks in advance,
>> Zardosht
Re: Is it possible that ECoreUtil.Copy() changes an EObject? [message #424013 is a reply to message #424010] Tue, 14 October 2008 10:18 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Zardosht,

Yes, derived features aren't copied. The assumption is that they are
derived/computed from the values of other non-derived features.


Zardosht Hodaie wrote:
> thank you Ed for your fast reply. The problem was in model. An
> Attribute of one of containments had its derived value set to true. I
> don't how it fixed the problem, but it was the cause.
>
>
> Ed Merks schrieb:
>> Zardosht,
>>
>> This should not be possible. You could add an adapter to listen
>> for any changes. E.g., you might use an EContentAdapter on the
>> original object to monitor any notifications that changes would
>> produce...
>>
>>
>>
>> Zardosht Hodaie wrote:
>>> Hi all,
>>>
>>> I encountered a problem using ECoreUtil.Copy() method. Here are the
>>> steps I did:
>>>
>>> 1. create objA (it contains a hierarchy of containments and EObjects
>>> referencing each other)
>>> 2. copy to create objB (objB = (cast)ECoreUtil.Copy(objA))
>>> 3. serialize both objects to separate files
>>>
>>> Now i expect that the two files have exactly identical contents. But
>>> they differ in just one line, in which two references of an ordered
>>> containment are output vice versa.
>>> I am sure that no problem occurs during serialization as i checked
>>> the serialization routine with the same object (i.e. serialize(objA,
>>> objA)) and both files were identical. That is, EcoreUtil.Copy()
>>> changes contents of objA as its being copied to objB.
>>>
>>> Can someone please explain what is the possible problem?
>>>
>>> Thanks in advance,
>>> Zardosht


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Generating comments
Next Topic:[CDO]: failover?
Goto Forum:
  


Current Time: Thu Apr 25 01:30:26 GMT 2024

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

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

Back to the top