|
|
Re: Loading a model from XMI into an already existing object [message #1268587 is a reply to message #1268569] |
Mon, 10 March 2014 18:03 |
|
A neat trick that the UML2 project's package merger uses is to
initialize an EcoreUtil.Copier with a mapping of existing objects to
"copies" that aren't actually copies but pre-existing objects. Then
running the copier transfers the values of features and copies
contained objects from the "original" objects to the "copies".
So, feeding a (loaded-object, mo) mapping into a copier and performing
the copy might be a place to start ...
HTH,
Christian
On 2014-03-10 17:25:56 +0000, Ed Merks said:
> Ken,
>
> Comments below.
>
> On 10/03/2014 6:04 PM, Ken Mising name wrote:
>> Hello. I am using EMF persistence to save a load my models. I am
>> wondering if it is possible to load a model from an XMI file and set
>> the fields of an already created object.
> No, not really. Deserialization creates new objects...
>>
>> So, right now, I see how to do this:
>>
>> resource.load(null);
>> MyObject mo = (MyObject)resource.getContents().get(0);
>>
>> This will create a brand new MyObject object. What I'd like to do is be
>> able to pass it a MyObject object and have it overwrite any fields it
>> reads from the XMI in the resource.
> You can transfer the values programmatically from that new object using
> the generated APIs, or reflectively using eGet and eSet on all the
> features...
>>
>> Maybe something like:
>>
>> resource.load(mo);
|
|
|
Re: Loading a model from XMI into an already existing object [message #1268594 is a reply to message #1268587] |
Mon, 10 March 2014 18:09 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Christian,
That's a good trick. One aspect to be careful of in any case is to
unset a feature that won't otherwise be set when the new object (or
object being copied) has eIsSet false for that feature...
On 10/03/2014 7:03 PM, Christian W. Damus wrote:
> A neat trick that the UML2 project's package merger uses is to
> initialize an EcoreUtil.Copier with a mapping of existing objects to
> "copies" that aren't actually copies but pre-existing objects. Then
> running the copier transfers the values of features and copies
> contained objects from the "original" objects to the "copies".
>
> So, feeding a (loaded-object, mo) mapping into a copier and performing
> the copy might be a place to start ...
>
> HTH,
>
> Christian
>
>
> On 2014-03-10 17:25:56 +0000, Ed Merks said:
>
>> Ken,
>>
>> Comments below.
>>
>> On 10/03/2014 6:04 PM, Ken Mising name wrote:
>>> Hello. I am using EMF persistence to save a load my models. I am
>>> wondering if it is possible to load a model from an XMI file and set
>>> the fields of an already created object.
>> No, not really. Deserialization creates new objects...
>>>
>>> So, right now, I see how to do this:
>>>
>>> resource.load(null);
>>> MyObject mo = (MyObject)resource.getContents().get(0);
>>>
>>> This will create a brand new MyObject object. What I'd like to do is
>>> be able to pass it a MyObject object and have it overwrite any
>>> fields it reads from the XMI in the resource.
>> You can transfer the values programmatically from that new object
>> using the generated APIs, or reflectively using eGet and eSet on all
>> the features...
>>>
>>> Maybe something like:
>>>
>>> resource.load(mo);
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Re: Loading a model from XMI into an already existing object [message #1268631 is a reply to message #1268594] |
Mon, 10 March 2014 19:23 |
|
Hi, Ed,
Indeed, UML2's package merger is a zoo of special-case method overrides
for reasons just like this.
As usual, the problem with any generic solution is that ... it is generic. :-D
cW
On 2014-03-10 18:09:35 +0000, Ed Merks said:
> Christian,
>
> That's a good trick. One aspect to be careful of in any case is to
> unset a feature that won't otherwise be set when the new object (or
> object being copied) has eIsSet false for that feature...
>
> On 10/03/2014 7:03 PM, Christian W. Damus wrote:
>> A neat trick that the UML2 project's package merger uses is to
>> initialize an EcoreUtil.Copier with a mapping of existing objects to
>> "copies" that aren't actually copies but pre-existing objects. Then
>> running the copier transfers the values of features and copies
>> contained objects from the "original" objects to the "copies".
>>
>> So, feeding a (loaded-object, mo) mapping into a copier and performing
>> the copy might be a place to start ...
>>
>> HTH,
>>
>> Christian
>>
>>
>> On 2014-03-10 17:25:56 +0000, Ed Merks said:
>>
>>> Ken,
>>>
>>> Comments below.
>>>
>>> On 10/03/2014 6:04 PM, Ken Mising name wrote:
>>>> Hello. I am using EMF persistence to save a load my models. I am
>>>> wondering if it is possible to load a model from an XMI file and set
>>>> the fields of an already created object.
>>> No, not really. Deserialization creates new objects...
>>>>
>>>> So, right now, I see how to do this:
>>>>
>>>> resource.load(null);
>>>> MyObject mo = (MyObject)resource.getContents().get(0);
>>>>
>>>> This will create a brand new MyObject object. What I'd like to do is be
>>>> able to pass it a MyObject object and have it overwrite any fields it
>>>> reads from the XMI in the resource.
>>> You can transfer the values programmatically from that new object using
>>> the generated APIs, or reflectively using eGet and eSet on all the
>>> features...
>>>>
>>>> Maybe something like:
>>>>
>>>> resource.load(mo);
|
|
|
Powered by
FUDForum. Page generated in 0.03447 seconds