Serialize an EObject without changing its resource [message #427526] |
Fri, 20 February 2009 03:02  |
Eclipse User |
|
|
|
Hi,
I wonder whether it is possible to serialize a single EObject into a
String without changing its resource (or any other side effects).
Here's why: We have an EMF model which is loaded from an XML file. The
application has a special viewer that shows a nicely displayed object
inside of a browser. For this, I would like to use the serialized form
of that object, run it through a stylesheet processor and put the result
into the browser.
This worked when I was using my own model code where one could just call
object:serialize(some stream). With EMF Serialization it goes like this:
Resource resource = ...
resource.getContents().add(object);
resource.save(out, null);
And it works. But, it changes the resource where the object was
contained in and the rest of the application starts to fail... for
instance, object.eContainer() is suddenly null.
Thanks for any hints
Peter
|
|
|
|
|
Re: Serialize an EObject without changing its resource [message #427531 is a reply to message #427528] |
Fri, 20 February 2009 06:30  |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
--------------080500060904060207020602
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
Peter,
This option is likely to serve your purpose as well:
/**
* Write only the subtree starting at the specified list of EObjects,
* which must be objects contained by the resource.
*/
String OPTION_ROOT_OBJECTS = "ROOT_OBJECTS";
Peter Kullmann wrote:
> Thanks a lot, Eike. Copy works like charm.
> Peter
>
> Eike Stepper schrieb:
>> Peter,
>>
>> I think it's absolutely necessary to use a Resource for serialization
>> because all the persistence logic is concentrated there.
>> If you can't afford to change the object during this process you
>> could try to copy it and add that copy to the resource.
>> I'm not so used to the copy utilities like EcoreUtil.copy(). You'll
>> have to ensure that you don't copy too much (e.g. deep copy)...
>>
>> Cheers
>> /Eike
>>
>> ----
>> http://thegordian.blogspot.com
>>
>>
>>
>> Peter Kullmann schrieb:
>>> Hi,
>>>
>>> I wonder whether it is possible to serialize a single EObject into a
>>> String without changing its resource (or any other side effects).
>>>
>>> Here's why: We have an EMF model which is loaded from an XML file.
>>> The application has a special viewer that shows a nicely displayed
>>> object inside of a browser. For this, I would like to use the
>>> serialized form of that object, run it through a stylesheet
>>> processor and put the result into the browser.
>>> This worked when I was using my own model code where one could just
>>> call object:serialize(some stream). With EMF Serialization it goes
>>> like this:
>>>
>>> Resource resource = ...
>>> resource.getContents().add(object);
>>> resource.save(out, null);
>>>
>>> And it works. But, it changes the resource where the object was
>>> contained in and the rest of the application starts to fail... for
>>> instance, object.eContainer() is suddenly null.
>>>
>>> Thanks for any hints
>>> Peter
--------------080500060904060207020602
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Peter,<br>
<br>
This option is likely to serve your purpose as well:<br>
<blockquote><small>
|
|
|
Powered by
FUDForum. Page generated in 0.29129 seconds