Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Serialize only selected objects....
Serialize only selected objects.... [message #781046] Fri, 20 January 2012 07:54 Go to next message
Martin  odloucký is currently offline Martin odlouckýFriend
Messages: 49
Registered: July 2010
Member
Hi there,
I wonder, if there is an easy way to serialize only some objects contained in an EList or EMap. I am using default serialization to XMI and I need to save only those objects which have a special attribute set to true. I know that the serialization process is highly configurable and extensible but it si still too complicated for me.

Thanks
Re: Serialize only selected objects.... [message #781173 is a reply to message #781046] Fri, 20 January 2012 08:19 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26215
Registered: July 2009
Senior Member
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Martin,<br>
<br>
Comments below.<br>
<br>
On 20/01/2012 8:54 AM, Martin odloucký wrote:
<blockquote cite="mid:jfb6kb$5ni$1@news.eclipse.org" type="cite">Hi
there, I wonder, if there is an easy way to serialize only some
objects contained in an EList or EMap. </blockquote>
No, you can't filter just parts of a list as you serialize, at least
not easily.   You can selectively serialize starting with certain
objects:<small><br>
</small>
<blockquote><small>  /**</small><br>
<small>   * Write only the subtree starting at the specified list
of EObjects, </small><br>
<small>   * which must be objects contained by the resource.</small><br>
<small>   */</small><br>
<small>  String OPTION_ROOT_OBJECTS = "ROOT_OBJECTS";</small><br>
</blockquote>
If you don't want things to be in your instance, remove them; after
all, they won't be there when you deserialize.<br>
<blockquote cite="mid:jfb6kb$5ni$1@news.eclipse.org" type="cite">I
am using default serialization to XMI and I need to save only
those objects which have a special attribute set to true. I know
that the serialization process is highly configurable and
extensible but it si still too complicated for me. <br>
Thanks
<br>
</blockquote>
</body>
</html>
Re: Serialize only selected objects.... [message #781796 is a reply to message #781173] Sun, 22 January 2012 09:37 Go to previous messageGo to next message
Martin  odloucký is currently offline Martin odlouckýFriend
Messages: 49
Registered: July 2010
Member
Thanks Ed for your answer. Maybe I explain a bit what I am trying to achieve. I am developing a decorator framework which can also serialize its decorators. I use class Decorator which has a reference to EObject which it decorates. The decorators are stored in EMap<EObject, Decorator> which is then serialized. The decorated objects should not know anything about their decorators. So far it works good, but....

If I want to delete a decorated object a need a special command which also deletes all decorators asociated with the object. Thus at least the command manipulating those objects need to know about the decorators. I do not like that, I want decoartors to be completely independent. To achieve this I thought that when serializing the decorators I could save only those with have their decorated objects contained in some resource, otherwise I would leave them out from serialization since they are already deleted and their decorators are of no use anymore.

Thanks for any advice
Re: Serialize only selected objects.... [message #781812 is a reply to message #781796] Sun, 22 January 2012 10:43 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26215
Registered: July 2009
Senior Member
Martin,

Comments below.

On 22/01/2012 10:37 AM, Martin odloucký wrote:
> Thanks Ed for your answer. Maybe I explain a bit what I am trying to
> achieve. I am developing a decorator framework which can also
> serialize its decorators. I use class Decorator which has a reference
> to EObject which it decorates. The decorators are stored in
> EMap<EObject, Decorator> which is then serialized. The decorated
> objects should not know anything about their decorators. So far it
> works good, but....
>
> If I want to delete a decorated object a need a special command which
> also deletes all decorators asociated with the object. Thus at least
> the command manipulating those objects need to know about the
> decorators. I do not like that, I want decoartors to be completely
> independent. To achieve this I thought that when serializing the
> decorators I could save only those with have their decorated objects
> contained in some resource, otherwise I would leave them out from
> serialization since they are already deleted and their decorators are
> of no use anymore.
Are there item providers generated for the decorators themselves? The
default delete command will be setting the key of the map entry to null
when the object being decorated is removed. That will leave the map in
an inconsistent state, especially when more than one object is deleted
there will be more than one key for null. So better you try to
properly clean up the model. A good approach would be to specialize
createSetCommand for you EObjectToDecoratorMapEntryItemProvider so that
when you set the key feature to null, instead of created the normal
command which does that, you create a RemoveCommand to remove the entire
entry. I think that still satisfies your goal of making the decorated
model know nothing about the decorator model, it's only the decorator
model that's smart enough to clean up properly. The advantage is of
course that you don't specialize serialization and you avoid having the
decorator model being in an inconsistent state.
> Thanks for any advice
Re: Serialize only selected objects.... [message #929162 is a reply to message #781812] Mon, 01 October 2012 09:10 Go to previous messageGo to next message
Martin  odloucký is currently offline Martin odlouckýFriend
Messages: 49
Registered: July 2010
Member
Ok, this is a bit old thread, so sorry for reopening, but it took me some time to understand your answer Ed, and it also took some time before the project I am working on got to the point were this solution is being implemented. Unfortunately, things changed a bit.

Now I understand that DeleteCommand can do such a horrendous job as to find all references to deleted object within an editing domain. However, now the decorators should be contained in separate editing domain. So the model has its own editing domain and does not know anything about decorators. The decorators are contained in another domain so now the DeleteCommand would no find references from decorators to decorated objects. So how to save only decorators that decorate objects actually present in the model? It is no problem to have decorators of deleted objects in memory, actually it is a good thing, because when the delete operation is undone, the decorator is still in memory and everything works. But when saving I need to save only valid decorators. I tried just copying those decoartors to a new container before saving and save only the new container. But there is a problem because when a decorator is assigned to a new container it is automatically removed from its original container (oh the smart EMF). Only solution that does not require tinkering with the saving mechanics which comes to my mind is to copy to a new container and after saving copy back to the original. Oh, this seems like a sin against EMF ideas to me.

Thanks for any help.
Re: Serialize only selected objects.... [message #930180 is a reply to message #929162] Tue, 02 October 2012 04:51 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26215
Registered: July 2009
Senior Member
Martin,

Comments below.

On 01/10/2012 11:10 AM, Martin odloucký wrote:
> Ok, this is a bit old thread, so sorry for reopening, but it took me
> some time to understand your answer Ed, and it also took some time
> before the project I am working on got to the point were this solution
> is being implemented. Unfortunately, things changed a bit.
> Now I understand that DeleteCommand can do such a horrendous job as to
> find all references to deleted object within an editing domain.
Yes, it's a relatively trivial bit of brute force logic...
> However, now the decorators should be contained in separate editing
> domain. So the model has its own editing domain and does not know
> anything about decorators. The decorators are contained in another
> domain so now the DeleteCommand would no find references from
> decorators to decorated objects.
I suppose a little like the Ecore model's editor doesn't know anything
about the GenModel editor...
> So how to save only decorators that decorate objects actually present
> in the model?
The GenModel has a reconcile method that implements this type of logic.
I.e., pruning out broken references and adding new decorators for
undecorated things.
> It is no problem to have decorators of deleted objects in memory,
> actually it is a good thing, because when the delete operation is
> undone, the decorator is still in memory and everything works. But
> when saving I need to save only valid decorators. I tried just copying
> those decoartors to a new container before saving and save only the
> new container. But there is a problem because when a decorator is
> assigned to a new container it is automatically removed from its
> original container (oh the smart EMF). Only solution that does not
> require tinkering with the saving mechanics which comes to my mind is
> to copy to a new container and after saving copy back to the original.
> Oh, this seems like a sin against EMF ideas to me.
It's easy to walk the model looking for references that refer to objects
not contained in a resource (or unresolved proxies) and prune those
out. You can always do it with a command so that's it's undoable...
> Thanks for any help.
Re: Serialize only selected objects.... [message #932571 is a reply to message #930180] Thu, 04 October 2012 08:23 Go to previous messageGo to next message
Martin  odloucký is currently offline Martin odlouckýFriend
Messages: 49
Registered: July 2010
Member
Hi Ed, I understand walking the decorators and deleting those with decorated objects not contained in any resource. However, I do not understend when should I execute command doing such a thing. Should I do it when I am deleting the decorated object? This would mean, however, that the editing framework of teh core model has to know that decorators need to be deleted which violates the principle of the core model not knowing anything about being decorated.

Can I somewere read about how the GenModel manages the decorators? It seems that the GenModel is updated when the underlying Ecore model is saved. This is an interesting thing and I would like to know how this is achieved.
Re: Serialize only selected objects.... [message #937012 is a reply to message #932571] Mon, 08 October 2012 15:13 Go to previous messageGo to next message
Martin  odloucký is currently offline Martin odlouckýFriend
Messages: 49
Registered: July 2010
Member
Nobody knows the answer?
Re: Serialize only selected objects.... [message #937272 is a reply to message #932571] Mon, 08 October 2012 21:03 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26215
Registered: July 2009
Senior Member
Martin,

Comments below.

On 04/10/2012 10:23 AM, Martin odloucký wrote:
> Hi Ed, I understand walking the decorators and deleting those with
> decorated objects not contained in any resource. However, I do not
> understend when should I execute command doing such a thing.
The GenModelEditor calls GenModel.reconcile when it first loads the
resource.
> Should I do it when I am deleting the decorated object?
You can do it when you load the decorator model.
> This would mean, however, that the editing framework of teh core
> model has to know that decorators need to be deleted which violates
> the principle of the core model not knowing anything about being
> decorated.
Yes. The Ecore model can be edited separate from the GenModel, so it
needs to be resilient to changes and breakages...
> Can I somewere read about how the GenModel manages the decorators?
Look at what GenModelImpl.reconcile does. It prunes out unresolved
proxies and redecorates new things...
> It seems that the GenModel is updated when the underlying Ecore model
> is saved.
No.
> This is an interesting thing and I would like to know how this is
> achieved.
It looks for problems right after loading.
Previous Topic:Display other properties in EMF tree editor
Next Topic:how to get the reachable objects from an EObject
Goto Forum:
  


Current Time: Sat Nov 22 03:14:23 GMT 2014

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

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