Skip to content

Commit 816c4b2

Browse files
author
trisberg
committed
BATCH-63: added <streams> element to <chunk>
1 parent 12c4fb0 commit 816c4b2

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParser.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
*
5050
* @author Dave Syer
5151
* @author Thomas Risberg
52-
*
52+
* @since 2.0
5353
*/
5454
public class StepParser {
5555

@@ -293,7 +293,6 @@ private void handleListenersElement(Element element, RootBeanDefinition bd, Pars
293293
Element listenersElement =
294294
DomUtils.getChildElementByTagName(element, "listeners");
295295
if (listenersElement != null) {
296-
List<String> listenerRefs = new ArrayList<String>();
297296
List<BeanReference> listenerBeans = new ArrayList<BeanReference>();
298297
List<Element> listenerElements =
299298
DomUtils.getChildElementsByTagName(listenersElement, "listener");
@@ -316,7 +315,6 @@ private void handleListenersElement(Element element, RootBeanDefinition bd, Pars
316315
listenerElement.getTagName() + "> element with attributes: " + attributes);
317316
}
318317
if (StringUtils.hasText(listenerRef)) {
319-
listenerRefs.add(listenerRef);
320318
BeanReference bean = new RuntimeBeanReference(listenerRef);
321319
listenerBeans.add(bean);
322320
}
@@ -340,6 +338,32 @@ else if (StringUtils.hasText(className)) {
340338
}
341339
}
342340

341+
@SuppressWarnings("unchecked")
342+
private void handleStreamsElement(Element element, RootBeanDefinition bd, ParserContext parserContext) {
343+
Element streamsElement =
344+
DomUtils.getChildElementByTagName(element, "streams");
345+
if (streamsElement != null) {
346+
List<BeanReference> listenerBeans = new ArrayList<BeanReference>();
347+
List<Element> listenerElements =
348+
DomUtils.getChildElementsByTagName(streamsElement, "listener");
349+
if (listenerElements != null) {
350+
for (Element listenerElement : listenerElements) {
351+
String listenerRef = listenerElement.getAttribute("ref");
352+
if (StringUtils.hasText(listenerRef)) {
353+
BeanReference bean = new RuntimeBeanReference(listenerRef);
354+
listenerBeans.add(bean);
355+
}
356+
else {
357+
throw new BeanCreationException("ref not specified for <" + listenerElement.getTagName() + "> element");
358+
}
359+
}
360+
}
361+
ManagedList arguments = new ManagedList();
362+
arguments.addAll(listenerBeans);
363+
bd.getPropertyValues().addPropertyValue("streams", arguments);
364+
}
365+
}
366+
343367
/**
344368
* @param element
345369
* @param parserContext

spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.0.xsd

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,23 @@
242242
</xsd:sequence>
243243
</xsd:complexType>
244244
</xsd:element>
245+
<xsd:element name="streams" minOccurs="0" maxOccurs="1">
246+
<xsd:annotation>
247+
<xsd:documentation><![CDATA[
248+
List of all streams to be included for the step definition
249+
]]>
250+
</xsd:documentation>
251+
</xsd:annotation>
252+
<xsd:complexType>
253+
<xsd:sequence>
254+
<xsd:element name="stream" minOccurs="1" maxOccurs="unbounded">
255+
<xsd:complexType>
256+
<xsd:attribute name="ref" type="xsd:string"/>
257+
</xsd:complexType>
258+
</xsd:element>
259+
</xsd:sequence>
260+
</xsd:complexType>
261+
</xsd:element>
245262
<xsd:element name="skippable-exception-classes" minOccurs="0" maxOccurs="1">
246263
<xsd:annotation>
247264
<xsd:documentation><![CDATA[

spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepWithChunkJobParserTests-context.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
<listener class="org.springframework.batch.core.configuration.xml.TestListener"/>
1515
<listener ref="listener"/>
1616
</listeners>
17+
<streams>
18+
<stream ref="reader"/>
19+
</streams>
1720
</chunk>
1821
</step>
1922
</job>

0 commit comments

Comments
 (0)