added namespace support for setting resolution required attribute and providing a custom ChannelResolver

SingleChannelRouter also now returns null when the xpath expression evaluates to empty String
INT-360
This commit is contained in:
Jonas Partner
2008-11-13 20:14:56 +00:00
parent 6b468da46d
commit b730a0ddc5
6 changed files with 106 additions and 16 deletions

View File

@@ -52,12 +52,16 @@ public class XPathRouterParser extends AbstractConsumerEndpointParser {
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");
NodeList xPathExpressionNodes = element.getElementsByTagNameNS(
element.getNamespaceURI(), "xpath-expression");
Assert.isTrue(xPathExpressionNodes.getLength() < 2,
"Only one xpath-expression child can be specified.");
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) {
@@ -74,6 +78,16 @@ 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);
}
return builder;
}

View File

@@ -99,6 +99,8 @@
<xsd:attribute name="input-channel" type="xsd:string" use="required"/>
<xsd:attribute name="xpath-expression-ref" type="xsd:string" use="optional"/>
<xsd:attribute name="multi-channel" type="xsd:string" default="false"/>
<xsd:attribute name="channel-resolver" type="xsd:string" use="optional"/>
<xsd:attribute name="resolution-required" type="xsd:boolean" use="optional" />
</xsd:complexType>
</xsd:element>

View File

@@ -76,12 +76,10 @@ public class XPathSingleChannelRouter extends AbstractXPathRouter {
public String[] determineTargetChannelNames(Message<?> message) {
Node node = getConverter().convertToNode(message.getPayload());
String result = getXPathExpression().evaluateAsString(node);
if ("".equals(result)) {
throw new MessagingException(message,"XPath expression must not be empty");
}
if (result == null) {
if (result == null || "".equals(result)) {
return null;
}
return new String[] { result };
}