[prev in list] [next in list] [prev in thread] [next in thread]
List: castor-user
Subject: Re: [castor-user] Using Interfaces during marshalling/unmarshalling
From: "Emerson, Matt" <Matt.Emerson () FMR ! COM>
Date: 2005-03-11 22:41:51
Message-ID: F37047909B49CC4D9BB75D6CCD33F627309BC1 () MSGMMKDRB2WIN ! DMN1 ! FMR ! COM
[Download RAW message or body]
This is a multi-part message in MIME format.
--MML_1110580969_29861@2522.exolab.org
content-class: urn:content-classes:message
Content-Type: multipart/alternative;
boundary="----_=_NextPart_001_01C5268B.847C0D90"
This is a multi-part message in MIME format.
I just discovered that we have manually turned off the creation of the
xsi:type in the final document. Once I removed this, I was able to
marshall/unmarshall correctly.
Thanks,
Matt
-----Original Message-----
From: Emerson, Matt
Sent: Wednesday, March 09, 2005 6:58 PM
To: castor-user@exolab.org
Subject: [WARNING: This message originated from outside of
Fidelity] [castor-user] Using Interfaces during
marshalling/unmarshalling
I have created two classes and 1 interface: Product, SubProduct,
and SubProductIF
They are as follows:
Public class Product
private SubProductIF sample
public Product()
public void setSample(SubProductIF data) { this sample =
data; }
public SubProductIF getSample() { return this.sample; }
}
Public class SubProduct implements SubProductIF
{
private String name;
private String value;
public SubProduct() {}
public void setName(String data) { this.name = data; }
public void set Value(String data) { this.value = data;
}
public String getName() { return this.name; }
public String getValue() { return this.value; }
}
And the interface:
public interface SubProductIF
{
public void setName(String pValue);
public String getName();
public void setValue(String pValue);
public String getValue();
}
The mapping is as follows:
<mapping>
<description>Description of the mapping for the Product
Class</description>
<class name="com.fmr.cfit.matt.castor.Product">
<map-to xml="WrapperProductClass"></map-to>
<field name="sample"
type="com.fmr.cfit.matt.castor.SubProductIF">
<bind-xml name="sample_product"
node="element"/>
</field>
</class>
<class name="com.fmr.cfit.matt.castor.SubProduct">
<map-to xml="sub_product"></map-to>
<field name="name" type="java.lang.String">
<bind-xml name="name" node="attribute"/>
</field>
<field name="value" type="java.lang.String">
<bind-xml name="value" node="element"/>
</field>
</class>
</mapping>
When I marshall the class, everything works fine. However, when
I unmarshall it, it throws an error because it can't find the
constructor for SubProduct. Reading the documentation, it says to use
the xsi:type attribute...but that seems like something that has to be
added to the final marshalled class. Since I want this to be an
identity transformation, if I can't do that automatically, it is not
very useful. Does anyone have any ideas how I could make this into an
two-way transform using interfaces?
Thanks,
Matt
The Error:
#endElement: class
#endElement: mapping
#startElement: WrapperProductClass
#startElement: sample_product
unable to instantiate a new type of:
com.fmr.cfit.matt.castor.SubProductIF org.xml.sax.SAXException: unable
to instantiate a new type of: com.fmr.cfit.matt.castor.SubProductIF
void
org.exolab.castor.xml.UnmarshalHandler.startElement(java.lang.String,
java.lang.String, org.exolab.castor.xml.AttributeSet)
UnmarshalHandler.java:2096
void
org.exolab.castor.xml.UnmarshalHandler.startElement(java.lang.String,
java.lang.String, java.lang.String, org.xml.sax.Attributes)
UnmarshalHandler.java:1292
void
org.apache.xerces.parsers.SAXParser.startElement(org.apache.xerces.utils
.QName, org.apache.xerces.framework.XMLAttrList, int)
SAXParser.java:1371
void
org.apache.xerces.validators.common.XMLValidator.callStartElement(org.ap
ache.xerces.utils.QName) XMLValidator.java:840
boolean
org.apache.xerces.framework.XMLDocumentScanner.scanElement(org.apache.xe
rces.utils.QName) XMLDocumentScanner.java:1852 boolean
org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatc
h(boolean) XMLDocumentScanner.java:1233 boolean
org.apache.xerces.framework.XMLDocumentScanner.parseSome(boolean)
XMLDocumentScanner.java:380 void
org.apache.xerces.framework.XMLParser.parse(org.xml.sax.InputSource)
XMLParser.java:908
java.lang.Object
org.exolab.castor.xml.Unmarshaller.unmarshal(org.xml.sax.InputSource)
Unmarshaller.java:605
java.lang.Object
org.exolab.castor.xml.Unmarshaller.unmarshal(java.io.Reader)
Unmarshaller.java:513 void
com.fmr.cfit.matt.castor.TestCastor.runTest2()
TestCastor.java:76 void
com.fmr.cfit.matt.castor.TestCastor.main(ja
[Attachment #3 (text/html)]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Message</TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2800.1491" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=243094022-11032005><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=243094022-11032005><FONT face=Arial color=#0000ff size=2>I just
discovered that we have manually turned off the creation of the xsi:type in the
final document. Once I removed this, I was able to marshall/unmarshall
correctly.</FONT></SPAN></DIV>
<DIV><SPAN class=243094022-11032005><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=243094022-11032005><FONT face=Arial color=#0000ff
size=2>Thanks,</FONT></SPAN></DIV>
<DIV><SPAN class=243094022-11032005><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=243094022-11032005><FONT face=Arial color=#0000ff
size=2>Matt</FONT></SPAN></DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV></DIV>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left><FONT
face=Tahoma size=2>-----Original Message-----<BR><B>From:</B> Emerson, Matt
<BR><B>Sent:</B> Wednesday, March 09, 2005 6:58 PM<BR><B>To:</B>
castor-user@exolab.org<BR><B>Subject:</B> [WARNING: This message originated
from outside of Fidelity] [castor-user] Using Interfaces during
marshalling/unmarshalling<BR><BR></FONT></DIV><!-- Converted from text/rtf format --><BR>
<P><FONT face=Arial size=2>I have created two classes and 1 interface:
Product, SubProduct, and SubProductIF</FONT> <BR><FONT face=Arial size=2>They
are as follows:</FONT> </P>
<P><FONT face=Arial size=2>Public class Product</FONT> </P>
<P> <FONT face=Arial size=2>private
SubProductIF sample</FONT> </P>
<P> <FONT face=Arial size=2>public
Product()</FONT> </P>
<P> <FONT face=Arial size=2>public
void setSample(SubProductIF data) { this sample = data; }</FONT>
<BR> <FONT face=Arial size=2>public
SubProductIF getSample() { return this.sample; }</FONT> <BR><FONT face=Arial
size=2>}</FONT> </P>
<P><FONT face=Arial size=2>Public class SubProduct implements
SubProductIF</FONT> <BR><FONT face=Arial size=2>{</FONT>
<BR> <FONT face=Arial size=2>private
String name;</FONT> <BR> <FONT
face=Arial size=2>private String value;</FONT> </P>
<P> <FONT face=Arial size=2>public
SubProduct() {}</FONT> </P>
<P> <FONT face=Arial size=2>public
void setName(String data) { this.name = data; }</FONT>
<BR> <FONT face=Arial size=2>public
void set Value(String data) { this.value = data; }</FONT> </P>
<P> <FONT face=Arial size=2>public
String getName() { return this.name; }</FONT>
<BR> <FONT face=Arial size=2>public
String getValue() { return this.value; }</FONT> <BR><FONT face=Arial
size=2>}</FONT> </P>
<P><FONT face=Arial size=2>And the interface:</FONT> <BR><FONT face=Arial
size=2>public interface SubProductIF </FONT><BR><FONT face=Arial
size=2>{</FONT> <BR><FONT face=Arial size=2> public void
setName(String pValue);</FONT> <BR><FONT face=Arial size=2>
public String getName();</FONT> <BR><FONT face=Arial size=2>
</FONT><BR><FONT face=Arial size=2> public void
setValue(String pValue);</FONT> <BR><FONT face=Arial size=2>
public String getValue();</FONT> <BR><FONT face=Arial size=2>}</FONT> </P>
<P><FONT face=Arial size=2>The mapping is as follows:</FONT> <BR><FONT
face=Arial size=2><mapping></FONT>
<BR> <FONT face=Arial
size=2><description>Description of the mapping for the Product
Class</description></FONT>
<BR> <FONT face=Arial
size=2><class name="com.fmr.cfit.matt.castor.Product"></FONT>
<BR>
<FONT face=Arial size=2><map-to
xml="WrapperProductClass"></map-to>
</FONT><BR>
<FONT face=Arial size=2><field
name="sample" type="com.fmr.cfit.matt.castor.SubProductIF"></FONT>
<BR>
<FONT face=Arial
size=2><bind-xml name="sample_product" node="element"/></FONT>
<BR>
<FONT face=Arial
size=2></field></FONT> <BR>
<FONT face=Arial size=2></class></FONT>
<BR> <FONT face=Arial
size=2><class name="com.fmr.cfit.matt.castor.SubProduct"></FONT>
<BR>
<FONT face=Arial size=2><map-to
xml="sub_product"></map-to></FONT>
<BR>
<FONT face=Arial size=2><field
name="name" type="java.lang.String"></FONT>
<BR>
<FONT face=Arial
size=2><bind-xml name="name" node="attribute"/></FONT>
<BR>
<FONT face=Arial
size=2></field></FONT> <BR>
<FONT face=Arial size=2><field
name="value" type="java.lang.String"></FONT>
<BR>
<FONT face=Arial
size=2><bind-xml name="value" node="element"/></FONT>
<BR>
<FONT face=Arial
size=2></field></FONT> <BR>
<FONT face=Arial size=2></class></FONT> <BR><FONT face=Arial
size=2></mapping></FONT> </P>
<P><FONT face=Arial size=2>When I marshall the class, everything works
fine. However, when I unmarshall it, it throws an error because it can't
find the constructor for SubProduct. Reading the documentation, it says
to use the xsi:type attribute…but that seems like something that has to be
added to the final marshalled class. Since I want this to be an identity
transformation, if I can't do that automatically, it is not very useful.
Does anyone have any ideas how I could make this into an two-way transform
using interfaces?</FONT></P>
<P><FONT face=Arial size=2>Thanks,</FONT> </P>
<P><FONT face=Arial size=2>Matt</FONT> </P>
<P><FONT face=Arial size=2>The Error:</FONT> </P>
<P><FONT face=Arial size=2>#endElement: class</FONT> <BR><FONT face=Arial
size=2>#endElement: mapping</FONT> <BR><FONT face=Arial
size=2> #startElement: WrapperProductClass</FONT> <BR><FONT face=Arial
size=2> #startElement: sample_product</FONT> </P>
<P><FONT face=Arial size=2> unable to instantiate a new type of:
com.fmr.cfit.matt.castor.SubProductIF org.xml.sax.SAXException: unable to
instantiate a new type of: com.fmr.cfit.matt.castor.SubProductIF</FONT></P>
<P><FONT face=Arial size=2> void
org.exolab.castor.xml.UnmarshalHandler.startElement(java.lang.String,
java.lang.String, org.exolab.castor.xml.AttributeSet)
UnmarshalHandler.java:2096</FONT></P>
<P><FONT face=Arial size=2> void
org.exolab.castor.xml.UnmarshalHandler.startElement(java.lang.String,
java.lang.String, java.lang.String, org.xml.sax.Attributes)
UnmarshalHandler.java:1292</FONT></P>
<P><FONT face=Arial size=2> void
org.apache.xerces.parsers.SAXParser.startElement(org.apache.xerces.utils.QName,
org.apache.xerces.framework.XMLAttrList, int)
SAXParser.java:1371</FONT></P>
<P><FONT face=Arial size=2> void
org.apache.xerces.validators.common.XMLValidator.callStartElement(org.apache.xerces.utils.QName)
XMLValidator.java:840</FONT></P>
<P><FONT face=Arial size=2> boolean
org.apache.xerces.framework.XMLDocumentScanner.scanElement(org.apache.xerces.utils.QName)
XMLDocumentScanner.java:1852 boolean
org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(boolean)
XMLDocumentScanner.java:1233 boolean
org.apache.xerces.framework.XMLDocumentScanner.parseSome(boolean)
XMLDocumentScanner.java:380 void
org.apache.xerces.framework.XMLParser.parse(org.xml.sax.InputSource)
</FONT></P>
<P>
<FONT face=Arial
size=2>XMLParser.java:908</FONT> <BR><FONT face=Arial
size=2> java.lang.Object
org.exolab.castor.xml.Unmarshaller.unmarshal(org.xml.sax.InputSource)</FONT>
<BR><FONT face=Arial size=2>
Unmarshaller.java:605</FONT>
<BR><FONT face=Arial size=2>
java.lang.Object
org.exolab.castor.xml.Unmarshaller.unmarshal(java.io.Reader)</FONT> <BR><FONT
face=Arial size=2>
Unmarshaller.java:513 void
com.fmr.cfit.matt.castor.TestCastor.runTest2()</FONT> <BR><FONT face=Arial
size=2>
TestCastor.java:76
void
com.fmr.cfit.matt.castor.TestCastor.main(ja</FONT>
</P></BLOCKQUOTE></BODY></HTML>
["footer" (footer)]
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
minimalist@exolab.org with a subject of:
unsubscribe castor-user
--MML_1110580969_29861@2522.exolab.org--
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic