diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParser.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParser.java index 8a1643e1b..1c053e714 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParser.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParser.java @@ -68,21 +68,24 @@ public class StepParser { @SuppressWarnings("unchecked") List taskElements = (List) DomUtils.getChildElementsByTagName(element, "task"); + @SuppressWarnings("unchecked") + List chunkOrientedElements = (List) DomUtils.getChildElementsByTagName(element, "chunk-oriented"); if (taskElements.size() > 0) { - //TaskParser taskParser = new TaskParser(); -// Object task = taskParser.parse(taskElements.get(0), parserContext); Object task = parseTask(taskElements.get(0), parserContext); stateBuilder.addConstructorArgValue(stepRef); stateBuilder.addConstructorArgValue(task); } - else { - if (StringUtils.hasText(stepRef)) { + else if (chunkOrientedElements.size() > 0) { + Object task = parseChunkOriented(chunkOrientedElements.get(0), parserContext); + stateBuilder.addConstructorArgValue(stepRef); + stateBuilder.addConstructorArgValue(task); + } + else if (StringUtils.hasText(stepRef)) { RuntimeBeanReference stateDef = new RuntimeBeanReference(stepRef); stateBuilder.addConstructorArgValue(stateDef); - } - else { - throw new BeanCreationException("Error creating Step for " + element); - } + } + else { + throw new BeanCreationException("Error creating Step for " + element); } return getNextElements(parserContext, stateBuilder.getBeanDefinition(), element); @@ -185,6 +188,43 @@ public class StepParser { } + /** + * @param element + * @param parserContext + * @return the TaskletStep bean + */ + protected RootBeanDefinition parseChunkOriented(Element element, ParserContext parserContext) { + + System.out.println("PARSING PROCESS!!!"); + + RootBeanDefinition bd = new RootBeanDefinition("org.springframework.batch.core.step.item.SimpleStepFactoryBean", null, null); + + String readerBeanId = element.getAttribute("reader"); + if (StringUtils.hasText(readerBeanId)) { + RuntimeBeanReference taskletRef = new RuntimeBeanReference(readerBeanId); + bd.getPropertyValues().addPropertyValue("itemReader", taskletRef); + } + + String writerBeanId = element.getAttribute("writer"); + if (StringUtils.hasText(writerBeanId)) { + RuntimeBeanReference taskletRef = new RuntimeBeanReference(writerBeanId); + bd.getPropertyValues().addPropertyValue("itemWriter", taskletRef); + } + + String jobRepository = element.getAttribute("job-repository"); + RuntimeBeanReference jobRepositoryRef = new RuntimeBeanReference(jobRepository); + bd.getPropertyValues().addPropertyValue("jobRepository", jobRepositoryRef); + + String transactionManager = element.getAttribute("transaction-manager"); + RuntimeBeanReference tx = new RuntimeBeanReference(transactionManager); + bd.getPropertyValues().addPropertyValue("transactionManager", tx); + + bd.setRole(BeanDefinition.ROLE_SUPPORT); + + return bd; + + } + /** * @param element * @param parserContext @@ -199,6 +239,7 @@ public class StepParser { RuntimeBeanReference taskletRef = new RuntimeBeanReference(taskletBeanId); bd.getPropertyValues().addPropertyValue("tasklet", taskletRef); } + String jobRepository = element.getAttribute("job-repository"); RuntimeBeanReference jobRepositoryRef = new RuntimeBeanReference(jobRepository); bd.getPropertyValues().addPropertyValue("jobRepository", jobRepositoryRef); diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.0.xsd b/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.0.xsd index db84db732..3d5bb49c1 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.0.xsd +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.0.xsd @@ -20,12 +20,8 @@ Defines a job composed of a set of steps and transitions between steps. The job will be exposed - in - the enclosing - bean factory as a component of type Job - that can be - launched using a - JobLauncher. + in the enclosing bean factory as a component of type Job + that can be launched using a JobLauncher. @@ -70,23 +66,7 @@ - - - - - - - - - - + @@ -117,13 +97,9 @@ - Defines a stage in job processing backed by a - Step. The name - attribute has to match the id of a - bean definition - for - a Step. The - next attribute is a synonym for <next on="*" .../> + Defines a stage in job processing backed by a Step. The name + attribute has to match the id of a bean definition for a Step. + The next attribute is a synonym for <next on="*" .../> @@ -191,65 +167,75 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -269,6 +255,14 @@ + + + + + + + + @@ -350,5 +344,45 @@ + + + + + + + + + + + + + + + + + + + + ` + + + + + + \ No newline at end of file diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepWithTaskJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepWithTaskJobParserTests.java index 133659667..1bb07f7e4 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepWithTaskJobParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepWithTaskJobParserTests.java @@ -57,6 +57,6 @@ public class StepWithTaskJobParserTests { JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParameters()); job.execute(jobExecution); assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); - assertEquals(2, jobExecution.getStepExecutions().size()); + assertEquals(3, jobExecution.getStepExecutions().size()); } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TestReader.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TestReader.java new file mode 100644 index 000000000..ae27884e3 --- /dev/null +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TestReader.java @@ -0,0 +1,31 @@ +package org.springframework.batch.core.configuration.xml; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.springframework.batch.item.ItemReader; +import org.springframework.batch.item.ParseException; +import org.springframework.batch.item.UnexpectedInputException; + +public class TestReader implements ItemReader { + + List items = null; + + { + List l = new ArrayList(); + l.add("Item *** 1 ***"); + l.add("Item *** 2 ***"); + this.items = Collections.synchronizedList(l); + } + + public String read() throws Exception, UnexpectedInputException, + ParseException { + if (items.size() > 0) { + String item = items.remove(0); + return item; + } + return null; + } + +} diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TestWriter.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TestWriter.java new file mode 100644 index 000000000..c0946f70f --- /dev/null +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TestWriter.java @@ -0,0 +1,12 @@ +package org.springframework.batch.core.configuration.xml; + +import java.util.List; + +import org.springframework.batch.item.ItemWriter; + +public class TestWriter implements ItemWriter { + + public void write(List items) throws Exception { + } + +} diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepWithTaskJobParserTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepWithTaskJobParserTests-context.xml index f4b1ac8cd..2826dd54b 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepWithTaskJobParserTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepWithTaskJobParserTests-context.xml @@ -11,11 +11,18 @@ - + + + + + + + + \ No newline at end of file