Stephen Bash
Mon, 24 Jan 2005 08:11:45 -0800
Everyone-
As motivation, consider the following example:
public class DataContainer
{
private Map data; public Map getData()
{
return data;
} public void setData( Map data )
{
this.data = data;
}
}public class DataToXML
{
public static void main( String[] args )
{
HashMap mapData = new HashMap();
mapData.put( "Boolean1", new Boolean( true ) );
mapData.put( "String1", "Test1" );
mapData.put( "Boolean2", new Boolean( false ) );
mapData.put( "String2", "Test2" ); DataContainer myData = new DataContainer();
myData.setData( mapData ); Mapping myMap = new Mapping();
myMap.loadMapping( "dataContainerMap.xml" );
Marshaller m1 = new Marshaller( new FileWriter( "myData.xml") );
m1.setMapping( myMap );
m1.marshal( myData );
}
}<DataContainer>
<DataMap>
<DataEntry dataKey="Boolean1" boolean="true" />
<DataEntry dataKey="String1" string="Test1" />
<DataEntry dataKey="Boolean2" boolean="false" />
<DataEntry dataKey="String2" string="Test2" />
</DataMap>
</DataContainer>The complete mapping file is below:
<mapping>
<class name="DataContainer">
<map-to xml="DataContainer" />
<field name="data" collection="map">
<bind-xml name="DataEntry">
<class name="org.exolab.castor.mapping.MapItem">
<field name="key" type="string">
<bind-xml name="dataKey" node="attribute"/>
</field>
<field name="value">
<bind-xml auto-naming="deriveByClass" node="attribute" />
</field>
</class>
</bind-xml>
</field>
</class>
</mapping>Stephen