Java Reference
In-Depth Information
<beans:bean id="xmlOutputWriter"
<beans:property name="resource" ref="outputFile" />
<beans:property name="marshaller" ref="customerMarshaller" />
<beans:property name="rootTagName" value="customers" />
<beans:bean id="customerMarshaller"
<beans:property name="aliases">
<beans:entry key="customer"
value="com.apress.springbatch.chapter9.Customer" />
<step id="formatStep">
<chunk reader="customerFileReader" writer="xmlOutputWriter"
<job id="formatJob">
<step id="step1" parent="formatStep"/>
Of the 69 lines of XML that it took to configure the original formatJob as shown in Listing 9-7, the
formatJob in Listing 9-19 has changed only 14 lines (shortening the file overall by one line). The changes
begin with the definition of a new ItemWriter, xmlOutputWriter . This bean is a reference to the
StaxEventItemWriter the section has been talking about and defines three dependencies: the resource to
write to, the Marshaller implementation, and the root tag name for each XML fragment the Marshaller
will generate.
Just below xmlOutputWriter is customerMarshaller . This bean is used to generate an XML fragment
for each item the job processes. Using Spring's org.springframework.oxm.xtream.XStreamMarshaller
class, the only further configuration you're required to provide is a Map of aliases to use for each type the
Marshaller comes across. By default, the Marshaller uses the attribute's name as the tag name, but you
provide an alias for the Customer class because the XStreamMarshaller uses the fully qualified name for
the class by default as the root tag of each fragment ( com.apress.springbatch.chatper8.Customer instead
of just customer).
In order for the job to be able to compile and run, you need to make one more update. The POM file
needs a new dependency to handle the XML processing, a reference to Spring's Object/XML Mapping
(OXM) library. Listing 9-20 shows the update to the POM that is required.
Search WWH ::

Custom Search