Marc DINV Jambert
07/11/2002 12:44
Pour : [EMAIL PROTECTED]
cc :
Objet : xsi-type DISAPPEARED when using collections!
Hello
I am using the following basic schema so as to generate bean classes through
SourceGenerator
-------------------------------
<!-- Description of a place -->
<xsd:complexType name="placeBean">
<xsd:sequence>
<xsd:element name="identifier" type="xsd:string"/>
<xsd:element name="memo" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<!-- Description of a step -->
<xsd:complexType name="stepBean">
<xsd:sequence>
<xsd:element name="fromPlace" type="placeBean"/>
<xsd:element name="toPlace" type="placeBean"/>
<xsd:element name="duration" type="xsd:duration"/>
</xsd:sequence>
</xsd:complexType>
<!-- Description of a traject -->
<xsd:complexType name="trajectBean">
<xsd:sequence>
<xsd:element name="fromPlace" type="placeBean" />
<xsd:element name="toPlace" type="placeBean"/>
</xsd:sequence>
</xsd:complexType>
<!-- Description of an itinerary -->
<xsd:complexType name="itineraryBean">
<xsd:sequence>
<xsd:element name="step" type="stepBean" maxOccurs="unbounded"
minOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
-------------------------------
Then I run the following Test case:
-------------------------------
public void testMarshalling () throws Exception
{
Place fromPlace1 = new Place ("LieuDepart1", "Precisions");
Place toPlace1 = new Place ("LieuArrivee1", "Precisions");
// Duration of 1 hour and 30 minutes.
Duration duration1 = new Duration ("PT1H30M");
Step step1 = new Step (fromPlace1, toPlace1, duration1);
Place fromPlace2 = new Place ("LieuDepart2", "Precisions");
Place toPlace2 = new Place ("LieuArrivee2", "Precisions");
// Duration of 30 minutes.
Duration duration2 = new Duration ("PT30M");
Step step2 = new Step (fromPlace2, toPlace2, duration2);
Itinerary originalItinerary = new Itinerary ();
originalItinerary.addStep (step1);
originalItinerary.addStep (step2);
StringWriter writer = new StringWriter ();
Marshaller.marshal (originalItinerary, writer);
StringReader reader = new StringReader (writer.toString ());
Itinerary unmarshalledItinerary = new Itinerary ();
Unmarshaller unmarshaller = new Unmarshaller (unmarshalledItinerary);
unmarshaller.unmarshal (reader);
Assert.assertEquals (originalItinerary, unmarshalledItinerary);
}
// Place inherits from PlaceBean
// Step inherits from StepBean
// Itinerary inherits from ItineraryBean
-------------------------------
Finally I end up with the following exception :
----------------------------------------
[java] 1) testMarshalling(carsher.test.model.ItineraryTest)
[java] org.xml.sax.SAXException: unable to find FieldDescriptor for 'from-place'
in ClassDescriptor of stepBean
[java] at org.exolab.castor.xml.UnmarshalHandler.startElement(Unknown
Source)
[java] at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown
Source)
[java] at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
[java] at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown
Source)
[java] at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
[java] at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
[java] at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
[java] at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
[java] at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
[java] at org.exolab.castor.xml.Unmarshaller.unmarshal(Unknown Source)
[java] at org.exolab.castor.xml.Unmarshaller.unmarshal(Unknown Source)
[java] at
carsher.test.model.ItineraryTest.testMarshalling(ItineraryTest.java:50)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at carsher.test.AllTests.main(AllTests.java:40)
----------------------------------------
When I look into generated xml data, I notice that xsi:type="java:carsher.model.Step"
is not present in 'step' element (which explains why exception
is thrown)
----------------------------------------
<itinerary valid="true" step-count="2">
<step valid="true">
<from-place valid="true" xsi:type="java:carsher.model.Place"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<memo>Precisions</memo>
<identifier>LieuDepart1</identifier>
</from-place>
<to-place valid="true" xsi:type="java:carsher.model.Place"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<memo>Precisions</memo>
<identifier>LieuArrivee1</identifier>
</to-place>
<duration>PT1H30M</duration>
</step>
<step valid="true">
<from-place valid="true" xsi:type="java:carsher.model.Place"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<memo>Precisions</memo>
<identifier>LieuDepart2</identifier>
</from-place>
<to-place valid="true" xsi:type="java:carsher.model.Place"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<memo>Precisions</memo>
<identifier>LieuArrivee2</identifier>
</to-place>
<duration>PT30M</duration>
</step>
</itinerary>
----------------------------------------
It seems to me that there is a relation with using add method on generated
collections... but I don't know what to do to resolve this!
I am using castor 0.9.4.1 ang I generate my sources with j2 collections type.
Thanks everybody
Marc
----------------
Les donnees et renseignements contenus dans ce message sont personnels, confidentiels
et secrets. Ce message est adresse a l'individu ou l'entite dont les coordonnees
figurent ci-dessus. Si vous n'etes pas le bon destinataire, nous vous demandons de ne
pas lire, copier, utiliser ou divulguer cette communication. Nous vous prions de
notifier cette erreur a l'expediteur et d'effacer immediatement cette communication de
votre systeme.
The information contained in this message is privileged, confidential, and protected
from disclosure. This message is intended for the individual or entity adressed
herein. If you are not the intended recipient, please do not read, copy, use or
disclose this communication to others; also please notify the sender by replying to
this message, and then delete it from your system.
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev