BATCH-63: added beginning of <chunk-oriented> element and parsing

This commit is contained in:
trisberg
2008-11-06 18:08:20 +00:00
parent 9fc06e577f
commit 8a1eae327c
6 changed files with 217 additions and 92 deletions

View File

@@ -68,21 +68,24 @@ public class StepParser {
@SuppressWarnings("unchecked")
List<Element> taskElements = (List<Element>) DomUtils.getChildElementsByTagName(element, "task");
@SuppressWarnings("unchecked")
List<Element> chunkOrientedElements = (List<Element>) 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);

View File

@@ -20,12 +20,8 @@
<xsd:documentation>
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.
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
@@ -70,23 +66,7 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="transaction-manager" type="xsd:string"
default="transactionManager">
<xsd:annotation>
<xsd:documentation
source="java:org.springframework.transaction.PlatformTransactionManager"><![CDATA[
The bean name of the TransactionManager that is to be used. This attribute
is not required, and only needs to be specified explicitly
if the bean name of the desired TransactionManager is not 'transactionManager'.
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type
type="org.springframework.transaction.PlatformTransactionManager" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attributeGroup ref="transactionManager"/>
<xsd:attribute name="isolation-level-for-create"
type="xsd:string">
<xsd:annotation>
@@ -117,13 +97,9 @@
<xsd:element name="step">
<xsd:annotation>
<xsd:documentation>
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 &lt;next on="*" .../&gt;
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 &lt;next on="*" .../&gt;
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
@@ -191,65 +167,75 @@
<xsd:complexContent>
<xsd:extension base="nextType">
<xsd:sequence>
<xsd:element name="task" minOccurs="0" maxOccurs="1">
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="beans:identifiedType">
<xsd:attribute name="tasklet" type="xsd:string" use="required">
<xsd:annotation>
<xsd:documentation><![CDATA[
The bean name of the tasklet that is to be used for the task.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="job-repository" type="xsd:string"
default="jobRepository">
<xsd:annotation>
<xsd:documentation
source="java:org.springframework.batch.core.repository.JobRepository"><![CDATA[
The bean name of the JobRepository that is to be used. This attribute
is not required, and only needs to be specified explicitly
if the bean name of the desired JobRepository is not 'jobRepository'.
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type
type="org.springframework.batch.core.repository.JobRepository" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="transaction-manager" type="xsd:string"
default="transactionManager">
<xsd:annotation>
<xsd:documentation
source="java:org.springframework.transaction.PlatformTransactionManager"><![CDATA[
The bean name of the TransactionManager that is to be used. This attribute
is not required, and only needs to be specified explicitly
if the bean name of the desired TransactionManager is not 'transactionManager'.
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type
type="org.springframework.transaction.PlatformTransactionManager" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:choice>
<xsd:element name="chunk-oriented" minOccurs="0" maxOccurs="1">
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="processType"/>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="task" minOccurs="0" maxOccurs="1">
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="taskType"/>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
</xsd:choice>
<xsd:group ref="transitions"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="transitionWithNextType">
<xsd:complexType name="stepDefType">
<xsd:complexContent>
<xsd:extension base="nextType">
<xsd:group ref="transitions"/>
<xsd:extension base="beans:identifiedType">
<xsd:attributeGroup ref="jobRepository"/>
<xsd:attributeGroup ref="transactionManager"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="taskType">
<xsd:complexContent>
<xsd:extension base="stepDefType">
<xsd:attribute name="tasklet" type="xsd:string" use="required">
<xsd:annotation>
<xsd:documentation><![CDATA[
The bean name of the tasklet that is to be used for the task.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="processType">
<xsd:complexContent>
<xsd:extension base="stepDefType">
<xsd:attribute name="reader" type="xsd:string" use="required">
<xsd:annotation>
<xsd:documentation><![CDATA[
The bean name of the item reader that is to be used for the process.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="processor" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The bean name of the item processor that is to be used for the process.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="writer" type="xsd:string" use="required">
<xsd:annotation>
<xsd:documentation><![CDATA[
The bean name of the item writer that is to be used for the process.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
@@ -269,6 +255,14 @@
<xsd:group ref="transitions"/>
</xsd:complexType>
<xsd:complexType name="transitionWithNextType">
<xsd:complexContent>
<xsd:extension base="nextType">
<xsd:group ref="transitions"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:group name="transitions">
<xsd:sequence>
<xsd:choice minOccurs="0" maxOccurs="unbounded" >
@@ -350,5 +344,45 @@
</xsd:choice>
</xsd:sequence>
</xsd:group>
<xsd:attributeGroup name="jobRepository">
<xsd:attribute name="job-repository" type="xsd:string"
default="jobRepository">
<xsd:annotation>
<xsd:documentation
source="java:org.springframework.batch.core.repository.JobRepository"><![CDATA[
The bean name of the JobRepository that is to be used. This attribute
is not required, and only needs to be specified explicitly
if the bean name of the desired JobRepository is not 'jobRepository'.
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type
type="org.springframework.batch.core.repository.JobRepository" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
</xsd:attributeGroup>
<xsd:attributeGroup name="transactionManager">
<xsd:attribute name="transaction-manager" type="xsd:string"
default="transactionManager">
<xsd:annotation>
<xsd:documentation
source="java:org.springframework.transaction.PlatformTransactionManager"><![CDATA[
The bean name of the TransactionManager that is to be used. This attribute
is not required, and only needs to be specified explicitly
if the bean name of the desired TransactionManager is not 'transactionManager'.
]]></xsd:documentation>
<xsd:appinfo>
`<tool:annotation kind="ref">
<tool:expected-type
type="org.springframework.transaction.PlatformTransactionManager" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
</xsd:attributeGroup>
</xsd:schema>

View File

@@ -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());
}
}

View File

@@ -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<String> {
List<String> items = null;
{
List<String> l = new ArrayList<String>();
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;
}
}

View File

@@ -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<String> {
public void write(List<? extends String> items) throws Exception {
}
}

View File

@@ -11,11 +11,18 @@
<task tasklet="tasklet"/>
<next on="*" to="step2" />
</step>
<step name="step2">
<step name="step2" next="step3">
<task tasklet="tasklet"/>
</step>
<step name="step3">
<chunk-oriented reader="reader" writer="writer"/>
</step>
</job>
<beans:bean id="tasklet" class="org.springframework.batch.core.configuration.xml.DummyTasklet"/>
<beans:bean id="reader" class="org.springframework.batch.core.configuration.xml.TestReader"/>
<beans:bean id="writer" class="org.springframework.batch.core.configuration.xml.TestWriter"/>
</beans:beans>