INT-1076 added support for the 'ignore-channel-name-resolution-failures' attribute on <xpath-router/> elements.

This commit is contained in:
Mark Fisher
2010-05-04 14:31:20 +00:00
parent 2da44cf041
commit 85c3263e1e
4 changed files with 59 additions and 36 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,13 +23,15 @@ import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.AbstractConsumerEndpointParser;
import org.springframework.integration.xml.router.XPathMultiChannelRouter;
import org.springframework.integration.xml.router.XPathSingleChannelRouter;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Parser for the &lt;xpath-router/&gt; element.
*
* @author Jonas Partner
* @author Mark Fisher
*/
public class XPathRouterParser extends AbstractConsumerEndpointParser {
@@ -48,29 +50,19 @@ public class XPathRouterParser extends AbstractConsumerEndpointParser {
@Override
protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition();
boolean multiChannel = Boolean.parseBoolean(element.getAttribute("multi-channel"));
String xPathExpressionRef = element.getAttribute("xpath-expression-ref");
String channelResolver = element.getAttribute("channel-resolver");
String resolutionRequired = element.getAttribute("resolution-required");
String defaultOutputChannel = element.getAttribute("default-output-channel");
NodeList xPathExpressionNodes = element.getElementsByTagNameNS(
element.getNamespaceURI(), "xpath-expression");
Assert.isTrue(xPathExpressionNodes.getLength() < 2,
"Only one xpath-expression child can be specified.");
String xPathExpressionRef = element.getAttribute("xpath-expression-ref");
boolean xPathExpressionChildPresent = (xPathExpressionNodes.getLength() == 1);
boolean xPathReferencePresent = StringUtils.hasText(xPathExpressionRef);
Assert.isTrue(xPathExpressionChildPresent ^ xPathReferencePresent,
"Exactly one of 'xpath-expression' or 'xpath-expression-ref' is required.");
if (multiChannel) {
builder.getBeanDefinition().setBeanClass(XPathMultiChannelRouter.class);
}
else {
builder.getBeanDefinition().setBeanClass(XPathSingleChannelRouter.class);
}
boolean multiChannel = Boolean.parseBoolean(element.getAttribute("multi-channel"));
String classname = "org.springframework.integration.xml.router." +
((multiChannel) ? "XPathMultiChannelRouter" : "XPathSingleChannelRouter");
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(classname);
if (xPathExpressionChildPresent) {
BeanDefinition beanDefinition = this.xpathParser.parse(
(Element) xPathExpressionNodes.item(0), parserContext);
@@ -79,19 +71,10 @@ public class XPathRouterParser extends AbstractConsumerEndpointParser {
else {
builder.addConstructorArgReference(xPathExpressionRef);
}
if(StringUtils.hasText(resolutionRequired)){
builder.addPropertyValue("resolutionRequired", Boolean.parseBoolean(resolutionRequired));
}
if(StringUtils.hasText(channelResolver)){
builder.addPropertyReference("channelResolver", channelResolver);
}
if(StringUtils.hasText(defaultOutputChannel)){
builder.addPropertyReference("defaultOutputChannel", defaultOutputChannel);
}
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "resolution-required");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "ignore-channel-name-resolution-failures");
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "channel-resolver");
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "default-output-channel");
return builder;
}

View File

@@ -197,7 +197,20 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="resolution-required" type="xsd:boolean" use="optional"/>
<xsd:attribute name="resolution-required" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Specify whether this router should always be required to return at least one channel or name.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="ignore-channel-name-resolution-failures" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Specify whether a failure to resolve a channel name returned by this router should be ignored.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="default-output-channel" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>