Java Reference
In-Depth Information
<beans:bean id="customer" class="com.apress.springbatch.chapter7.Customer"
scope="prototype"/>
The DelimitedLineTokenizer allows for two options that you'll find very useful. The first is the ability
to configure the delimiter. A comma is the default value; however, any single character can be used. The
second option is the ability to configure what value will be used as a quote character. When this option is
used, that value will be used instead of “ as the character to indicate quotes. This character will also be
able to escape itself. Listing 7-10 shows an example of how a string is parsed when you use # character as
quote character.
Listing 7-10. Parsing a Delimited File with the Quote Character Configured
Michael,T,Minella,#123,4th Street#,Chicago,IL,60606
Is parsed as
Michael
T
Minella
123,4th Street
Chicago
IL
60606
Although that's all that is required to process delimited files, it's not the only option you have. The
current example maps address numbers and streets to two different fields. However, what if you wanted
to map them together into a single field as represented in the domain object in Listing 7-11?
Listing 7-11. Customer with a Single Street Address Field
package com.apress.springbatch.chapter7;
public class Customer {
private String firstName;
private String middleInitial;
private String lastName;
private String addressNumber;
private String street;
private String city;
private String state;
private String zip;
// Getters & setters go here
}
With the new object format, you will need to update how the FieldSet is mapped to the domain
object. To do this, you will create your own implementation of the
org.springframework.batch.item.file.mapping.FieldSetMapper interface. The FieldSetMapper
interface, as shown in Listing 7-12, consists of a single method, mapFieldSet , that allows you to map the
FieldSet as it is returned from the LineTokenizer to the domain object fields.
 
Search WWH ::




Custom Search