resolves INT-582

Includes refactoring of router hierarchy to avoid duplication of channel resolution logic
Subclasses of AbstractChannelNameResolvingMessageRouter can return MessageChannel , MessageChannel[], collection ... in addition to String
MethodInvokingRouter now extends AbstractChannelNameResolvingMessageRouter and is simplified as a result
This commit is contained in:
Jonas Partner
2009-02-22 10:34:43 +00:00
parent 4cb87799b0
commit fca5ae5501
16 changed files with 221 additions and 140 deletions

View File

@@ -34,8 +34,6 @@ import org.w3c.dom.Element;
public class XmlPayloadValidatingRouterParser extends
AbstractConsumerEndpointParser {
private XPathExpressionParser xpathParser = new XPathExpressionParser();
@Override
protected boolean shouldGenerateId() {
return false;

View File

@@ -19,14 +19,13 @@ package org.springframework.integration.xml.router;
import java.util.List;
import java.util.Map;
import org.w3c.dom.DOMException;
import org.w3c.dom.Node;
import org.springframework.integration.core.Message;
import org.springframework.integration.xml.XmlPayloadConverter;
import org.springframework.util.Assert;
import org.springframework.xml.xpath.NodeMapper;
import org.springframework.xml.xpath.XPathExpression;
import org.w3c.dom.DOMException;
import org.w3c.dom.Node;
/**
* A router that evaluates the XPath expression using
@@ -77,10 +76,9 @@ public class XPathMultiChannelRouter extends AbstractXPathRouter {
}
@SuppressWarnings("unchecked")
public String[] determineTargetChannelNames(Message<?> message) {
public List<Object> getChannelIndicatorList(Message<?> message) {
Node node = getConverter().convertToNode(message.getPayload());
List channelNamesList = getXPathExpression().evaluate(node, this.nodeMapper);
return (String[]) channelNamesList.toArray(new String[channelNamesList.size()]);
return getXPathExpression().evaluate(node, this.nodeMapper);
}
@@ -92,4 +90,6 @@ public class XPathMultiChannelRouter extends AbstractXPathRouter {
}
}

View File

@@ -16,15 +16,16 @@
package org.springframework.integration.xml.router;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.w3c.dom.Node;
import org.springframework.integration.core.Message;
import org.springframework.integration.core.MessagingException;
import org.springframework.integration.xml.DefaultXmlPayloadConverter;
import org.springframework.integration.xml.XmlPayloadConverter;
import org.springframework.xml.xpath.XPathExpression;
import org.w3c.dom.Node;
/**
* Router that evaluates the payload using {@link XPathExpression#evaluateAsString(Node)}
@@ -73,14 +74,20 @@ public class XPathSingleChannelRouter extends AbstractXPathRouter {
* @throws MessagingException if the {@link XPathExpression} evaluates to
* an empty string
*/
public String[] determineTargetChannelNames(Message<?> message) {
@Override
protected List<Object> getChannelIndicatorList(Message<?> message) {
List<Object> channels = new ArrayList<Object>();
Node node = getConverter().convertToNode(message.getPayload());
String result = getXPathExpression().evaluateAsString(node);
if (result == null || "".equals(result)) {
return null;
} else {
channels.add(result);
}
return new String[] { result };
return channels;
}
}