Java Reference
In-Depth Information
A marshalling endpoint requires both the
marshaller
and
unmarshaller
properties to be set. Usually,
you can specify a single marshaller for both properties. For Castor, you declare a
CastorMarshaller
bean
as the marshaller.
<beans ...>
...
<bean id="temperatureEndpoint"
class="com.apress.springenterpriserecipes.weather.Temperature
➥
MarshallingEndpoint">
<property name="marshaller" ref="marshaller" />
<property name="unmarshaller" ref="marshaller" />
<property name="weatherService" ref="weatherService" />
</bean>
<bean id="marshaller"
class="org.springframework.oxm.castor.CastorMarshaller">
<property name="mappingLocation" value="classpath:mapping.xml" />
</bean>
</beans>
Note that Castor requires a mapping configuration file to know how to map objects to and from
XML documents. You can create this file in the classpath root and specify it in the
mappingLocation
property (e.g.,
mapping.xml
). The following Castor mapping file defines the mappings for the
GetTemperaturesRequest
,
GetTemperaturesResponse
, and
TemperatureInfo
classes:
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
<mapping>
<class name="com.apress.springenterpriserecipes.weather.GetTemperaturesRequest">
<map-to xml="GetTemperaturesRequest"
<field name="city" type="string">
<bind-xml name="city" node="element" />
</field>
<field name="dates" collection="arraylist" type="string"
handler="com.apress.springenterpriserecipes.weather.DateFieldHandler">
<bind-xml name="date" node="element" />
</field>
</class>
<class name="com.apress.springenterpriserecipes.weather.
➥
GetTemperaturesResponse">
<map-to xml="GetTemperaturesResponse"
<field name="temperatures" collection="arraylist"
type="com.apress.springenterpriserecipes.weather.TemperatureInfo">
<bind-xml name="TemperatureInfo" node="element" />
</field>
</class>
Search WWH ::
Custom Search