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

	<job id="restartSampleJob" restartable="true" xmlns="http://www.springframework.org/schema/batch">
		<step id="step1">
			<tasklet>
				<chunk reader="itemReader" processor="processor" writer="tradeWriter" commit-interval="2">
					<streams>
						<stream ref="fileItemReader" />
					</streams>
				</chunk>
			</tasklet>
		</step>
	</job>

	<!-- INFRASTRUCTURE SETUP -->

	<bean id="processor" class="org.springframework.batch.item.validator.ValidatingItemProcessor">
		<constructor-arg ref="fixedValidator" />
	</bean>

	<bean id="tradeWriter" class="org.springframework.batch.sample.domain.trade.internal.TradeWriter">
		<property name="dao" ref="tradeDao" />
	</bean>

	<bean id="itemReader" class="org.springframework.batch.sample.support.ExceptionThrowingItemReaderProxy">
		<property name="delegate" ref="fileItemReader" />
	</bean>

	<bean id="fileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
		<property name="resource" value="#{jobParameters['input.file']}" />
		<property name="lineMapper">
			<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
				<property name="lineTokenizer" ref="fixedFileTokenizer" />
				<property name="fieldSetMapper" ref="fieldSetMapper" />
			</bean>
		</property>
		<property name="saveState" value="true" />
	</bean>

	<bean id="fixedFileTokenizer" 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="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.domain.trade.internal.JdbcTradeDao">
		<property name="dataSource" ref="dataSource" />
		<property name="incrementer">
			<bean parent="incrementerParent">
				<property name="incrementerName" value="TRADE_SEQ" />
			</bean>

		</property>
	</bean>

	<bean id="fieldSetMapper" class="org.springframework.batch.sample.domain.trade.internal.TradeFieldSetMapper" />

</beans>