Home » Modeling » EMF » Custom serialization
|
Re: Custom serialization [message #425666 is a reply to message #425661] |
Thu, 04 December 2008 12:57 |
Ed Merks Messages: 33133 Registered: July 2009 |
Senior Member |
|
|
Rodolphe,
Comments below.
Rodolphe Beck wrote:
> Hello,
>
> I have to save my objects in a particular format, therefore I must
> customize the way EMF objects are serialized.
>
> I first tried to get in memory access to the object, but I couldn't
> find a way to do it.
> Then I wanted to reload the .XMI and iterate on it to recover my
> objects, but it still doesn't work.
What specifically is the symptom of "not working"?
>
> Here is my code :
> http://pastebin.com/m286c17ba
It doesn't seem good to use "toOSString" since that will use "\" on
Windows rather than "/" as is proper for a URI.
>
> As advised in another post here, I looked at the XyzExample.java in
> *test.
>
> It works in the test, not in my plugin, why ?
Again, the symptoms of not working are kind of important to understand.
I wonder what you use wsLocation for? Likely no good will come from
accessing the physical OS-specific file path for the workspace...
>
> Thanks.
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | |
Re: Custom serialization [message #425694 is a reply to message #425682] |
Fri, 05 December 2008 08:29 |
Rodolphe Beck Messages: 18 Registered: July 2009 |
Junior Member |
|
|
Ed Merks wrote:
> Rodolphe,
> Comments below.
> Rodolphe Beck wrote:
>> Ok my message wass totaly unclear sorry about that...
>>
>> I changed my code into :
>> http://pastebin.com/m7ebe537d
>>
>> And I managed to have my resource. Then, when I wanted to get the
>> content of my file, so I tried :
>> TreeIterator<EObject> ti = instanceResource.getAllContents();
>> But my treeiterator was empty...
>>
>> With : EList<EObject> list = instanceResource.getContents();
>> It works.
> That doesn't make must sense. The former walks the whole tree and the
> latter walks just the roots, so the former should always include the
> latter...
Yes, but in my case it doesn't :)
>>
>> By the way, is it possible to access the objects directly in memory,
>> so I don't have to parse the file again ?
> Only by loading a resource will have have an in-memory representation.
> You can keep it around as long as you need it.
Sure, but when you create an element of your diagram, before you type
CTRL+s to serialize the element into the diagram file, this element should
be somewhere in memory. I couldn't find a way to load it directly from
here.
>>
>> Thanks
>>
|
|
| | |
Re: Custom serialization [message #425703 is a reply to message #425694] |
Fri, 05 December 2008 11:06 |
Ed Merks Messages: 33133 Registered: July 2009 |
Senior Member |
|
|
Rodolphe,
Comments below.
Rodolphe Beck wrote:
> Ed Merks wrote:
>
>> Rodolphe,
>
>> Comments below.
>
>
>> Rodolphe Beck wrote:
>>> Ok my message wass totaly unclear sorry about that...
>>>
>>> I changed my code into :
>>> http://pastebin.com/m7ebe537d
>>>
>>> And I managed to have my resource. Then, when I wanted to get the
>>> content of my file, so I tried :
>>> TreeIterator<EObject> ti = instanceResource.getAllContents();
>>> But my treeiterator was empty...
>>>
>>> With : EList<EObject> list = instanceResource.getContents();
>>> It works.
>> That doesn't make must sense. The former walks the whole tree and
>> the latter walks just the roots, so the former should always include
>> the latter...
> Yes, but in my case it doesn't :)
So you claim, but it seems impossible to me for ti.hasNext() not to
return precisely the value of
instanceResource.getContents().iterator().hasNext() the first time it's
called because that's how the tree iterator is implemented...
>>>
>>> By the way, is it possible to access the objects directly in memory,
>>> so I don't have to parse the file again ?
>> Only by loading a resource will have have an in-memory
>> representation. You can keep it around as long as you need it.
> Sure, but when you create an element of your diagram, before you type
> CTRL+s to serialize the element into the diagram file, this element
> should be somewhere in memory.
I'm very confused by how this relates to not parsing the file again though.
> I couldn't find a way to load it directly from here.
If you have it in memory, why do you need to load it. There's clearly
something I'm completely missing in your description...
>>>
>>> Thanks
>>>
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | |
Re: Custom serialization [message #425738 is a reply to message #425703] |
Fri, 05 December 2008 17:50 |
Rodolphe Beck Messages: 18 Registered: July 2009 |
Junior Member |
|
|
Ed Merks wrote:
> Rodolphe,
> Comments below.
> Rodolphe Beck wrote:
>> Ed Merks wrote:
>>
>>> Rodolphe,
>>
>>> Comments below.
>>
>>
>>> Rodolphe Beck wrote:
>>>> Ok my message wass totaly unclear sorry about that...
>>>>
>>>> I changed my code into :
>>>> http://pastebin.com/m7ebe537d
>>>>
>>>> And I managed to have my resource. Then, when I wanted to get the
>>>> content of my file, so I tried :
>>>> TreeIterator<EObject> ti = instanceResource.getAllContents();
>>>> But my treeiterator was empty...
>>>>
>>>> With : EList<EObject> list = instanceResource.getContents();
>>>> It works.
>>> That doesn't make must sense. The former walks the whole tree and
>>> the latter walks just the roots, so the former should always include
>>> the latter...
>> Yes, but in my case it doesn't :)
> So you claim, but it seems impossible to me for ti.hasNext() not to
> return precisely the value of
> instanceResource.getContents().iterator().hasNext() the first time it's
> called because that's how the tree iterator is implemented...
The proof then :
http://img229.imageshack.us/my.php?image=treeiteratorfu3.jpg
My final code :
http://pastebin.com/m503cce28
About the debug thing, that is how I solved my problems actually.
Concerning the in memory access of objects, I was thinking of accessing
the same registry as EMF/GMF.
Here I create a diagram with EMF/GMF, when I hit ctrl+s my objects are
serialized from "somewhere in memory" to my diagram file.
Then when I want to export in another format, I parse the diagram file
manually to get the objects and serialize them in another format.
In memory access would be accessing the objects withour re-parsing the
file (as it is already managed by EMF/GMF)
|
|
|
Re: Custom serialization [message #425742 is a reply to message #425738] |
Fri, 05 December 2008 19:07 |
Ed Merks Messages: 33133 Registered: July 2009 |
Senior Member |
|
|
Rodolphe,
Comments below.
Rodolphe Beck wrote:
> Ed Merks wrote:
>
>> Rodolphe,
>
>> Comments below.
>
>
>> Rodolphe Beck wrote:
>>> Ed Merks wrote:
>>>
>>>> Rodolphe,
>>>
>>>> Comments below.
>>>
>>>
>>>> Rodolphe Beck wrote:
>>>>> Ok my message wass totaly unclear sorry about that...
>>>>>
>>>>> I changed my code into :
>>>>> http://pastebin.com/m7ebe537d
>>>>>
>>>>> And I managed to have my resource. Then, when I wanted to get the
>>>>> content of my file, so I tried :
>>>>> TreeIterator<EObject> ti = instanceResource.getAllContents();
>>>>> But my treeiterator was empty...
>>>>>
>>>>> With : EList<EObject> list = instanceResource.getContents();
>>>>> It works.
>>>> That doesn't make must sense. The former walks the whole tree and
>>>> the latter walks just the roots, so the former should always
>>>> include the latter...
>>> Yes, but in my case it doesn't :)
>> So you claim, but it seems impossible to me for ti.hasNext() not to
>> return precisely the value of
>> instanceResource.getContents().iterator().hasNext() the first time
>> it's called because that's how the tree iterator is implemented...
> The proof then :
> http://img229.imageshack.us/my.php?image=treeiteratorfu3.jpg
Well, the TreeIterator is actually implements as a list (stack) of
iterators, so looking at the toString version before calling hasNext
will show you the same thing as an empty list, but that's not proof that
hasNext will return false nor that next() will not return the first
object in the root of the resource.
>
> My final code :
>
> http://pastebin.com/m503cce28
>
> About the debug thing, that is how I solved my problems actually.
>
> Concerning the in memory access of objects, I was thinking of
> accessing the same registry as EMF/GMF.
>
> Here I create a diagram with EMF/GMF, when I hit ctrl+s my objects are
> serialized from "somewhere in memory" to my diagram file.
From the objects contained in the resource managed by the editor.
> Then when I want to export in another format, I parse the diagram file
> manually to get the objects and serialize them in another format.
> In memory access would be accessing the objects withour re-parsing the
> file (as it is already managed by EMF/GMF)
You just need to get your hands on the resource objects in that already
open editor...
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Goto Forum:
Current Time: Tue Apr 16 14:45:22 GMT 2024
Powered by FUDForum. Page generated in 1.56677 seconds
|