Serializing/Deserializing subtypes [message #414832] |
Fri, 23 November 2007 11:16  |
Eclipse User |
|
|
|
Originally posted by: petarsams.yahoo.com
Hello all,
I have this ECORE metamodel:
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="porodica"
nsURI="http:///porodica.ecore" nsPrefix="por">
<eClassifiers xsi:type="ecore:EClass" name="Family">
<eStructuralFeatures xsi:type="ecore:EReference" name="members"
ordered="false"
lowerBound="1" upperBound="-1" eType="#//Member" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="dad"
eType="#//Father"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="mom"
eType="#//Mother"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="sons" upperBound="-1"
eType="#//Son"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="daughters"
upperBound="-1"
eType="#//Daughter"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Mother"
eSuperTypes="#//Member"/>
<eClassifiers xsi:type="ecore:EClass" name="Father"
eSuperTypes="#//Member"/>
<eClassifiers xsi:type="ecore:EClass" name="Son" eSuperTypes="#//Member"/>
<eClassifiers xsi:type="ecore:EClass" name="Daughter"
eSuperTypes="#//Member"/>
<eClassifiers xsi:type="ecore:EClass" name="Member">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
</ecore:EPackage>
I have this instance of above model:
<?xml version="1.0" encoding="UTF-8"?>
<por:Family xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:por="http:///porodica.ecore">
<por:members xsi:type="por:Father" name="N1"/>
<por:members xsi:type="por:Mother" name="N2"/>
<por:members xsi:type="por:Daughter" name="N3"/>
<por:members xsi:type="por:Son" name="N4"/>
<por:members xsi:type="por:Daughter" name="N5"/>
<por:members xsi:type="por:Son" name="N6"/>
</por:Family>
What should I do in the code of deserializer in order to be able to load
next instance without reporting "Feature Father not found ...."
<?xml version="1.0" encoding="UTF-8"?>
<por:Family xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:por="http:///porodica.ecore">
<por:Father name="N1"/>
<por:Mother name="N2"/>
<por:Daughter name="N3"/>
<por:Son name="N4"/>
<por:Daughter name="N5"/>
<por:Son name="N6"/>
</por:Family>
I must note that I am getting XMI file as is and that I am not able to
change the layout of elements in Family XMI. I also don't have control of
serialization
process.
Thanx for your attention.
|
|
|
|
|
Re: Serializing/Deserializing subtypes [message #414840 is a reply to message #414839] |
Fri, 23 November 2007 16:23   |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
--------------000102000102050901040103
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Petar,
Given an XSD that describes the XML serialization, you can convert it to
an Ecore model as illustrated in this tutorial.
Tutorial: Generating an EMF Model using XML Schema
< http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. emf.doc/tutorials/xlibmod/xlibmod.html>
You can use annotations on your Ecore model to direct how serialization
and deserialization is done. This document describes the annotations.
XML Schema to Ecore Mapping
< http://www.eclipse.org/modeling/emf/docs/overviews/XMLSchema ToEcoreMapping.pdf>
If you had a schema that corresponds to the actual serialization you
will be receiving that might be the best starting point.
This article might be useful too:
Binding XML to Java
< http://www.theserverside.com/tt/articles/article.tss?l=Bindi ngXMLJava>
PetarSams wrote:
> Hi Ed,
>
> I am dealing with complex problem using XMLVM to create XML representation
> of
> Java byte code and .net assembly language and then using QVT operational
> mapping on them. XMLVM
> gives me XML files which i cannot change.
>
> The XML file, for which you told that it is not good, comes from my head.
> I am using it to simplify problem explanation.
>
> I don't know about XML schemas and i think i can not use them. I use
> smartQVT, and it can only work with ecore and xmi formats.
>
> Can i use annotations in Ecore files or something else to tell
> deserializer/serializer to that <por:Father is subtype of <por:Member? I
> mean if
> <por:members is EReference on type EClass Member, and EClass Father is
> subtype of EClass Member, it should be possible to cast this somewhere
> wthout error.
>
> This is the part of the code that smartQVT uses to load files
>
> this.resource.unload();
> this.resource.load(Collections.EMPTY_MAP);
> Iterator iter = this.resource.getAllContents();
> while (iter.hasNext()) {
> EObject element = (EObject) iter.next();
> extent.add(element);
> }
>
> Maybe i can change something here?
> I read that some of them use something like MetaData to tell serializer how
> to organize layout of the elements.
> I would like to learn what i actually need to solve my problem. If you can
> just point to me what i need to learn it would be great.
>
> Thanx a lot
>
>
> "PetarSams" <petarsams@yahoo.com> wrote in message
> news:fi6ud4$ga0$1@build.eclipse.org...
>
>> Hello all,
>>
>> I have this ECORE metamodel:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <ecore:EPackage xmi:version="2.0"
>> xmlns:xmi="http://www.omg.org/XMI"
>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="porodica"
>> nsURI="http:///porodica.ecore" nsPrefix="por">
>>
>>
>> <eClassifiers xsi:type="ecore:EClass" name="Family">
>> <eStructuralFeatures xsi:type="ecore:EReference" name="members"
>> ordered="false"
>> lowerBound="1" upperBound="-1" eType="#//Member" containment="true"/>
>> <eStructuralFeatures xsi:type="ecore:EReference" name="dad"
>> eType="#//Father"/>
>> <eStructuralFeatures xsi:type="ecore:EReference" name="mom"
>> eType="#//Mother"/>
>> <eStructuralFeatures xsi:type="ecore:EReference" name="sons"
>> upperBound="-1" eType="#//Son"/>
>> <eStructuralFeatures xsi:type="ecore:EReference" name="daughters"
>> upperBound="-1"
>> eType="#//Daughter"/>
>> </eClassifiers>
>>
>> <eClassifiers xsi:type="ecore:EClass" name="Mother"
>> eSuperTypes="#//Member"/>
>> <eClassifiers xsi:type="ecore:EClass" name="Father"
>> eSuperTypes="#//Member"/>
>> <eClassifiers xsi:type="ecore:EClass" name="Son" eSuperTypes="#//Member"/>
>> <eClassifiers xsi:type="ecore:EClass" name="Daughter"
>> eSuperTypes="#//Member"/>
>>
>> <eClassifiers xsi:type="ecore:EClass" name="Member">
>> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
>> lowerBound="1" eType="ecore:EDataType
>> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
>> </eClassifiers>
>>
>> </ecore:EPackage>
>>
>> I have this instance of above model:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <por:Family xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
>> xmlns:por="http:///porodica.ecore">
>> <por:members xsi:type="por:Father" name="N1"/>
>> <por:members xsi:type="por:Mother" name="N2"/>
>> <por:members xsi:type="por:Daughter" name="N3"/>
>> <por:members xsi:type="por:Son" name="N4"/>
>> <por:members xsi:type="por:Daughter" name="N5"/>
>> <por:members xsi:type="por:Son" name="N6"/>
>> </por:Family>
>>
>> What should I do in the code of deserializer in order to be able to load
>> next instance without reporting "Feature Father not found ...."
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <por:Family xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
>> xmlns:por="http:///porodica.ecore">
>> <por:Father name="N1"/>
>> <por:Mother name="N2"/>
>> <por:Daughter name="N3"/>
>> <por:Son name="N4"/>
>> <por:Daughter name="N5"/>
>> <por:Son name="N6"/>
>> </por:Family>
>>
>> I must note that I am getting XMI file as is and that I am not able to
>> change the layout of elements in Family XMI. I also don't have control of
>> serialization
>> process.
>>
>> Thanx for your attention.
>>
>>
>
>
>
--------------000102000102050901040103
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">
Petar,<br>
<br>
Given an XSD that describes the XML serialization, you can convert it
to an Ecore model as illustrated in this tutorial.<br>
<blockquote><a
href=" http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. emf.doc/tutorials/xlibmod/xlibmod.html">Tutorial:
Generating an EMF Model using XML Schema</a><br>
</blockquote>
You can use annotations on your Ecore model to direct how serialization
and deserialization is done. This document describes the annotations.<br>
<blockquote><a
href=" http://www.eclipse.org/modeling/emf/docs/overviews/XMLSchema ToEcoreMapping.pdf">XML
Schema to Ecore Mapping</a><br>
</blockquote>
If you had a schema that corresponds to the actual serialization you
will be receiving that might be the best starting point.<br>
<br>
This article might be useful too:<br>
<blockquote><a target="_out"
href=" http://www.theserverside.com/tt/articles/article.tss?l=Bindi ngXMLJava">Binding
XML to Java</a><br>
<br>
</blockquote>
PetarSams wrote:
<blockquote cite="mid:fi7dd8$khq$1@build.eclipse.org" type="cite">
<pre wrap="">Hi Ed,
I am dealing with complex problem using XMLVM to create XML representation
of
Java byte code and .net assembly language and then using QVT operational
mapping on them. XMLVM
gives me XML files which i cannot change.
The XML file, for which you told that it is not good, comes from my head.
I am using it to simplify problem explanation.
I don't know about XML schemas and i think i can not use them. I use
smartQVT, and it can only work with ecore and xmi formats.
Can i use annotations in Ecore files or something else to tell
deserializer/serializer to that <por:Father is subtype of <por:Member? I
mean if
<por:members is EReference on type EClass Member, and EClass Father is
subtype of EClass Member, it should be possible to cast this somewhere
wthout error.
This is the part of the code that smartQVT uses to load files
this.resource.unload();
this.resource.load(Collections.EMPTY_MAP);
Iterator iter = this.resource.getAllContents();
while (iter.hasNext()) {
EObject element = (EObject) iter.next();
extent.add(element);
}
Maybe i can change something here?
I read that some of them use something like MetaData to tell serializer how
to organize layout of the elements.
I would like to learn what i actually need to solve my problem. If you can
just point to me what i need to learn it would be great.
Thanx a lot
"PetarSams" <a class="moz-txt-link-rfc2396E" href="mailto:petarsams@yahoo.com"><petarsams@yahoo.com></a> wrote in message
<a class="moz-txt-link-freetext" href="news:fi6ud4$ga0$1@build.eclipse.org">news:fi6ud4$ga0$1@build.eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Hello all,
I have this ECORE metamodel:
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage 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:ecore=<a class="moz-txt-link-rfc2396E" href="http://www.eclipse.org/emf/2002/Ecore">"http://www.eclipse.org/emf/2002/Ecore"</a> name="porodica"
nsURI=<a class="moz-txt-link-rfc2396E" href="http:///porodica.ecore">"http:///porodica.ecore"</a> nsPrefix="por">
<eClassifiers xsi:type="ecore:EClass" name="Family">
<eStructuralFeatures xsi:type="ecore:EReference" name="members"
ordered="false"
lowerBound="1" upperBound="-1" eType="#//Member" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="dad"
eType="#//Father"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="mom"
eType="#//Mother"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="sons"
upperBound="-1" eType="#//Son"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="daughters"
upperBound="-1"
eType="#//Daughter"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Mother"
eSuperTypes="#//Member"/>
<eClassifiers xsi:type="ecore:EClass" name="Father"
eSuperTypes="#//Member"/>
<eClassifiers xsi:type="ecore:EClass" name="Son" eSuperTypes="#//Member"/>
<eClassifiers xsi:type="ecore:EClass" name="Daughter"
eSuperTypes="#//Member"/>
<eClassifiers xsi:type="ecore:EClass" name="Member">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
lowerBound="1" eType="ecore:EDataType
<a class="moz-txt-link-freetext" href="http://www.eclipse.org/emf/2002/Ecore#//EString">http://www.eclipse.org/emf/2002/Ecore#//EString</a>"/>
</eClassifiers>
</ecore:EPackage>
I have this instance of above model:
<?xml version="1.0" encoding="UTF-8"?>
<por:Family 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:por=<a class="moz-txt-link-rfc2396E" href="http:///porodica.ecore">"http:///porodica.ecore"</a>>
<por:members xsi:type="por:Father" name="N1"/>
<por:members xsi:type="por:Mother" name="N2"/>
<por:members xsi:type="por:Daughter" name="N3"/>
<por:members xsi:type="por:Son" name="N4"/>
<por:members xsi:type="por:Daughter" name="N5"/>
<por:members xsi:type="por:Son" name="N6"/>
</por:Family>
What should I do in the code of deserializer in order to be able to load
next instance without reporting "Feature Father not found ...."
<?xml version="1.0" encoding="UTF-8"?>
<por:Family 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:por=<a class="moz-txt-link-rfc2396E" href="http:///porodica.ecore">"http:///porodica.ecore"</a>>
<por:Father name="N1"/>
<por:Mother name="N2"/>
<por:Daughter name="N3"/>
<por:Son name="N4"/>
<por:Daughter name="N5"/>
<por:Son name="N6"/>
</por:Family>
I must note that I am getting XMI file as is and that I am not able to
change the layout of elements in Family XMI. I also don't have control of
serialization
process.
Thanx for your attention.
</pre>
</blockquote>
<pre wrap=""><!---->
</pre>
</blockquote>
<br>
</body>
</html>
--------------000102000102050901040103--
|
|
|
Re: Serializing/Deserializing subtypes [message #414852 is a reply to message #414839] |
Mon, 26 November 2007 08:15  |
Eclipse User |
|
|
|
Originally posted by: udaykabe.hotmail.com
Petar,
XSLT might be an option to do the job. Take a look at the sample XSLT
stylesheet that I have attached. You could use something like it to
transform your XMLVM documents to ecore files.
The attached stylesheet will copy all nodes from the input to the output
while transforming the por:Father, por:Mother, por:Son and por:Daughter
elements into por:members elements.
Uday
"PetarSams" <petarsams@yahoo.com> wrote in message
news:fi7dd8$khq$1@build.eclipse.org...
> Hi Ed,
>
> I am dealing with complex problem using XMLVM to create XML representation
> of
> Java byte code and .net assembly language and then using QVT operational
> mapping on them. XMLVM
> gives me XML files which i cannot change.
>
> The XML file, for which you told that it is not good, comes from my head.
> I am using it to simplify problem explanation.
>
> I don't know about XML schemas and i think i can not use them. I use
> smartQVT, and it can only work with ecore and xmi formats.
>
> Can i use annotations in Ecore files or something else to tell
> deserializer/serializer to that <por:Father is subtype of <por:Member? I
> mean if
> <por:members is EReference on type EClass Member, and EClass Father is
> subtype of EClass Member, it should be possible to cast this somewhere
> wthout error.
>
> This is the part of the code that smartQVT uses to load files
>
> this.resource.unload();
> this.resource.load(Collections.EMPTY_MAP);
> Iterator iter = this.resource.getAllContents();
> while (iter.hasNext()) {
> EObject element = (EObject) iter.next();
> extent.add(element);
> }
>
> Maybe i can change something here?
> I read that some of them use something like MetaData to tell serializer
> how
> to organize layout of the elements.
> I would like to learn what i actually need to solve my problem. If you can
> just point to me what i need to learn it would be great.
>
> Thanx a lot
>
>
> "PetarSams" <petarsams@yahoo.com> wrote in message
> news:fi6ud4$ga0$1@build.eclipse.org...
>> Hello all,
>>
>> I have this ECORE metamodel:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <ecore:EPackage xmi:version="2.0"
>> xmlns:xmi="http://www.omg.org/XMI"
>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="porodica"
>> nsURI="http:///porodica.ecore" nsPrefix="por">
>>
>>
>> <eClassifiers xsi:type="ecore:EClass" name="Family">
>> <eStructuralFeatures xsi:type="ecore:EReference" name="members"
>> ordered="false"
>> lowerBound="1" upperBound="-1" eType="#//Member" containment="true"/>
>> <eStructuralFeatures xsi:type="ecore:EReference" name="dad"
>> eType="#//Father"/>
>> <eStructuralFeatures xsi:type="ecore:EReference" name="mom"
>> eType="#//Mother"/>
>> <eStructuralFeatures xsi:type="ecore:EReference" name="sons"
>> upperBound="-1" eType="#//Son"/>
>> <eStructuralFeatures xsi:type="ecore:EReference" name="daughters"
>> upperBound="-1"
>> eType="#//Daughter"/>
>> </eClassifiers>
>>
>> <eClassifiers xsi:type="ecore:EClass" name="Mother"
>> eSuperTypes="#//Member"/>
>> <eClassifiers xsi:type="ecore:EClass" name="Father"
>> eSuperTypes="#//Member"/>
>> <eClassifiers xsi:type="ecore:EClass" name="Son"
>> eSuperTypes="#//Member"/>
>> <eClassifiers xsi:type="ecore:EClass" name="Daughter"
>> eSuperTypes="#//Member"/>
>>
>> <eClassifiers xsi:type="ecore:EClass" name="Member">
>> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
>> lowerBound="1" eType="ecore:EDataType
>> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
>> </eClassifiers>
>>
>> </ecore:EPackage>
>>
>> I have this instance of above model:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <por:Family xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
>> xmlns:por="http:///porodica.ecore">
>> <por:members xsi:type="por:Father" name="N1"/>
>> <por:members xsi:type="por:Mother" name="N2"/>
>> <por:members xsi:type="por:Daughter" name="N3"/>
>> <por:members xsi:type="por:Son" name="N4"/>
>> <por:members xsi:type="por:Daughter" name="N5"/>
>> <por:members xsi:type="por:Son" name="N6"/>
>> </por:Family>
>>
>> What should I do in the code of deserializer in order to be able to load
>> next instance without reporting "Feature Father not found ...."
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <por:Family xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
>> xmlns:por="http:///porodica.ecore">
>> <por:Father name="N1"/>
>> <por:Mother name="N2"/>
>> <por:Daughter name="N3"/>
>> <por:Son name="N4"/>
>> <por:Daughter name="N5"/>
>> <por:Son name="N6"/>
>> </por:Family>
>>
>> I must note that I am getting XMI file as is and that I am not able to
>> change the layout of elements in Family XMI. I also don't have control of
>> serialization
>> process.
>>
>> Thanx for your attention.
>>
>
>
Attachment: sample.xsl
(Size: 1.44KB, Downloaded 245 times)
|
|
|
Powered by
FUDForum. Page generated in 0.05485 seconds