org.springframework.batch.item.file.mapping
Class PatternMatchingCompositeLineMapper<T>

java.lang.Object
  extended by org.springframework.batch.item.file.mapping.PatternMatchingCompositeLineMapper<T>
All Implemented Interfaces:
LineMapper<T>, InitializingBean

public class PatternMatchingCompositeLineMapper<T>
extends Object
implements LineMapper<T>, InitializingBean

A LineMapper implementation that stores a mapping of String patterns to delegate LineTokenizers as well as a mapping of String patterns to delegate FieldSetMappers. Each line received will be tokenized and then mapped to a field set.

Both the tokenizing and the mapping work in a similar way. The line will be checked for its matching pattern. If the key matches a pattern in the map of delegates, then the corresponding delegate will be used. Patterns are sorted starting with the most specific, and the first match succeeds.

Since:
2.0
Author:
Dan Garrette, Dave Syer
See Also:
PatternMatchingCompositeLineTokenizer

Constructor Summary
PatternMatchingCompositeLineMapper()
           
 
Method Summary
 void afterPropertiesSet()
           
 T mapLine(String line, int lineNumber)
          Implementations must implement this method to map the provided line to the parameter type T.
 void setFieldSetMappers(Map<String,FieldSetMapper<T>> fieldSetMappers)
           
 void setTokenizers(Map<String,LineTokenizer> tokenizers)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PatternMatchingCompositeLineMapper

public PatternMatchingCompositeLineMapper()
Method Detail

mapLine

public T mapLine(String line,
                 int lineNumber)
          throws Exception
Description copied from interface: LineMapper
Implementations must implement this method to map the provided line to the parameter type T. The line number represents the number of lines into a file the current line resides.

Specified by:
mapLine in interface LineMapper<T>
Parameters:
line - to be mapped
lineNumber - of the current line
Returns:
mapped object of type T
Throws:
Exception - if error occured while parsing.

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
Exception

setTokenizers

public void setTokenizers(Map<String,LineTokenizer> tokenizers)

setFieldSetMappers

public void setFieldSetMappers(Map<String,FieldSetMapper<T>> fieldSetMappers)


Copyright © 2009 SpringSource. All Rights Reserved.