Team,
I have not been able to get the Collections wrapping property set in
castor.properties to work correctly.
I know that the properties are read correctly, cuz the indent and the debug
from the same file produces the desired result.
There seems to be a way to set the property programatically in the
Introspector class. , But how do I tie the introspector to the marshaller
object and the mapping object.
Am I missing something here? I am trying to get my XML output to work the
same way as explained in the API.
WRAP_COLLECTIONS_PROPERTY
public static final java.lang.String WRAP_COLLECTIONS_PROPERTY
The property name for enabling collection wrapping. The property
controls whether or not collections (arrays, vectors, etc) should be wrapped
in a container element. For example:
<foos>
<foo>foo1</foo>
<foo>foo2</foo>
</foos>
instead of the default:
<foos>foo1<foos>
<foos>foo2</foos>
Use this property with a value of true or false in the castor.properties
file org.exolab.castor.xml.introspector.wrapCollections=true -or-
org.exolab.castor.xml.introspector.wrapCollections=false This property is
false by default.
EXPECTED OUTPUT:
<Schedule>
<Voyage voyageID="3121">
<Vessel>
<name>INDAMEX ALABAMA </name>
<code>INAL</code>
</Vessel>
<ArrivalPorts>
<PortStop xsi:type="PortStop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<StopDate>2003-06-12T00:00:00.000-04:00</StopDate>
<Port>
<PortID>NYC</PortID>
<Type>L</Type>
</Port>
</PortStop>
<PortStop xsi:type="PortStop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<StopDate>2003-06-13T00:00:00.000-04:00</StopDate>
<Port>
<PortID>ORF</PortID>
<Type>L</Type>
</Port>
</PortStop>
</ArrivalPorts>
<DeparturePorts>
<PortStop xsi:type="PortStop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<StopDate>2003-06-14T00:00:00.000-04:00</StopDate>
<Port>
<PortID>ORF</PortID>
<Type>D</Type>
</Port>
</PortStop>
<PortStop xsi:type="PortStop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<StopDate>2003-06-16T00:00:00.000-04:00</StopDate>
<Port>
<PortID>CHS</PortID>
<Type>D</Type>
</Port>
</PortStop>
</DeparturePorts>
</Voyage>
</Schedule>
CURRENT OUTPUT:
<Schedule>
<Voyage voyageID="3121">
<Vessel>
<name>INDAMEX ALABAMA </name>
<code>INAL</code>
</Vessel>
<ArrivalPorts xsi:type="PortStop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<StopDate>2003-06-12T00:00:00.000-04:00</StopDate>
<Port>
<PortID>NYC</PortID>
<Type>L</Type>
</Port>
</ArrivalPorts>
<ArrivalPorts xsi:type="PortStop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<StopDate>2003-06-13T00:00:00.000-04:00</StopDate>
<Port>
<PortID>ORF</PortID>
<Type>L</Type>
</Port>
</ArrivalPorts>
<DeparturePorts xsi:type="PortStop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<StopDate>2003-06-14T00:00:00.000-04:00</StopDate>
<Port>
<PortID>ORF</PortID>
<Type>D</Type>
</Port>
</DeparturePorts>
<DeparturePorts xsi:type="PortStop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<StopDate>2003-06-16T00:00:00.000-04:00</StopDate>
<Port>
<PortID>CHS</PortID>
<Type>D</Type>
</Port>
</DeparturePorts>
</Voyage>
</Schedule>
Castor.properties
# Example properties indent the output, require validation
# on input and turn debugging on.
#
#org.exolab.castor.validation=false
org.exolab.castor.indent=true
#org.exolab.castor.debug=true
org.exolab.castor.xml.introspector.wrapCollections=true
MAPPING FILE:
<?xml version="1.0"?>
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Object Mapping DTD Version
1.0//EN"
"http://castor.exolab.org/mapping.dtd">
<mapping>
<class name="com.cpships.vss.schedule.Schedule">
<map-to xml="Schedule"/>
<field name="voyages"
type="com.cpships.vss.domain.Voyage"
collection="arraylist">
<bind-xml name="Voyage" node="element"/>
</field>
<field name="arrivalPorts"
type="com.cpships.vss.domain.Port"
collection="arraylist">
<bind-xml name="AllArrivalPorts" node="element" />
</field>
<field name="departurePorts"
type="com.cpships.vss.domain.Port"
collection="arraylist">
<bind-xml name="AllDeparturePorts" node="element" />
</field>
</class>
<class name="com.cpships.vss.domain.Voyage">
<field name="voyageNumber"
type="java.lang.String">
<bind-xml name="voyageID" node="attribute"/>
</field>
<field name="vessel"
type="com.cpships.vss.domain.Vessel">
<bind-xml name="Vessel" node="element"/>
</field>
<field name="arrivalPorts"
type="com.cpships.vss.domain.Port"
collection="arraylist">
<bind-xml name="ArrivalPorts"/>
</field>
<field name="departPorts"
type="com.cpships.vss.domain.Port"
collection="arraylist">
<bind-xml name="DeparturePorts"/>
</field>
</class>
<class name="com.cpships.vss.domain.Vessel">
<field name="name"
type="java.lang.String">
<bind-xml name="name" node="element"/>
</field>
<field name="description"
type="java.lang.String">
<bind-xml name="description" node="element"/>
</field>
<field name="code"
type="java.lang.String">
<bind-xml name="code" node="element"/>
</field>
</class>
<class name="com.cpships.vss.domain.PortStop">
<map-to xml="PortStop"/>
<field name="stopDate"
type="java.util.Date">
<bind-xml name="StopDate" node="element"/>
</field>
<field name="port"
type="com.cpships.vss.domain.Port">
<bind-xml name="Port" node="element"/>
</field>
</class>
<class name="com.cpships.vss.domain.Port">
<map-to xml="Port"/>
<field name="portID"
type="java.lang.String">
<bind-xml name="PortID" node="element"/>
</field>
<field name="type"
type="java.lang.String">
<bind-xml name="Type" node="element"/>
</field>
<field name="portName"
type="java.lang.String">
<bind-xml name="PortName" node="element"/>
</field>
</class>
</mapping>
Schedule Class:
/* Generated by Together */
package com.cpships.vss.schedule;
import java.util.ArrayList;
import com.cpships.vss.domain.Voyage;
import com.cpships.vss.domain.Port;
import com.cpships.vss.domain.PortStop;
public class Schedule
{
private ArrayList voyages = null;
private ArrayList arrivalPorts = null;
private ArrayList departurePorts = null;
private String direction = null;
public Schedule()
{
voyages = new ArrayList();
}
public void setVoyages( ArrayList voyages )
{
this.voyages = voyages;
}
public ArrayList getVoyages()
{
return this.voyages;
}
public void setArrivalPorts( ArrayList arrivalPorts )
{
this.arrivalPorts = arrivalPorts;
}
public ArrayList getArrivalPorts()
{
return this.arrivalPorts;
}
public void setDeparturePorts( ArrayList departurePorts )
{
this.departurePorts = departurePorts;
}
public ArrayList getDeparturePorts()
{
return this.departurePorts;
}
public void addVoyage( Voyage voyage )
{
if( voyages == null )
voyages = new ArrayList();
voyages.add( voyage );
}
public void setDirection( String direction )
{
this.direction = direction;
}
public String getDirection()
{
return this.direction;
}
}
Thanks,
Sathya
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev