BATCH-1179: Remove ref= attribute from <step/> in favor of parent=

This commit is contained in:
dhgarrette
2009-03-25 21:10:38 +00:00
parent d25a779444
commit 69c8cbc120
34 changed files with 80 additions and 188 deletions

View File

@@ -46,15 +46,15 @@ public abstract class AbstractStepParser {
protected static final String ID_ATTR = "id";
protected static final String PARENT_ATTR = "parent";
private static final String PARENT_ATTR = "parent";
protected static final String TASKLET_ATTR = "tasklet";
private static final String TASKLET_ATTR = "tasklet";
protected static final String TASKLET_ELE = "tasklet";
private static final String TASKLET_ELE = "tasklet";
protected static final String LISTENERS_ELE = "listeners";
private static final String LISTENERS_ELE = "listeners";
protected static final String MERGE_ATTR = "merge";
private static final String MERGE_ATTR = "merge";
private static final String TX_ATTRIBUTES_ELE = "transaction-attributes";

View File

@@ -45,15 +45,15 @@ public class FlowParser extends AbstractSingleBeanDefinitionParser {
private static final String SPLIT_ELE = "split";
public static final String NEXT_ATTR = "next";
private static final String NEXT_ATTR = "next";
public static final String NEXT_ELE = "next";
private static final String NEXT_ELE = "next";
public static final String END_ELE = "end";
private static final String END_ELE = "end";
public static final String FAIL_ELE = "fail";
private static final String FAIL_ELE = "fail";
public static final String STOP_ELE = "stop";
private static final String STOP_ELE = "stop";
private static final String ON_ATTR = "on";

View File

@@ -15,15 +15,7 @@
*/
package org.springframework.batch.core.configuration.xml;
import static org.springframework.batch.core.configuration.xml.FlowParser.END_ELE;
import static org.springframework.batch.core.configuration.xml.FlowParser.FAIL_ELE;
import static org.springframework.batch.core.configuration.xml.FlowParser.NEXT_ATTR;
import static org.springframework.batch.core.configuration.xml.FlowParser.NEXT_ELE;
import static org.springframework.batch.core.configuration.xml.FlowParser.STOP_ELE;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.springframework.batch.core.job.flow.support.state.StepState;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -31,11 +23,7 @@ import org.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* Internal parser for the &lt;step/&gt; elements inside a job. A step element
@@ -52,10 +40,6 @@ import org.w3c.dom.NodeList;
*/
public class InlineStepParser extends AbstractStepParser {
private static final String REF_ATTR = "ref";
private static final String TX_MANAGER_ATTR = "transaction-manager";
/**
* Parse the step and turn it into a list of transitions.
*
@@ -71,55 +55,13 @@ public class InlineStepParser extends AbstractStepParser {
BeanDefinitionBuilder stateBuilder = BeanDefinitionBuilder.genericBeanDefinition(StepState.class);
String stepId = element.getAttribute(ID_ATTR);
String stepRef = element.getAttribute(REF_ATTR);
if (StringUtils.hasText(stepRef)) {
this.checkStepRef(element, parserContext);
BeanDefinitionBuilder stepBuilder = BeanDefinitionBuilder.genericBeanDefinition(DelegatingStep.class);
stepBuilder.addConstructorArgValue(stepId);
stepBuilder.addConstructorArgReference(stepRef);
AbstractBeanDefinition bd = stepBuilder.getBeanDefinition();
bd.setSource(parserContext.extractSource(element));
parserContext.getRegistry().registerBeanDefinition(stepId, bd);
stateBuilder.addConstructorArgReference(stepId);
}
else {
AbstractBeanDefinition bd = parseTasklet(element, parserContext, jobRepositoryRef);
parserContext.registerBeanComponent(new BeanComponentDefinition(bd, stepId));
stateBuilder.addConstructorArgReference(stepId);
}
AbstractBeanDefinition bd = parseTasklet(element, parserContext, jobRepositoryRef);
parserContext.registerBeanComponent(new BeanComponentDefinition(bd, stepId));
stateBuilder.addConstructorArgReference(stepId);
return FlowParser.getNextElements(parserContext, stepId, stateBuilder.getBeanDefinition(), element);
}
private void checkStepRef(Element element, ParserContext parserContext) {
List<String> legalAttributes = Arrays.asList(ID_ATTR, REF_ATTR, NEXT_ATTR, TX_MANAGER_ATTR);
NamedNodeMap allAttributes = element.getAttributes();
for (int i = 0; i < allAttributes.getLength(); i++) {
String attribute = allAttributes.item(i).getNodeName();
if (!legalAttributes.contains(attribute)) {
cantBeCombinedWithRef(attribute, "attribute", element, parserContext);
}
}
List<String> legalElements = Arrays.asList(NEXT_ELE, END_ELE, FAIL_ELE, STOP_ELE);
NodeList allElements = element.getChildNodes();
for (int i = 0; i < allElements.getLength(); i++) {
Node child = allElements.item(i);
if (child instanceof Element) {
String childName = child.getNodeName();
if (!legalElements.contains(childName)) {
cantBeCombinedWithRef(childName, "element", element, parserContext);
}
}
}
}
private void cantBeCombinedWithRef(String itemName, String itemType, Element element, ParserContext parserContext) {
parserContext.getReaderContext().error(
"The '" + itemName + "' " + itemType + " can't be combined with the '" + REF_ATTR + "=\""
+ element.getAttribute(REF_ATTR) + "\"' attribute specification for <" + element.getNodeName()
+ ">", element);
}
}

View File

@@ -69,7 +69,7 @@
</xsd:complexType>
</xsd:element>
<xsd:element name="step">
<xsd:element name="step" type="stepType">
<xsd:annotation>
<xsd:documentation>
Defines a stage in job processing backed by a
@@ -78,16 +78,6 @@
to form a Job flow.
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="stepType">
<xsd:attribute name="id" type="xsd:ID" use="required" />
<xsd:attributeGroup ref="jobRepositoryAttribute" />
<xsd:attributeGroup ref="stepAttributes" />
<xsd:attributeGroup ref="abstractAttribute" />
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="job-listener">
@@ -173,37 +163,17 @@
<xsd:group name="flowGroup">
<xsd:choice>
<xsd:element name="step">
<xsd:element name="step" type="flowStepType">
<xsd:annotation>
<xsd:documentation>
Defines a stage in job processing backed by a
Step. The id attribute must be specified. The
step
requires either a tasklet definition, a
step requires either a tasklet definition, a
tasklet reference, a reference to a step defined
elsewhere, or a reference
to a (possibly
elsewhere, or a reference to a (possibly
abstract) parent step.
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="flowStepType">
<xsd:attribute name="id" type="xsd:ID" use="required" />
<xsd:attribute name="ref" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation>
A reference to a step defined elsewhere.
</xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="ref" />
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attributeGroup ref="stepAttributes" />
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="split">
<xsd:annotation>
@@ -273,6 +243,10 @@
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:group ref="stepElements" />
</xsd:choice>
<xsd:attribute name="id" type="xsd:ID" use="required" />
<xsd:attributeGroup ref="jobRepositoryAttribute" />
<xsd:attributeGroup ref="stepAttributes" />
<xsd:attributeGroup ref="abstractAttribute" />
<xsd:attributeGroup ref="transactionManagerAttribute" />
</xsd:complexType>
@@ -281,6 +255,8 @@
<xsd:group ref="stepElements" />
<xsd:group ref="transitions" />
</xsd:choice>
<xsd:attribute name="id" type="xsd:ID" use="required" />
<xsd:attributeGroup ref="stepAttributes" />
<xsd:attributeGroup ref="transactionManagerAttribute" />
<xsd:attributeGroup ref="nextAttribute" />
</xsd:complexType>

View File

@@ -124,12 +124,6 @@ public class StepParserTests {
new XmlBeanFactory(new ClassPathResource(contextLocation));
}
@Test(expected = BeanDefinitionParsingException.class)
public void testStepParserParentAndRef() throws Exception {
new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/StepParserParentAndRefTests-context.xml");
}
@Test
public void testParentStep() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext(

View File

@@ -7,12 +7,12 @@
<beans:import resource="common-context.xml" />
<job id="job">
<step id="s1" ref="step1">
<step id="s1" parent="step1">
<next on="FAILED" to="s2" />
<next on="*" to="s3" />
</step>
<step id="s2" ref="step2"/>
<step id="s3" ref="step3"/>
<step id="s2" parent="step2"/>
<step id="s3" parent="step3"/>
</job>
</beans:beans>

View File

@@ -13,8 +13,8 @@
<next on="FOO" to="s1"/>
<next on="*" to="s2"/>
</decision>
<step id="s1" ref="step1" />
<step id="s2" ref="step2" />
<step id="s1" parent="step1" />
<step id="s2" parent="step2" />
</job>
</beans:beans>

View File

@@ -9,8 +9,8 @@
<beans:import resource="common-context.xml" />
<job id="job">
<step id="s1" ref="step1" next="fail"/>
<step id="fail" ref="failingStep"/>
<step id="s1" parent="step1" next="fail"/>
<step id="fail" parent="failingStep"/>
</job>
</beans:beans>

View File

@@ -9,8 +9,8 @@
<beans:import resource="common-context.xml" />
<job id="job">
<step id="s1" ref="step1" next="s2"/>
<step id="s2" ref="step2"/>
<step id="s1" parent="step1" next="s2"/>
<step id="s2" parent="step2"/>
</job>
</beans:beans>

View File

@@ -9,7 +9,7 @@
<beans:import resource="common-context.xml" />
<job id="job">
<step id="s1" ref="step1">
<step id="s1" parent="step1">
<end on="COMPLETED"/>
<fail on="COMPLETED"/>
</step>

View File

@@ -9,7 +9,7 @@
<beans:import resource="common-context.xml" />
<job id="job">
<step id="fail" ref="failingStep">
<step id="fail" parent="failingStep">
<end on="*" />
</step>
</job>

View File

@@ -9,8 +9,8 @@
<beans:import resource="common-context.xml" />
<job id="job">
<step id="s1" ref="step1" next="fail"/>
<step id="fail" ref="failingStep">
<step id="s1" parent="step1" next="fail"/>
<step id="fail" parent="failingStep">
<end on="*" exit-code="EARLY TERMINATION"/>
</step>
</job>

View File

@@ -9,7 +9,7 @@
<beans:import resource="common-context.xml" />
<job id="job">
<step id="s1" ref="step1">
<step id="s1" parent="step1">
<fail on="*" />
</step>
</job>

View File

@@ -9,8 +9,8 @@
<beans:import resource="common-context.xml" />
<job id="job">
<step id="s1" ref="step1" next="fail"/>
<step id="fail" ref="failingStep">
<step id="s1" parent="step1" next="fail"/>
<step id="fail" parent="failingStep">
<fail on="FAILED" exit-code="FAILED EARLY TERMINATION"/>
</step>
</job>

View File

@@ -7,7 +7,7 @@
<beans:import resource="common-context.xml" />
<job id="job" incrementer="testIncrementer" job-repository="jobRepository">
<step id="s1" ref="step1"/>
<step id="s1" parent="step1"/>
<listeners>
<listener after-job-method="afterJob" ref="testListener"/>
<listener after-job-method="afterJob" class="org.springframework.batch.core.configuration.xml.TestJobListener"/>

View File

@@ -9,9 +9,9 @@
<beans:import resource="common-context.xml" />
<job id="job">
<step id="s1" ref="step1" next="fail"/>
<step id="fail" ref="failingStep" next="s2"/>
<step id="s2" ref="step2"/>
<step id="s1" parent="step1" next="fail"/>
<step id="fail" parent="failingStep" next="s2"/>
<step id="s2" parent="step2"/>
</job>
</beans:beans>

View File

@@ -7,11 +7,11 @@
<beans:import resource="common-context.xml" />
<job id="job">
<step id="s1" ref="step1" next="s3">
<step id="s1" parent="step1" next="s3">
<next on="COMPLETED WITH SKIPS" to="s2" />
</step>
<step id="s2" ref="step2"/>
<step id="s3" ref="step3"/>
<step id="s2" parent="step2"/>
<step id="s3" parent="step3"/>
</job>
</beans:beans>

View File

@@ -7,7 +7,7 @@
<beans:import resource="common-context.xml" />
<job id="job">
<step id="s1" ref="step1" />
<step id="s1" parent="step1" />
</job>
</beans:beans>

View File

@@ -21,7 +21,7 @@
</beans:bean>
<job id="job" job-repository="thisRepository">
<step id="s1" ref="step1" />
<step id="s1" parent="step1" />
</job>
</beans:beans>

View File

@@ -11,13 +11,13 @@
<job id="job">
<split id="split1" task-executor="taskExecutor">
<flow>
<step id="fail" ref="failingStep">
<step id="fail" parent="failingStep">
<fail on="FAILED"/>
<end on="*"/>
</step>
</flow>
<flow>
<step id="s1" ref="step1"/>
<step id="s1" parent="step1"/>
</flow>
</split>
</job>

View File

@@ -14,18 +14,18 @@
<next on="FAILED" to="s3"/>
<flow>
<step id="s1" ref="step1"/>
<step id="s1" parent="step1"/>
</flow>
<fail on="COMPLETED" />
<flow>
<step id="fail" ref="failingStep"/>
<step id="fail" parent="failingStep"/>
</flow>
</split>
<step id="s3" ref="step3"/>
<step id="s3" parent="step3"/>
</job>

View File

@@ -9,14 +9,14 @@
<job id="job">
<split id="split" next="s4">
<flow>
<step id="s1" ref="step1" next="s2"/>
<step id="s2" ref="step2" />
<step id="s1" parent="step1" next="s2"/>
<step id="s2" parent="step2" />
</flow>
<flow>
<step id="s3" ref="step3" />
<step id="s3" parent="step3" />
</flow>
</split>
<step id="s4" ref="step4" />
<step id="s4" parent="step4" />
</job>
</beans:beans>

View File

@@ -7,7 +7,7 @@
<beans:import resource="common-context.xml" />
<job id="job">
<step id="s1" ref="step2"/>
<step id="s1" parent="step2"/>
</job>
</beans:beans>

View File

@@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/batch" xmlns:beans="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.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<beans:import resource="common-context.xml" />
<job id="job">
<step id="s1" parent="baseStep" ref="step1"/>
</job>
<step id="baseStep" abstract="false">
<listeners>
<listener class="org.springframework.batch.core.listener.StepExecutionListenerSupport"/>
</listeners>
</step>
</beans:beans>

View File

@@ -11,20 +11,20 @@
<tasklet reader="reader" writer="writer" commit-interval="5" />
<transaction-attributes propagation="REQUIRED" isolation="DEFAULT" />
</step>
<step id="s2" ref="standalone2" next="s3" />
<step id="s2" parent="standalone2" next="s3" />
<step id="s3" tasklet="dummyTasklet" parent="baseStep" next="s4">
<transaction-attributes propagation="REQUIRED" isolation="DEFAULT" />
</step>
<step id="s4" ref="standalone4" next="s5" />
<step id="s4" parent="standalone4" next="s5" />
<step id="s5" parent="baseStep" next="s6">
<tasklet reader="reader" writer="writer" commit-interval="5" />
<transaction-attributes propagation="REQUIRED" isolation="DEFAULT" />
</step>
<step id="s6" ref="standalone6" next="s7" />
<step id="s6" parent="standalone6" next="s7" />
<step id="s7" tasklet="dummyTasklet" parent="baseStep" next="s8">
<transaction-attributes propagation="REQUIRED" isolation="DEFAULT" />
</step>
<step id="s8" ref="standalone8" next="s5" />
<step id="s8" parent="standalone8" next="s5" />
</job>
<step id="standalone2" parent="baseStep">

View File

@@ -7,10 +7,10 @@
<beans:import resource="common-context.xml" />
<job id="job">
<step id="s1" ref="step1">
<step id="s1" parent="step1">
<stop on="*" restart="s2"/>
</step>
<step id="s2" ref="step2"/>
<step id="s2" parent="step2"/>
</job>
</beans:beans>

View File

@@ -7,10 +7,10 @@
<beans:import resource="common-context.xml" />
<job id="job">
<step id="fail" ref="failingStep">
<step id="fail" parent="failingStep">
<stop on="FAILED" restart="s2"/>
</step>
<step id="s2" ref="step2"/>
<step id="s2" parent="step2"/>
</job>
</beans:beans>

View File

@@ -9,14 +9,14 @@
<beans:bean id="decider" class="org.springframework.batch.core.configuration.xml.StopJobParserTests$TestDecider"/>
<job id="job">
<step id="s1" ref="step1">
<step id="s1" parent="step1">
<stop on="COMPLETED" restart="decision"/>
</step>
<decision id="decision" decider="decider">
<next on="FOO" to="s2"/>
<end on="*" exit-code="FAILED"/>
</decision>
<step id="s2" ref="step2"/>
<step id="s2" parent="step2"/>
</job>
</beans:beans>

View File

@@ -7,14 +7,12 @@
<beans:import resource="common-context.xml" />
<job id="job">
<step id="s1" ref="taskletStep">
<!-- On restart this step will be re-executed: effect is infinitely re-runnable job -->
<step id="s1" parent="step1" allow-start-if-complete="true">
<!-- On normal step status: stop the job, but restart with the same step. -->
<stop on="COMPLETED" restart="s1"/>
<end on="*"/>
</step>
</job>
<!-- On restart this step will be re-executed: effect is infinitely re-runnable job -->
<step id="taskletStep" parent="step1" allow-start-if-complete="true"/>
</beans:beans>

View File

@@ -7,7 +7,7 @@
<beans:import resource="common-context.xml" />
<job id="job">
<step id="s0" ref="step2" next="fail"/>
<step id="s0" parent="step2" next="fail"/>
<!-- On restart this step will be re-executed: effect is infinitely re-runnable job -->
<step id="fail" parent="failingStep" allow-start-if-complete="true">

View File

@@ -7,10 +7,10 @@
<beans:import resource="common-context.xml" />
<job id="job">
<step id="s1" ref="step1">
<step id="s1" parent="step1">
<next on="*" to="s2" />
</step>
<step id="s2" ref="step2" />
<step id="s2" parent="step2" />
</job>
</beans:beans>

View File

@@ -20,7 +20,7 @@
<tasklet reader="gameFileItemReader" writer="gameWriter"
commit-interval="${job.commit.interval}" />
</step>
<step id="playerSummarization" ref="summarizationStep" />
<step id="playerSummarization" parent="summarizationStep" />
</job>
<step id="summarizationStep">

View File

@@ -9,9 +9,10 @@
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
<batch:job id="partitionJob">
<batch:step id="step" ref="step1:master" />
</batch:job>
<bean id="partitionJob" class="org.springframework.batch.core.job.SimpleJob">
<property name="jobRepository" ref="jobRepository" />
<property name="steps" ref="step1:master"/>
</bean>
<bean name="step1:master" class="org.springframework.batch.core.partition.support.PartitionStep">
<property name="jobRepository" ref="jobRepository" />

View File

@@ -25,7 +25,7 @@
<step id="errorPrint1" tasklet="errorLogTasklet" next="step2"/>
<step id="step2" ref="secondPass" next="skipCheckingDecision"/>
<step id="step2" parent="secondPass" next="skipCheckingDecision"/>
<decision id="skipCheckingDecision" decider="skipCheckingDecider">
<end on="*"/>