Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Custom serialization of my model
Custom serialization of my model [message #419000] Wed, 07 May 2008 18:26 Go to next message
VincentL is currently offline VincentLFriend
Messages: 88
Registered: July 2009
Member
Hi all,

I'm looking for a method to serialize my model in a different format
than the default XMI format. For example, it could be a .txt file.

Example:

Currently the output file is something like this.

<?xml version="1.0" encoding="UTF-8"?>
<seqeditor:TestFile xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:seqeditor="http://www.opalrt.com/tm.ui.seqeditor" name="myName1"
myAttr="myAttrib1">
<children xsi:type="seqeditor:Variable" name="myVariable"
myAttr="myAttrib2"/>
<children xsi:type="seqeditor:Test" name="myTest" myAttr="myAttrib3">
<children xsi:type="seqeditor:Loop" name="myLoop" myAttr="myAttrib4">
<children xsi:type="seqeditor:StepCompile" name="myName2"
myAttr="myAttrib5"/>
</children>
</children>
</seqeditor:TestFile>


I would like to have something like this instead:

TestFile
name=myName1
myAttr=myAttrib1
Variable
name=myVariable
myAttr=myAttrib2
Test
name=myTest
myAttr=myAttrib3
Loop
name=myLoop
myAttr=myAttrib4
StepCompile
name=myName2
myAttr=myAttrib5


To be honnest, I don't know where to start...

Can I override some method of my Eclass to change the default way the
object serialize? Or should I write complety new code to iterate my
model children?

Any help will be appreciate.

Thanks.

Vincent
Re: Custom serialization of my model [message #419001 is a reply to message #419000] Wed, 07 May 2008 19:42 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Vincent,

Comments below.


Vincent L. wrote:
>
> Hi all,
>
> I'm looking for a method to serialize my model in a different format
> than the default XMI format. For example, it could be a .txt file.
>
> Example:
>
> Currently the output file is something like this.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <seqeditor:TestFile xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:seqeditor="http://www.opalrt.com/tm.ui.seqeditor" name="myName1"
> myAttr="myAttrib1">
> <children xsi:type="seqeditor:Variable" name="myVariable"
> myAttr="myAttrib2"/>
> <children xsi:type="seqeditor:Test" name="myTest" myAttr="myAttrib3">
> <children xsi:type="seqeditor:Loop" name="myLoop" myAttr="myAttrib4">
> <children xsi:type="seqeditor:StepCompile" name="myName2"
> myAttr="myAttrib5"/>
> </children>
> </children>
> </seqeditor:TestFile>
>
>
> I would like to have something like this instead:
>
> TestFile
> name=myName1
> myAttr=myAttrib1
> Variable
> name=myVariable
> myAttr=myAttrib2
> Test
> name=myTest
> myAttr=myAttrib3
> Loop
> name=myLoop
> myAttr=myAttrib4
> StepCompile
> name=myName2
> myAttr=myAttrib5
>
>
> To be honnest, I don't know where to start...
>
> Can I override some method of my Eclass to change the default way the
> object serialize? Or should I write complety new code to iterate my
> model children?
You'd need to implement your own ResourceImpl and specialize the doLoad
and doSave methods. You might want to look at the
BinaryResourceImpl.java in our 2.4M7 build as an example of how to
traverse a structure and convert it to a serialized form; in this case
to a compact binary serialized form.
>
> Any help will be appreciate.
>
> Thanks.
>
> Vincent
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Custom serialization of my model [message #419006 is a reply to message #419001] Wed, 07 May 2008 20:39 Go to previous messageGo to next message
VincentL is currently offline VincentLFriend
Messages: 88
Registered: July 2009
Member
Thanks Ed,

It helps a lot... Do you have any example that show how to use this class?

It will help me to figure out how can I integrate this class in my futur
plugin.

Thanks a lot.

Vincent




Ed Merks wrote:
> Vincent,
>
> Comments below.
>
>
> Vincent L. wrote:
>>
>> Hi all,
>>
>> I'm looking for a method to serialize my model in a different format
>> than the default XMI format. For example, it could be a .txt file.
>>
>> Example:
>>
>> Currently the output file is something like this.
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <seqeditor:TestFile xmi:version="2.0"
>> xmlns:xmi="http://www.omg.org/XMI"
>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xmlns:seqeditor="http://www.opalrt.com/tm.ui.seqeditor" name="myName1"
>> myAttr="myAttrib1">
>> <children xsi:type="seqeditor:Variable" name="myVariable"
>> myAttr="myAttrib2"/>
>> <children xsi:type="seqeditor:Test" name="myTest" myAttr="myAttrib3">
>> <children xsi:type="seqeditor:Loop" name="myLoop" myAttr="myAttrib4">
>> <children xsi:type="seqeditor:StepCompile" name="myName2"
>> myAttr="myAttrib5"/>
>> </children>
>> </children>
>> </seqeditor:TestFile>
>>
>>
>> I would like to have something like this instead:
>>
>> TestFile
>> name=myName1
>> myAttr=myAttrib1
>> Variable
>> name=myVariable
>> myAttr=myAttrib2
>> Test
>> name=myTest
>> myAttr=myAttrib3
>> Loop
>> name=myLoop
>> myAttr=myAttrib4
>> StepCompile
>> name=myName2
>> myAttr=myAttrib5
>>
>> To be honnest, I don't know where to start...
>>
>> Can I override some method of my Eclass to change the default way the
>> object serialize? Or should I write complety new code to iterate my
>> model children?
> You'd need to implement your own ResourceImpl and specialize the doLoad
> and doSave methods. You might want to look at the
> BinaryResourceImpl.java in our 2.4M7 build as an example of how to
> traverse a structure and convert it to a serialized form; in this case
> to a compact binary serialized form.
>>
>> Any help will be appreciate.
>>
>> Thanks.
>>
>> Vincent
>>
Re: Custom serialization of my model [message #419008 is a reply to message #419006] Wed, 07 May 2008 21:07 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------000404010003030902060602
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Vincent,

If you change a generated XyzExample.java in a *.tests project you get
when you invoke Generate Test Code, you could register a resource
factory that creates a binary resource in order to test it.

resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
(Resource.Factory.Registry.DEFAULT_EXTENSION,
new ResourceFactoryImpl()
{
@Override
public Resource createResource(URI uri)
{
return new BinaryResourceImpl(uri);
}
});


Vincent L. wrote:
> Thanks Ed,
>
> It helps a lot... Do you have any example that show how to use this
> class?
>
> It will help me to figure out how can I integrate this class in my
> futur plugin.
>
> Thanks a lot.
>
> Vincent
>
>
>
>
> Ed Merks wrote:
>> Vincent,
>>
>> Comments below.
>>
>>
>> Vincent L. wrote:
>>>
>>> Hi all,
>>>
>>> I'm looking for a method to serialize my model in a different format
>>> than the default XMI format. For example, it could be a .txt file.
>>>
>>> Example:
>>>
>>> Currently the output file is something like this.
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <seqeditor:TestFile xmi:version="2.0"
>>> xmlns:xmi="http://www.omg.org/XMI"
>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>> xmlns:seqeditor="http://www.opalrt.com/tm.ui.seqeditor"
>>> name="myName1" myAttr="myAttrib1">
>>> <children xsi:type="seqeditor:Variable" name="myVariable"
>>> myAttr="myAttrib2"/>
>>> <children xsi:type="seqeditor:Test" name="myTest" myAttr="myAttrib3">
>>> <children xsi:type="seqeditor:Loop" name="myLoop"
>>> myAttr="myAttrib4">
>>> <children xsi:type="seqeditor:StepCompile" name="myName2"
>>> myAttr="myAttrib5"/>
>>> </children>
>>> </children>
>>> </seqeditor:TestFile>
>>>
>>>
>>> I would like to have something like this instead:
>>>
>>> TestFile
>>> name=myName1
>>> myAttr=myAttrib1
>>> Variable
>>> name=myVariable
>>> myAttr=myAttrib2
>>> Test
>>> name=myTest
>>> myAttr=myAttrib3
>>> Loop
>>> name=myLoop
>>> myAttr=myAttrib4
>>> StepCompile
>>> name=myName2
>>> myAttr=myAttrib5
>>> To be honnest, I don't know where to start...
>>>
>>> Can I override some method of my Eclass to change the default way
>>> the object serialize? Or should I write complety new code to iterate
>>> my model children?
>> You'd need to implement your own ResourceImpl and specialize the
>> doLoad and doSave methods. You might want to look at the
>> BinaryResourceImpl.java in our 2.4M7 build as an example of how to
>> traverse a structure and convert it to a serialized form; in this
>> case to a compact binary serialized form.
>>>
>>> Any help will be appreciate.
>>>
>>> Thanks.
>>>
>>> Vincent
>>>


--------------000404010003030902060602
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Vincent,<br>
<br>
If you change a generated XyzExample.java in a *.tests project you get
when you invoke Generate Test Code, you could register a resource
factory that creates a binary resource in order to test it.<br>
<br>
<small>&nbsp;&nbsp;&nbsp;
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (Resource.Factory.Registry.DEFAULT_EXTENSION, <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new ResourceFactoryImpl()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; @Override<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public Resource createResource(URI uri)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new BinaryResourceImpl(uri);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });</small><br>
<br>
<br>
Vincent L. wrote:
<blockquote cite="mid:fvt417$t6s$1@build.eclipse.org" type="cite">Thanks
Ed,
<br>
<br>
It helps a lot... Do you have any example that show how to use this
class?
<br>
<br>
It will help me to figure out how can I integrate this class in my
futur plugin.
<br>
<br>
Thanks a lot.
<br>
<br>
Vincent
<br>
<br>
<br>
<br>
<br>
Ed Merks wrote:
<br>
<blockquote type="cite">Vincent,
<br>
<br>
Comments below.
<br>
<br>
<br>
Vincent L. wrote:
<br>
<blockquote type="cite"><br>
Hi all,
<br>
<br>
I'm looking for a method to serialize my model in a different format
than the default XMI format. For example, it could be a .txt file.
<br>
<br>
Example:
<br>
<br>
Currently the output file is something like this.
<br>
<br>
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
<br>
&lt;seqeditor:TestFile xmi:version="2.0"
xmlns:xmi=<a class="moz-txt-link-rfc2396E" href="http://www.omg.org/XMI">"http://www.omg.org/XMI"</a>
xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a>
xmlns:seqeditor=<a class="moz-txt-link-rfc2396E" href="http://www.opalrt.com/tm.ui.seqeditor">"http://www.opalrt.com/tm.ui.seqeditor"</a> name="myName1"
myAttr="myAttrib1"&gt;
<br>
&nbsp; &lt;children xsi:type="seqeditor:Variable" name="myVariable"
myAttr="myAttrib2"/&gt;
<br>
&nbsp; &lt;children xsi:type="seqeditor:Test" name="myTest"
myAttr="myAttrib3"&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;children xsi:type="seqeditor:Loop" name="myLoop"
myAttr="myAttrib4"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;children xsi:type="seqeditor:StepCompile" name="myName2"
myAttr="myAttrib5"/&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;/children&gt;
<br>
&nbsp; &lt;/children&gt;
<br>
&lt;/seqeditor:TestFile&gt;
<br>
<br>
<br>
I would like to have something like this instead:
<br>
<br>
TestFile
<br>
&nbsp;&nbsp;&nbsp; name=myName1
<br>
&nbsp;&nbsp;&nbsp; myAttr=myAttrib1
<br>
&nbsp;&nbsp;&nbsp; Variable
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; name=myVariable
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; myAttr=myAttrib2
<br>
&nbsp;&nbsp;&nbsp; Test
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; name=myTest
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; myAttr=myAttrib3
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; Loop
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name=myLoop
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myAttr=myAttrib4
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; StepCompile
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; name=myName2
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; myAttr=myAttrib5
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; To be honnest, I don't know where to start...
<br>
<br>
Can I override some method of my Eclass to change the default way the
object serialize? Or should I write complety new code to iterate my
model children?
<br>
</blockquote>
You'd need to implement your own ResourceImpl and specialize the doLoad
and doSave methods. You might want to look at the
BinaryResourceImpl.java in our 2.4M7 build as an example of how to
traverse a structure and convert it to a serialized form; in this case
to a compact binary serialized form.
<br>
<blockquote type="cite"><br>
Any help will be appreciate.
<br>
<br>
Thanks.
<br>
<br>
Vincent
<br>
<br>
</blockquote>
</blockquote>
</blockquote>
<br>
</body>
</html>

--------------000404010003030902060602--


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:EditingDomainActionBarContributor
Next Topic:Re: Object ref string truncation problem
Goto Forum:
  


Current Time: Fri Apr 26 06:54:12 GMT 2024

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

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

Back to the top