BATCH-63:added id and class attributes to <listener> element

This commit is contained in:
trisberg
2008-11-08 04:14:43 +00:00
parent 7cfafab52b
commit d49cc44abb
4 changed files with 27 additions and 7 deletions

View File

@@ -271,14 +271,30 @@ public class StepParser {
DomUtils.getChildElementsByTagName(listenersElement, "listener");
if (listenerElements != null) {
for (Element listenerElement : listenerElements) {
String id = listenerElement.getAttribute("id");
String listenerRef = listenerElement.getAttribute("ref");
if (StringUtils.hasText(listenerRef)) {
listenerRefs.add(listenerRef);
RuntimeBeanReference bean = new RuntimeBeanReference(listenerRef);
if (bean != null) {
listenerBeans.add(bean);
}
String className = listenerElement.getAttribute("class");
if ((StringUtils.hasText(id) || StringUtils.hasText(className))
&& StringUtils.hasText(listenerRef)) {
throw new BeanCreationException("Both 'id' or 'ref' plus 'class' specified; use 'class' with an optional 'id' or just 'ref' for <" + listenerElement.getTagName() + "> element with" + (StringUtils.hasText(id) ? " id=\"" + id + "\"" : "" ) + (StringUtils.hasText(className) ? " class=\"" + className + "\"" : "") + (StringUtils.hasText(listenerRef) ? " ref=\"" + listenerRef + "\"" : ""));
}
if (StringUtils.hasText(listenerRef)) {
listenerRefs.add(listenerRef);
BeanReference bean = new RuntimeBeanReference(listenerRef);
listenerBeans.add(bean);
}
else if (StringUtils.hasText(className)) {
RootBeanDefinition beanDef = new RootBeanDefinition(className, null, null);
if (!StringUtils.hasText(id)) {
id = parserContext.getReaderContext().generateBeanName(beanDef);
}
parserContext.getRegistry().registerBeanDefinition(id, beanDef);
BeanReference bean = new RuntimeBeanReference(id);
listenerBeans.add(bean);
}
else {
throw new BeanCreationException("Neither 'ref' or 'class' specified for <" + listenerElement.getTagName() + "> element");
}
}
}
ManagedList arguments = new ManagedList();

View File

@@ -225,8 +225,9 @@
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:element name="listener">
<xsd:element name="listener" minOccurs="1" maxOccurs="unbounded">
<xsd:complexType>
<xsd:attribute name="id" type="xsd:ID"/>
<xsd:attribute name="ref" type="xsd:string"/>
<xsd:attribute name="class" type="xsd:string"/>
</xsd:complexType>

View File

@@ -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;
@@ -51,6 +52,7 @@ public class StepWithChunkOrientedJobParserTests {
private TestReader reader;
@Autowired
@Qualifier("listener")
private TestListener listener;
@Autowired

View File

@@ -10,6 +10,7 @@
<step name="step1">
<chunk-oriented reader="reader" processor="processor" writer="writer">
<listeners>
<listener class="org.springframework.batch.core.configuration.xml.TestListener"/>
<listener ref="listener"/>
</listeners>
</chunk-oriented>