Java Reference
In-Depth Information
Listing 7-18. Configuring the CustomerFileLineTokenizer
<beans:bean id="customerFile"
class="org.springframework.core.io.FileSystemResyource" scope="step">
<beans:constructor-arg value="#{jobParameters[customerFile]}"/>
</beans:bean>
<beans:bean id="customerFileReader"
class="org.springframework.batch.item.file.FlatFileItemReader">
<beans:property name="resource" ref="customerFile" />
<beans:property name="lineMapper">
<beans:bean
class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<beans:property name="lineTokenizer">
<beans:bean class="com.apress.springbatch.chapter7.CustomerFileLineTokenizer">
<beans:property name="names"
value="firstName,middleInitial,lastName,address,city,state,zip"/>
<beans:property name="delimiter" value=","/>
</beans:bean>
</beans:property>
<beans:property name="fieldSetMapper">
<beans:bean class="org.springframework.batch.item.file.mapping.
BeanWrapperFieldSetMapper">
<beans:property name="prototypeBeanName" value="customer"/>
</beans:bean>
</beans:property>
</beans:bean>
</beans:property>
</beans:bean>
<beans:bean id="customer" class="com.apress.springbatch.chapter7.Customer"
scope="prototype"/>
The sky's the limit with what you can do with your own LineTokenizer and FieldSetMapper. Other
uses for custom LineTokenizers could include:
Parsing legacy file encodings like EBCDIC.
Parsing third party file formats like Microsoft's Excel Worksheets.
• Handling special type conversion requirements.
However, not all files are as simple as the customer one you have been working with. What if your
file contains multiple record formats? The next section will discuss how Spring Batch can choose the
appropriate LineTokenizer to parse each record it comes across.
 
Search WWH ::




Custom Search