BATCH-1129: small namespace/parser cleanup
This commit is contained in:
@@ -127,7 +127,6 @@ public abstract class AbstractStepParser {
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void setUpBeanDefinition(Element stepElement, AbstractBeanDefinition bd, ParserContext parserContext,
|
||||
String jobRepositoryRef) {
|
||||
checkStepAttributes(stepElement, bd);
|
||||
@@ -141,6 +140,22 @@ public abstract class AbstractStepParser {
|
||||
RuntimeBeanReference transactionManagerBeanRef = new RuntimeBeanReference(transactionManagerRef);
|
||||
bd.getPropertyValues().addPropertyValue("transactionManager", transactionManagerBeanRef);
|
||||
|
||||
handleTransactionAttributesElement(stepElement, bd, parserContext);
|
||||
|
||||
handleListenersElement(stepElement, bd, parserContext);
|
||||
|
||||
handleExceptionElement(stepElement, parserContext, bd, "no-rollback-exception-classes",
|
||||
"noRollbackExceptionClasses");
|
||||
|
||||
bd.setRole(BeanDefinition.ROLE_SUPPORT);
|
||||
|
||||
bd.setSource(parserContext.extractSource(stepElement));
|
||||
|
||||
}
|
||||
|
||||
private void handleTransactionAttributesElement(Element stepElement, AbstractBeanDefinition bd,
|
||||
ParserContext parserContext) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Element> txAttrElements = DomUtils.getChildElementsByTagName(stepElement, TX_ATTRIBUTES_ELE);
|
||||
if (txAttrElements.size() == 1) {
|
||||
Element txAttrElement = txAttrElements.get(0);
|
||||
@@ -159,26 +174,17 @@ public abstract class AbstractStepParser {
|
||||
}
|
||||
else if (txAttrElements.size() > 1) {
|
||||
parserContext.getReaderContext().error(
|
||||
"The '" + TX_ATTRIBUTES_ELE + "' element may not appear more than once in a single <"
|
||||
"The <" + TX_ATTRIBUTES_ELE + "/> element may not appear more than once in a single <"
|
||||
+ stepElement.getNodeName() + "/>.", stepElement);
|
||||
}
|
||||
|
||||
handleListenersElement(stepElement, bd, parserContext);
|
||||
|
||||
handleExceptionElement(stepElement, parserContext, bd, "no-rollback-exception-classes",
|
||||
"noRollbackExceptionClasses");
|
||||
|
||||
bd.setRole(BeanDefinition.ROLE_SUPPORT);
|
||||
|
||||
bd.setSource(parserContext.extractSource(stepElement));
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void handleExceptionElement(Element element, ParserContext parserContext, BeanDefinition bd,
|
||||
public static void handleExceptionElement(Element element, ParserContext parserContext, BeanDefinition bd,
|
||||
String subElementName, String propertyName) {
|
||||
Element child = DomUtils.getChildElementByTagName(element, subElementName);
|
||||
if (child != null) {
|
||||
List<Element> children = DomUtils.getChildElementsByTagName(element, subElementName);
|
||||
if (children.size() == 1) {
|
||||
Element child = children.get(0);
|
||||
String exceptions = DomUtils.getTextValue(child);
|
||||
if (StringUtils.hasLength(exceptions)) {
|
||||
String[] exceptionArray = StringUtils.tokenizeToStringArray(exceptions, ",\n");
|
||||
@@ -190,6 +196,12 @@ public abstract class AbstractStepParser {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (children.size() > 1) {
|
||||
parserContext.getReaderContext().error(
|
||||
"The <" + subElementName + "/> element may not appear more than once in a single <"
|
||||
+ element.getNodeName() + "/>.", element);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void checkStepAttributes(Element stepElement, AbstractBeanDefinition bd) {
|
||||
@@ -228,7 +240,7 @@ public abstract class AbstractStepParser {
|
||||
}
|
||||
else if (listenersElements.size() > 1) {
|
||||
parserContext.getReaderContext().error(
|
||||
"The '" + LISTENERS_ELE + "' element may not appear more than once in a single <"
|
||||
"The <" + LISTENERS_ELE + "/> element may not appear more than once in a single <"
|
||||
+ stepElement.getNodeName() + "/>.", stepElement);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ public class JobParser extends AbstractSingleBeanDefinitionParser {
|
||||
}
|
||||
else if (listenersElements.size() > 1) {
|
||||
parserContext.getReaderContext().error(
|
||||
"The 'listeners' element may not appear more than once in a single <job/>.", element);
|
||||
"The '<listeners/>' element may not appear more than once in a single <job/>.", element);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
*/
|
||||
package org.springframework.batch.core.configuration.xml;
|
||||
|
||||
import java.util.Arrays;
|
||||
import static org.springframework.batch.core.configuration.xml.AbstractStepParser.handleExceptionElement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.MutablePropertyValues;
|
||||
@@ -143,24 +144,6 @@ public class TaskletElementParser {
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void handleExceptionElement(Element element, ParserContext parserContext, BeanDefinition bd,
|
||||
String subElementName, String propertyName) {
|
||||
Element child = DomUtils.getChildElementByTagName(element, subElementName);
|
||||
if (child != null) {
|
||||
String exceptions = DomUtils.getTextValue(child);
|
||||
if (StringUtils.hasLength(exceptions)) {
|
||||
String[] exceptionArray = StringUtils.tokenizeToStringArray(exceptions, ",\n");
|
||||
if (exceptionArray.length > 0) {
|
||||
ManagedList managedList = new ManagedList();
|
||||
managedList.setMergeEnabled(Boolean.valueOf(child.getAttribute(MERGE_ATTR)));
|
||||
managedList.addAll(Arrays.asList(exceptionArray));
|
||||
bd.getPropertyValues().addPropertyValue(propertyName, managedList);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleRetryListenersElement(Element element, BeanDefinition bd, ParserContext parserContext) {
|
||||
Element listenersElement = DomUtils.getChildElementByTagName(element, "retry-listeners");
|
||||
if (listenersElement != null) {
|
||||
|
||||
@@ -289,7 +289,7 @@
|
||||
<xsd:choice>
|
||||
<xsd:element name="tasklet" type="taskletType" />
|
||||
<xsd:element name="transaction-attributes" type="transaction-attributesType" />
|
||||
<xsd:element name="no-rollback-exception-classes" minOccurs="0" maxOccurs="1">
|
||||
<xsd:element name="no-rollback-exception-classes">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
List of exception classes that should not cause rollback if possible. This list
|
||||
@@ -314,8 +314,8 @@
|
||||
<xsd:attribute name="propagation" default="REQUIRED">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation source="java:org.springframework.transaction.annotation.Propagation"><![CDATA[
|
||||
The transaction propagation behavior.
|
||||
]]></xsd:documentation>
|
||||
The transaction propagation behavior.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:string">
|
||||
@@ -332,8 +332,8 @@
|
||||
<xsd:attribute name="isolation" default="DEFAULT" type="isolationType">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation source="java:org.springframework.transaction.annotation.Isolation"><![CDATA[
|
||||
The transaction isolation level.
|
||||
]]></xsd:documentation>
|
||||
The transaction isolation level.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="timeout" type="xsd:integer" default="-1">
|
||||
|
||||
Reference in New Issue
Block a user