Java Reference
In-Depth Information
for (int i = 0; i < fields.length; i++) {
if (i == 4) {
parsedFields.set(i - 1,
parsedFields.get(i - 1) + " " + fields[i]);
} else {
FieldSet fieldSet =
fieldSetFactory.create(parsedFields.toArray(new String [0]),
return fieldSet;
public void setDelimiter(String delimiter) {
this.delimiter = delimiter;
public void setNames(String names) {
this.names = names;
The tokenize method of the CustomerFileLineTokenizer takes each record and splits it based upon
the delimiter that was configured with Spring. You loop through the fields, combining the third and
fourth fields together so that they are a single field. You then create a FieldSet using the
DefaultFieldSetFactory, passing it the one required parameter (an array of values to be your fields) and
one optional parameter (an array of names for the fields). This LineTokenizer names your fields so that
you can use the BeanWrapperFieldSetMapper to do your FieldSet to domain object mapping without
any additional code.
Configuring the CustomerFileLineTokenizer is identical to the configuration for the
DelimitedLineTokenizer with only the class name to change. Listing 7-18 shows the updated
Search WWH ::

Custom Search