diff --git a/execution/src/main/java/org/springframework/batch/execution/tasklet/support/CompositeItemProcessor.java b/execution/src/main/java/org/springframework/batch/execution/tasklet/support/CompositeItemProcessor.java deleted file mode 100644 index 7a8c70291..000000000 --- a/execution/src/main/java/org/springframework/batch/execution/tasklet/support/CompositeItemProcessor.java +++ /dev/null @@ -1,143 +0,0 @@ -package org.springframework.batch.execution.tasklet.support; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import org.springframework.batch.item.ItemProcessor; -import org.springframework.batch.restart.GenericRestartData; -import org.springframework.batch.restart.RestartData; -import org.springframework.batch.restart.Restartable; -import org.springframework.batch.statistics.StatisticsProvider; - -/** - * Runs a collection of ItemProcessors in fixed-order sequence. - * - * @author Robert Kasanicky - */ -public class CompositeItemProcessor implements ItemProcessor, Restartable, StatisticsProvider { - - private static final String SEPARATOR = "#"; - - private List itemProcessors; - - /** - * Calls injected ItemProcessors in order. - */ - public void process(Object data) throws Exception { - for (Iterator iterator = itemProcessors.listIterator(); iterator.hasNext();) { - ((ItemProcessor) iterator.next()).process(data); - } - } - - /** - * Compound restart data of all injected (Restartable) ItemProcessors, property keys are - * prefixed with list index of the ItemProcessor. - */ - public RestartData getRestartData() { - Properties props = createCompoundProperties(new PropertiesExtractor() { - public Properties extractProperties(Object o) { - if (o instanceof Restartable) { - return ((Restartable)o).getRestartData().getProperties(); - } else { - return null; - } - } - }); - return new GenericRestartData(props); - } - - /** - * @param data contains values of restart data, property keys are expected to be prefixed with - * list index of the ItemProcessor. - */ - public void restoreFrom(RestartData data) { - if (data == null || data.getProperties() == null) { - // do nothing - return; - } - - List restartDataList = parseProperties(data.getProperties()); - - // iterators would make the loop below less readable - for (int i=0; i < itemProcessors.size(); i++) { - if (itemProcessors.get(i) instanceof Restartable) { - ((Restartable) itemProcessors.get(i)).restoreFrom((RestartData) restartDataList.get(i)); - } - } - - } - - /** - * @return Properties containing statistics of all injected ItemProcessors, - * property keys are prefixed with the list index of the ItemProcessor. - */ - public Properties getStatistics() { - return createCompoundProperties(new PropertiesExtractor() { - public Properties extractProperties(Object o) { - if (o instanceof StatisticsProvider){ - return ((StatisticsProvider) o).getStatistics(); - } else { - return null; - } - } - }); - } - - public void setItemProcessors(List itemProcessors) { - this.itemProcessors = itemProcessors; - } - - /** - * Parses compound properties into a list of RestartData. - */ - private List parseProperties(Properties props) { - List restartDataList = new ArrayList(itemProcessors.size()); - for (int i = 0; i - -

-Specific implementations of support concerns. -

- - diff --git a/execution/src/test/java/org/springframework/batch/execution/tasklet/support/CompositeItemProcessorTests.java b/execution/src/test/java/org/springframework/batch/execution/tasklet/support/CompositeItemProcessorTests.java index 3dcf760c0..7f6fbe3b6 100644 --- a/execution/src/test/java/org/springframework/batch/execution/tasklet/support/CompositeItemProcessorTests.java +++ b/execution/src/test/java/org/springframework/batch/execution/tasklet/support/CompositeItemProcessorTests.java @@ -9,6 +9,7 @@ import junit.framework.TestCase; import org.easymock.MockControl; import org.springframework.batch.item.ItemProcessor; +import org.springframework.batch.item.processor.CompositeItemProcessor; import org.springframework.batch.restart.GenericRestartData; import org.springframework.batch.restart.RestartData; import org.springframework.batch.restart.Restartable; diff --git a/execution/src/test/java/org/springframework/batch/execution/tasklet/support/InputSourceItemProviderTests.java b/execution/src/test/java/org/springframework/batch/execution/tasklet/support/InputSourceItemProviderTests.java deleted file mode 100644 index ae0a75ea5..000000000 --- a/execution/src/test/java/org/springframework/batch/execution/tasklet/support/InputSourceItemProviderTests.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.execution.tasklet.support; - -import java.util.Properties; - -import junit.framework.TestCase; - -import org.springframework.batch.execution.tasklet.support.InputSourceItemProvider; -import org.springframework.batch.io.InputSource; -import org.springframework.batch.io.Skippable; -import org.springframework.batch.restart.GenericRestartData; -import org.springframework.batch.restart.RestartData; -import org.springframework.batch.restart.Restartable; -import org.springframework.batch.statistics.StatisticsProvider; -import org.springframework.batch.support.PropertiesConverter; - -/** - * Unit test for {@link InputSourceItemProvider} - * - * @author Robert Kasanicky - */ -public class InputSourceItemProviderTests extends TestCase { - - // object under test - private InputSourceItemProvider itemProvider = new InputSourceItemProvider(); - - private InputSource source; - - // create input template and inject it to data provider - protected void setUp() throws Exception { - source = new MockInputSource(this); - itemProvider.setInputSource(source); - } - - /** - * Uses input template to provide the domain object. - */ - public void testNext() { - Object result = itemProvider.next(); - assertSame("domain object is provided by the input template", this, result); - } - - /** - * Gets statistics from the input template - */ - public void testGetStatistics() { - Properties props = itemProvider.getStatistics(); - assertEquals("b", props.getProperty("a")); - } - - /** - * Gets restart data from the input template - */ - public void testGetRestartData() { - Properties props = itemProvider.getRestartData().getProperties(); - assertEquals("foo", props.getProperty("value")); - } - - /** - * Forwared restart data to input template - */ - public void testRestoreFrom() { - itemProvider.restoreFrom(new GenericRestartData(PropertiesConverter.stringToProperties("value=bar"))); - assertEquals("bar", itemProvider.next()); - } - - public void testSkip() { - itemProvider.skip(); - assertEquals("after skip", itemProvider.next()); - } - - private class MockInputSource implements InputSource, StatisticsProvider, Restartable, Skippable { - - private Object value; - - public Properties getStatistics() { - return PropertiesConverter.stringToProperties("a=b"); - } - - public RestartData getRestartData() { - return new GenericRestartData(PropertiesConverter.stringToProperties("value=foo")); - } - - public void restoreFrom(RestartData data) { - value = data.getProperties().getProperty("value"); - } - - public MockInputSource(Object value) { - this.value = value; - } - - public Object read() { - return value; - } - - public void close() { - } - - public void open() { - } - - public void skip() { - value = "after skip"; - } - - } - -} diff --git a/execution/src/test/java/org/springframework/batch/execution/tasklet/support/OutputSourceItemProcessorTests.java b/execution/src/test/java/org/springframework/batch/execution/tasklet/support/OutputSourceItemProcessorTests.java index fac54e90c..dd91e63ae 100644 --- a/execution/src/test/java/org/springframework/batch/execution/tasklet/support/OutputSourceItemProcessorTests.java +++ b/execution/src/test/java/org/springframework/batch/execution/tasklet/support/OutputSourceItemProcessorTests.java @@ -21,9 +21,9 @@ import java.util.Properties; import junit.framework.TestCase; -import org.springframework.batch.execution.tasklet.support.OutputSourceItemProcessor; import org.springframework.batch.io.OutputSource; import org.springframework.batch.io.Skippable; +import org.springframework.batch.item.processor.OutputSourceItemProcessor; import org.springframework.batch.restart.GenericRestartData; import org.springframework.batch.restart.RestartData; import org.springframework.batch.restart.Restartable; diff --git a/samples/src/main/resources/jobs/beanWrapperMapperSampleJob.xml b/samples/src/main/resources/jobs/beanWrapperMapperSampleJob.xml index 6d6ae62ca..b393d5bbe 100644 --- a/samples/src/main/resources/jobs/beanWrapperMapperSampleJob.xml +++ b/samples/src/main/resources/jobs/beanWrapperMapperSampleJob.xml @@ -22,7 +22,7 @@ class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet"> + class="org.springframework.batch.item.provider.DefaultFlatFileItemProvider"> @@ -42,7 +42,7 @@ class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet"> + class="org.springframework.batch.item.provider.DefaultFlatFileItemProvider"> diff --git a/samples/src/main/resources/jobs/fixedLengthImportJob.xml b/samples/src/main/resources/jobs/fixedLengthImportJob.xml index 5cee051c7..7f675048b 100644 --- a/samples/src/main/resources/jobs/fixedLengthImportJob.xml +++ b/samples/src/main/resources/jobs/fixedLengthImportJob.xml @@ -22,7 +22,7 @@ class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet"> + class="org.springframework.batch.item.provider.DefaultFlatFileItemProvider"> diff --git a/samples/src/main/resources/jobs/restartSample.xml b/samples/src/main/resources/jobs/restartSample.xml index 369a53b45..7d05ba364 100644 --- a/samples/src/main/resources/jobs/restartSample.xml +++ b/samples/src/main/resources/jobs/restartSample.xml @@ -20,7 +20,7 @@ + class="org.springframework.batch.item.provider.DefaultFlatFileItemProvider"> diff --git a/samples/src/main/resources/jobs/tradeJob.xml b/samples/src/main/resources/jobs/tradeJob.xml index 45aefc25c..4ef3d7d37 100644 --- a/samples/src/main/resources/jobs/tradeJob.xml +++ b/samples/src/main/resources/jobs/tradeJob.xml @@ -24,7 +24,7 @@ + class="org.springframework.batch.item.provider.DefaultFlatFileItemProvider"> @@ -44,7 +44,7 @@ + class="org.springframework.batch.item.provider.InputSourceItemProvider"> @@ -71,7 +71,7 @@ + class="org.springframework.batch.item.provider.InputSourceItemProvider"> diff --git a/samples/src/main/resources/jobs/xmlJob.xml b/samples/src/main/resources/jobs/xmlJob.xml index dad3fd597..e27afcd3d 100644 --- a/samples/src/main/resources/jobs/xmlJob.xml +++ b/samples/src/main/resources/jobs/xmlJob.xml @@ -22,7 +22,7 @@ class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet"> + class="org.springframework.batch.item.provider.InputSourceItemProvider"> @@ -39,7 +39,7 @@ - +