OK, newbie question here. I'm trying to write a simple FlatFileItemReader where each input file has a header line, several body lines, and a footer line. I configured a PatternMatchingCompositeLineMapper for the reader, since the header, footer, and body lines begin with a different sequence of characters, and I couldn't find a way for the reader to "skip" the first and last line of the input to process the body of the file. There may be another way to do this, but I haven't found an example of it yet.
Assuming that this is the way to do it, my first question is this: If the step has a reader, processor, and writer like the following:
and the reader is like the following:Code:<batch:job id="job" job-repository="jobRepository"> <batch:step id="step"> <batch:tasklet transaction-manager="transactionManager"> <batch:chunk reader="reader" processor="processor" writer="writer" commit-interval="1"/> </batch:tasklet> </batch:step> </batch:job>
and the mapper is like the following (assuming the first line starts with 000, all body lines start with 001, and the last line starts with 002):Code:<bean id="reader" class="org.springframework.batch.item.file.FlatFileItemReader"> <property name="resource" ... /> <property name="lineMapper" ref="mapper" /> </bean>
and your processor is also a CompositeItemProcessor, like the following:Code:<bean id="mapper" class="org.springframework.batch.item.file.mapping.PatternMatchingCompositeLineMapper"> <property name="tokenizers"> <map> <entry key="000*" value-ref="headerTokenizer" /> <entry key="001*" value-ref="bodyTokenizer" /> <entry key="002*" value-ref="footerTokenizer" /> </map> </property> <property name="fieldSetMappers"> <map> <entry key="000*" value-ref="headerMapper" /> <entry key="001*" value-ref="bodyMapper" /> <entry key="002*" value-ref="footerMapper" /> </map> </property> </bean>
I'm assuming from the above that I have to use a CompositeItemWriter, and the the processors and writers are typed by the bean that each tokenizer and fieldSetMapper returns, in the form of :Code:<bean id="processor" class="org.springframework.batch.item.support.CompositeItemProcessor"> <property name="itemProcessors"> <list> <bean class="com...HeaderProcessor"/> <bean class="com...BodyProcessor"/> <bean class="com...FooterProcessor"/> </list> </property> </bean>
If you're still with me, that would mean that the PatternMatchingCompositeLineMapper.mapLine() method would return different objects in the reader. can you infer from this that the processor and writer (themselves composites) delegate which processor/writer to call based on the type that mapLine() returns?Code:public class HeaderFieldMapper implements FieldSetMapper<InputFileHeader> { @Override public InputFileHeader mapFieldSet(FieldSet fields) { } }
I would really appreciate it if someone could tell me if this approach is sound. This is my first time around with Batch, and the learning curve (and lack of starting up docs) is a bit of a problem.
Thanks!
--
Brian Gardner
Java Architect, Verizon Wireless


Reply With Quote