<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:p="http://www.springframework.org/schema/p"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

	<bean id="beanWrapperMapperJob" parent="simpleJob">
		<property name="steps">
			<list>
				<bean id="step1" parent="simpleStep">
					<property name="streams" ref="tradeFileItemReader" />
					<property name="itemReader">
						<bean
							class="org.springframework.batch.item.validator.ValidatingItemReader">
							<property name="itemReader"
								ref="tradeFileItemReader" />
							<property name="validator"
								ref="fixedValidator" />
						</bean>
					</property>
					<property name="itemWriter">
						<bean
							class="org.springframework.batch.sample.item.writer.TradeWriter">
							<property name="dao" ref="tradeDao" />
						</bean>
					</property>
				</bean>
				<bean id="step2" parent="simpleStep">
					<property name="itemReader"
						ref="personFileItemReader" />
					<property name="itemWriter">
						<bean
							class="org.springframework.batch.sample.item.writer.PersonWriter" />
					</property>
				</bean>

			</list>
		</property>
	</bean>

	<!-- INFRASTRUCTURE SETUP -->

	<bean id="tradeFileItemReader"
		class="org.springframework.batch.item.file.FlatFileItemReader">
		<property name="resource" value="classpath:data/beanWrapperMapperSampleJob/input/20070122.teststream.ImportTradeDataStep.txt" />
		<property name="lineTokenizer" ref="tradeTokenizer" />
		<property name="fieldSetMapper" ref="tradeFieldSetMapper" />
	</bean>

	<bean id="personFileItemReader"
		class="org.springframework.batch.item.file.FlatFileItemReader">
		<property name="resource" value="classpath:data/beanWrapperMapperSampleJob/input/20070122.teststream.ImportPersonDataStep.txt" />
		<property name="lineTokenizer" ref="personTokenizer" />
		<property name="fieldSetMapper" ref="personFieldSetMapper" />
		<!--		<property name="validator" ref="fixedValidator" />-->
	</bean>

	<bean id="tradeTokenizer"
		class="org.springframework.batch.item.file.transform.FixedLengthTokenizer">
		<property name="names" value="ISIN,Quantity,price, CUSTOMER" />
		<property name="columns" value="1-12, 13-15, 16-20, 21-29" />
	</bean>

	<bean id="personTokenizer"
		class="org.springframework.batch.item.file.transform.FixedLengthTokenizer">
		<property name="names"
			value="Title, FirstName, LastName, Age, Address.AddrLine1, children[0].name, children[1].name" />
		<property name="columns"
			value="1-5, 6-20, 21-40, 41-45, 46-55, 56-65, 66-75" />
	</bean>

	<bean id="fixedValidator"
		class="org.springframework.batch.item.validator.SpringValidator">
		<property name="validator">
			<bean id="tradeValidator"
				class="org.springmodules.validation.valang.ValangValidator">
				<property name="valang">
					<value>
						<![CDATA[
						{ isin : length(?) < 13 : 'ISIN too long' : 'isin_length' : 12}
					]]>
					</value>
				</property>
			</bean>
		</property>
	</bean>

	<bean id="tradeDao"
		class="org.springframework.batch.sample.dao.JdbcTradeDao">
		<property name="jdbcTemplate" ref="jdbcTemplate" />
		<property name="incrementer">
			<bean parent="incrementerParent">
				<property name="incrementerName" value="TRADE_SEQ" />
			</bean>
		</property>
	</bean>

	<bean id="tradeFieldSetMapper"
		class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper">
		<property name="prototypeBeanName" value="trade" />
	</bean>

	<bean id="personFieldSetMapper"
		class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper">
		<property name="prototypeBeanName" value="person" />
	</bean>

	<bean id="trade"
		class="org.springframework.batch.sample.domain.Trade"
		scope="prototype" />

	<bean id="person"
		class="org.springframework.batch.sample.domain.Person"
		scope="prototype" />

</beans>
