BATCH-63: added <listeners> element to <simple-task>
This commit is contained in:
@@ -191,6 +191,37 @@ public class StepParser {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param element
|
||||
* @param parserContext
|
||||
* @return the TaskletStep bean
|
||||
*/
|
||||
protected RootBeanDefinition parseSimpleTask(Element element, ParserContext parserContext) {
|
||||
|
||||
RootBeanDefinition bd = new RootBeanDefinition("org.springframework.batch.core.step.tasklet.TaskletStep", null, null);
|
||||
|
||||
String taskletBeanId = element.getAttribute("tasklet");
|
||||
if (StringUtils.hasText(taskletBeanId)) {
|
||||
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);
|
||||
|
||||
String transactionManager = element.getAttribute("transaction-manager");
|
||||
RuntimeBeanReference tx = new RuntimeBeanReference(transactionManager);
|
||||
bd.getPropertyValues().addPropertyValue("transactionManager", tx);
|
||||
|
||||
handleListenersElement(element, bd, parserContext, "stepExecutionListeners");
|
||||
|
||||
bd.setRole(BeanDefinition.ROLE_SUPPORT);
|
||||
|
||||
return bd;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param element
|
||||
* @param parserContext
|
||||
@@ -301,7 +332,7 @@ public class StepParser {
|
||||
|
||||
handleExceptionElement(element, bd, "fatal-exception-classes", "fatalExceptionClasses", isFaultTolerant);
|
||||
|
||||
handleListenersElement(element, bd, parserContext);
|
||||
handleListenersElement(element, bd, parserContext, "listeners");
|
||||
|
||||
handleRetryListenersElement(element, bd, parserContext);
|
||||
|
||||
@@ -352,7 +383,7 @@ public class StepParser {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void handleListenersElement(Element element, RootBeanDefinition bd, ParserContext parserContext) {
|
||||
private void handleListenersElement(Element element, RootBeanDefinition bd, ParserContext parserContext, String property) {
|
||||
Element listenersElement =
|
||||
DomUtils.getChildElementByTagName(element, "listeners");
|
||||
if (listenersElement != null) {
|
||||
@@ -361,7 +392,7 @@ public class StepParser {
|
||||
listenerBeans);
|
||||
ManagedList arguments = new ManagedList();
|
||||
arguments.addAll(listenerBeans);
|
||||
bd.getPropertyValues().addPropertyValue("listeners", arguments);
|
||||
bd.getPropertyValues().addPropertyValue(property, arguments);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -448,33 +479,4 @@ public class StepParser {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param element
|
||||
* @param parserContext
|
||||
* @return the TaskletStep bean
|
||||
*/
|
||||
protected RootBeanDefinition parseSimpleTask(Element element, ParserContext parserContext) {
|
||||
|
||||
RootBeanDefinition bd = new RootBeanDefinition("org.springframework.batch.core.step.tasklet.TaskletStep", null, null);
|
||||
|
||||
String taskletBeanId = element.getAttribute("tasklet");
|
||||
if (StringUtils.hasText(taskletBeanId)) {
|
||||
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);
|
||||
|
||||
String transactionManager = element.getAttribute("transaction-manager");
|
||||
RuntimeBeanReference tx = new RuntimeBeanReference(transactionManager);
|
||||
bd.getPropertyValues().addPropertyValue("transactionManager", tx);
|
||||
|
||||
bd.setRole(BeanDefinition.ROLE_SUPPORT);
|
||||
|
||||
return bd;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -232,6 +232,21 @@
|
||||
<xsd:complexType name="simpleTaskType">
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="stepDefType">
|
||||
<xsd:sequence>
|
||||
<xsd:element name="listeners" minOccurs="0" maxOccurs="1">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
List of all listeners for the step definition
|
||||
]]>
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="listener" type="listenerType" minOccurs="1" maxOccurs="unbounded"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="tasklet" type="xsd:string" use="required">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -48,8 +49,13 @@ public class StepWithSimpleTaskJobParserTests {
|
||||
private JobRepository jobRepository;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("tasklet")
|
||||
private AbstractTestComponent tasklet;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("listener")
|
||||
private TestListener listener;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MapJobRepositoryFactoryBean.clear();
|
||||
@@ -63,5 +69,6 @@ public class StepWithSimpleTaskJobParserTests {
|
||||
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
|
||||
assertEquals(2, jobExecution.getStepExecutions().size());
|
||||
assertTrue(tasklet.isExecuted());
|
||||
assertTrue(listener.isExecuted());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,11 @@
|
||||
<next on="*" to="step2" />
|
||||
</step>
|
||||
<step name="step2">
|
||||
<simple-task tasklet="tasklet"/>
|
||||
<simple-task tasklet="tasklet">
|
||||
<listeners>
|
||||
<listener id="listener" class="org.springframework.batch.core.configuration.xml.TestListener"/>
|
||||
</listeners>
|
||||
</simple-task>
|
||||
</step>
|
||||
</job>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user