diff --git a/org.springframework.integration.security/src/test/java/org/springframework/integration/security/config/SecuredChannelsParserTests.java b/org.springframework.integration.security/src/test/java/org/springframework/integration/security/config/SecuredChannelsParserTests.java index ee28a85dc0..abb008458d 100644 --- a/org.springframework.integration.security/src/test/java/org/springframework/integration/security/config/SecuredChannelsParserTests.java +++ b/org.springframework.integration.security/src/test/java/org/springframework/integration/security/config/SecuredChannelsParserTests.java @@ -40,10 +40,10 @@ import org.springframework.integration.channel.AbstractPollableChannel; import org.springframework.integration.channel.ChannelInterceptor; import org.springframework.integration.channel.MessageChannel; import org.springframework.integration.message.Message; -import org.springframework.integration.message.selector.MessageSelector; import org.springframework.integration.security.channel.ChannelAccessPolicy; import org.springframework.integration.security.channel.ChannelInvocationDefinitionSource; import org.springframework.integration.security.channel.ChannelSecurityInterceptor; +import org.springframework.integration.selector.MessageSelector; import org.springframework.security.ConfigAttribute; import org.springframework.security.ConfigAttributeDefinition; import org.springframework.test.context.ContextConfiguration; diff --git a/org.springframework.integration.xml/src/main/java/org/springframework/integration/xml/selector/AbstractXPathMessageSelector.java b/org.springframework.integration.xml/src/main/java/org/springframework/integration/xml/selector/AbstractXPathMessageSelector.java index 511cf801c7..fd457b477d 100644 --- a/org.springframework.integration.xml/src/main/java/org/springframework/integration/xml/selector/AbstractXPathMessageSelector.java +++ b/org.springframework.integration.xml/src/main/java/org/springframework/integration/xml/selector/AbstractXPathMessageSelector.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2008 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. @@ -13,82 +13,77 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.xml.selector; import java.util.HashMap; import java.util.Map; -import org.springframework.integration.message.selector.MessageSelector; +import org.springframework.integration.selector.MessageSelector; import org.springframework.integration.xml.DefaultXmlPayloadConverter; import org.springframework.integration.xml.XmlPayloadConverter; import org.springframework.xml.xpath.XPathExpression; import org.springframework.xml.xpath.XPathExpressionFactory; /** - * Base class for XPath {@link MessageSelector} implementations + * Base class for XPath {@link MessageSelector} implementations. + * * @author Jonas Partner - * */ public abstract class AbstractXPathMessageSelector implements MessageSelector { private final XPathExpression xPathExpresion; - + private XmlPayloadConverter converter = new DefaultXmlPayloadConverter(); - + + /** - * * @param xPathExpression simple String expression */ - public AbstractXPathMessageSelector(String xPathExpression){ + public AbstractXPathMessageSelector(String xPathExpression) { this.xPathExpresion = XPathExpressionFactory.createXPathExpression(xPathExpression); } - + /** - * * @param xPathExpression * @param prefix * @param namespace */ - public AbstractXPathMessageSelector(String xPathExpression, String prefix, String namespace){ + public AbstractXPathMessageSelector(String xPathExpression, String prefix, String namespace) { Map namespaces = new HashMap(); namespaces.put(prefix, namespace); - this.xPathExpresion = XPathExpressionFactory.createXPathExpression(xPathExpression,namespaces); + this.xPathExpresion = XPathExpressionFactory.createXPathExpression(xPathExpression, namespaces); } - + /** - * * @param xPathExpression * @param namespaces */ - public AbstractXPathMessageSelector(String xPathExpression, Map namespaces){ - this.xPathExpresion = XPathExpressionFactory.createXPathExpression(xPathExpression,namespaces); + public AbstractXPathMessageSelector(String xPathExpression, Map namespaces) { + this.xPathExpresion = XPathExpressionFactory.createXPathExpression(xPathExpression, namespaces); } - + /** - * * @param xPathExpression */ - public AbstractXPathMessageSelector(XPathExpression xPathExpression){ + public AbstractXPathMessageSelector(XPathExpression xPathExpression) { this.xPathExpresion = xPathExpression; } - - - protected XmlPayloadConverter getConverter() { - return converter; - } - + + /** - * Converter used to convert payloads prior to XPAth testing - * @param converter + * Specify the converter used to convert payloads prior to XPath testing. */ public void setConverter(XmlPayloadConverter converter) { this.converter = converter; } + protected XmlPayloadConverter getConverter() { + return this.converter; + } + protected XPathExpression getXPathExpresion() { return xPathExpresion; } - - } diff --git a/org.springframework.integration.xml/src/main/java/org/springframework/integration/xml/selector/BooleanTestXPathMessageSelector.java b/org.springframework.integration.xml/src/main/java/org/springframework/integration/xml/selector/BooleanTestXPathMessageSelector.java index 1a9abb28ee..0a316a208a 100644 --- a/org.springframework.integration.xml/src/main/java/org/springframework/integration/xml/selector/BooleanTestXPathMessageSelector.java +++ b/org.springframework.integration.xml/src/main/java/org/springframework/integration/xml/selector/BooleanTestXPathMessageSelector.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2008 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. @@ -13,69 +13,77 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.xml.selector; import java.util.Map; -import org.springframework.integration.message.Message; -import org.springframework.integration.message.selector.MessageSelector; -import org.springframework.xml.xpath.XPathExpression; import org.w3c.dom.Document; import org.w3c.dom.Node; +import org.springframework.integration.message.Message; +import org.springframework.integration.selector.MessageSelector; +import org.springframework.xml.xpath.XPathExpression; + /** * Boolean XPath testing {@link MessageSelector}. Requires an XPathExpression - * which can be evaluated using {@link XPathExpression} evaluateAsBoolean. - * Supports payloads of type {@link Document} or {@link String} - * @author Jonas Partner + * which can be evaluated using {@link XPathExpression#evaluateAsBoolean(Node)}. + * Supports payloads of type {@link Document} or {@link String}. * + * @author Jonas Partner */ public class BooleanTestXPathMessageSelector extends AbstractXPathMessageSelector { /** * Create a boolean testing XPath {@link MessageSelector} supporting - * mutliple namespaces - * @param pathExpression + * mutliple namespaces. + * + * @param expression * @param namespaces */ - public BooleanTestXPathMessageSelector(String pathExpression, Map namespaces) { - super(pathExpression, namespaces); + public BooleanTestXPathMessageSelector(String expression, Map namespaces) { + super(expression, namespaces); } /** * Create a boolean testing XPath {@link MessageSelector} supporting a - * single namespace - * @param pathExpression + * single namespace. + * + * @param expression * @param prefix * @param namespace */ - public BooleanTestXPathMessageSelector(String pathExpression, String prefix, String namespace) { - super(pathExpression, prefix, namespace); + public BooleanTestXPathMessageSelector(String expression, String prefix, String namespace) { + super(expression, prefix, namespace); } /** - * Creates a boolean testing XPath {@link MessageSelector} with no namespace - * support - * @param pathExpression + * Create a boolean testing XPath {@link MessageSelector} with no namespace + * support. + * + * @param expression */ - public BooleanTestXPathMessageSelector(String pathExpression) { - super(pathExpression); + public BooleanTestXPathMessageSelector(String expression) { + super(expression); } /** - * Creates a boolean testing XPath {@link MessageSelector} using the - * provided {@link XPathExpression} - * @param pathExpression + * Create a boolean testing XPath {@link MessageSelector} using the + * provided {@link XPathExpression}. + * + * @param expression */ - public BooleanTestXPathMessageSelector(XPathExpression pathExpression) { - super(pathExpression); + public BooleanTestXPathMessageSelector(XPathExpression expression) { + super(expression); } + /** - * return true if the {@link XPathExpression} evaluates to true + * Return true if the {@link XPathExpression} evaluates to true */ public boolean accept(Message message) { Node node = getConverter().convertToNode(message.getPayload()); return getXPathExpresion().evaluateAsBoolean(node); } + } diff --git a/org.springframework.integration.xml/src/main/java/org/springframework/integration/xml/selector/StringValueTestXPathMessageSelector.java b/org.springframework.integration.xml/src/main/java/org/springframework/integration/xml/selector/StringValueTestXPathMessageSelector.java index 44831944aa..0204e9b856 100644 --- a/org.springframework.integration.xml/src/main/java/org/springframework/integration/xml/selector/StringValueTestXPathMessageSelector.java +++ b/org.springframework.integration.xml/src/main/java/org/springframework/integration/xml/selector/StringValueTestXPathMessageSelector.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2008 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. @@ -13,21 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.xml.selector; import java.util.Map; -import org.springframework.integration.message.Message; -import org.springframework.integration.message.selector.MessageSelector; -import org.springframework.xml.xpath.XPathExpression; import org.w3c.dom.Document; import org.w3c.dom.Node; +import org.springframework.integration.message.Message; +import org.springframework.integration.selector.MessageSelector; +import org.springframework.xml.xpath.XPathExpression; + /** - * XPath {@link MessageSelector} which tests for a provided value Supports - * payloads of type {@link Document} or {@link String} - * @author Jonas Partner + * XPath {@link MessageSelector} that tests if a provided value supports + * payloads of type {@link Document} or {@link String}. * + * @author Jonas Partner */ public class StringValueTestXPathMessageSelector extends AbstractXPathMessageSelector { @@ -35,75 +37,79 @@ public class StringValueTestXPathMessageSelector extends AbstractXPathMessageSel private volatile boolean caseSensitive = true; + /** * Create a selector which tests for the given value and supports multiple - * namespaces - * @param pathExpression + * namespaces. + * + * @param expression * @param namespaces * @param valueToTestFor */ - public StringValueTestXPathMessageSelector(String pathExpression, Map namespaces, - String valueToTestFor) { - super(pathExpression, namespaces); + public StringValueTestXPathMessageSelector(String expression, Map namespaces, String valueToTestFor) { + super(expression, namespaces); this.valueToTestFor = valueToTestFor; } /** - * Creates a single namespace Xpath selector - * @param pathExpression + * Creates a single namespace Xpath selector. + * + * @param expression * @param prefix * @param namespace * @param valueToTestFor */ - public StringValueTestXPathMessageSelector(String pathExpression, String prefix, String namespace, - String valueToTestFor) { - super(pathExpression, prefix, namespace); + public StringValueTestXPathMessageSelector(String expression, String prefix, String namespace, String valueToTestFor) { + super(expression, prefix, namespace); this.valueToTestFor = valueToTestFor; } /** - * Creates non namespaced testing selector - * @param pathExpression + * Creates non-namespaced testing selector. + * + * @param expression * @param valueToTestFor */ - public StringValueTestXPathMessageSelector(String pathExpression, String valueToTestFor) { - - super(pathExpression); + public StringValueTestXPathMessageSelector(String expression, String valueToTestFor) { + super(expression); this.valueToTestFor = valueToTestFor; } /** - * Creates selector with provided {@link XPathExpression} - * @param pathExpression + * Creates a selector with the provided {@link XPathExpression}. + * + * @param expression * @param valueToTestFor */ - public StringValueTestXPathMessageSelector(XPathExpression pathExpression, String valueToTestFor) { - super(pathExpression); + public StringValueTestXPathMessageSelector(XPathExpression expression, String valueToTestFor) { + super(expression); this.valueToTestFor = valueToTestFor; } - /** - * Evaluate the payload returning true if the value returned by the - * {@link XPathExpression} is equal to the valueToTestFor - */ - public boolean accept(Message message) { - Node nodeToTest = getConverter().convertToNode(message.getPayload()); - String xPathResult = getXPathExpresion().evaluateAsString(nodeToTest); - if (caseSensitive) { - return valueToTestFor.equals(xPathResult); - } - else { - return valueToTestFor.equalsIgnoreCase(xPathResult); - } - } /** - * should comparison of value returned by {@link XPathExpression} to test - * value be case sensitive + * Specify whether comparison of value returned by {@link XPathExpression} + * to test value should be case sensitive. Default is 'true'. + * * @param caseSensitive */ public void setCaseSensitive(boolean caseSensitive) { this.caseSensitive = caseSensitive; } + /** + * Evaluate the payload and return true if the value returned by the + * {@link XPathExpression} is equal to the valueToTestFor. + */ + public boolean accept(Message message) { + Node nodeToTest = getConverter().convertToNode(message.getPayload()); + String xPathResult = getXPathExpresion().evaluateAsString(nodeToTest); + if (this.caseSensitive) { + return this.valueToTestFor.equals(xPathResult); + } + else { + return this.valueToTestFor.equalsIgnoreCase(xPathResult); + } + } + } diff --git a/org.springframework.integration.xml/src/test/java/org/springframework/integration/xml/config/XPathSelectorParserTests.java b/org.springframework.integration.xml/src/test/java/org/springframework/integration/xml/config/XPathSelectorParserTests.java index a8c64abacb..99e45a6cdc 100644 --- a/org.springframework.integration.xml/src/test/java/org/springframework/integration/xml/config/XPathSelectorParserTests.java +++ b/org.springframework.integration.xml/src/test/java/org/springframework/integration/xml/config/XPathSelectorParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2008 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. @@ -13,17 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.xml.config; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.junit.Test; -import org.springframework.integration.message.GenericMessage; -import org.springframework.integration.message.selector.MessageSelector; -import org.springframework.integration.xml.util.XmlTestUtil; import org.w3c.dom.Document; +import org.springframework.integration.message.GenericMessage; +import org.springframework.integration.selector.MessageSelector; +import org.springframework.integration.xml.util.XmlTestUtil; + +/** + * @author Jonas Partner + */ public class XPathSelectorParserTests { @Test @@ -43,8 +48,7 @@ public class XPathSelectorParserTests { assertTrue(selector.accept(new GenericMessage(XmlTestUtil.getDocumentForString("outputOne")))); assertFalse(selector.accept(new GenericMessage(XmlTestUtil.getDocumentForString("outputOne")))); } - - + @Test public void testStringExpressionWithNestedMap() throws Exception { StringBuffer contextXml = new StringBuffer(""); @@ -57,7 +61,8 @@ public class XPathSelectorParserTests { assertFalse(selector.accept(new GenericMessage(XmlTestUtil.getDocumentForString("outputOne")))); } - + + public MessageSelector getSelector( String testcontextXml) throws Exception{ TestXmlApplicationContext ctx = TestXmlApplicationContextHelper.getTestAppContext(testcontextXml); @@ -65,6 +70,4 @@ public class XPathSelectorParserTests { } - - } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/channel/ChannelPurger.java b/org.springframework.integration/src/main/java/org/springframework/integration/channel/ChannelPurger.java index c3982bd3e2..2724674c94 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/channel/ChannelPurger.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/channel/ChannelPurger.java @@ -20,7 +20,7 @@ import java.util.ArrayList; import java.util.List; import org.springframework.integration.message.Message; -import org.springframework.integration.message.selector.MessageSelector; +import org.springframework.integration.selector.MessageSelector; import org.springframework.util.Assert; /** diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/channel/MessageChannelTemplate.java b/org.springframework.integration/src/main/java/org/springframework/integration/channel/MessageChannelTemplate.java index fe83399f46..73d9dc20f7 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/channel/MessageChannelTemplate.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/channel/MessageChannelTemplate.java @@ -26,7 +26,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.integration.message.Message; import org.springframework.integration.message.MessageBuilder; -import org.springframework.integration.message.selector.MessageSelector; +import org.springframework.integration.selector.MessageSelector; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallback; diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/channel/NullChannel.java b/org.springframework.integration/src/main/java/org/springframework/integration/channel/NullChannel.java index ff4915df3f..f3808737f2 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/channel/NullChannel.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/channel/NullChannel.java @@ -22,7 +22,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.integration.message.Message; -import org.springframework.integration.message.selector.MessageSelector; +import org.springframework.integration.selector.MessageSelector; /** * A channel implementation that essentially behaves like "/dev/null". diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/channel/PollableChannel.java b/org.springframework.integration/src/main/java/org/springframework/integration/channel/PollableChannel.java index bce136d94d..8e1c4b054d 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/channel/PollableChannel.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/channel/PollableChannel.java @@ -19,7 +19,7 @@ package org.springframework.integration.channel; import java.util.List; import org.springframework.integration.message.Message; -import org.springframework.integration.message.selector.MessageSelector; +import org.springframework.integration.selector.MessageSelector; /** * @author Mark Fisher diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/channel/QueueChannel.java b/org.springframework.integration/src/main/java/org/springframework/integration/channel/QueueChannel.java index 3cda730c17..72e592e6be 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/channel/QueueChannel.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/channel/QueueChannel.java @@ -23,7 +23,7 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; import org.springframework.integration.message.Message; -import org.springframework.integration.message.selector.MessageSelector; +import org.springframework.integration.selector.MessageSelector; import org.springframework.util.Assert; /** diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/channel/ThreadLocalChannel.java b/org.springframework.integration/src/main/java/org/springframework/integration/channel/ThreadLocalChannel.java index f8c2657fa6..5c19f354b7 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/channel/ThreadLocalChannel.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/channel/ThreadLocalChannel.java @@ -22,7 +22,7 @@ import java.util.Queue; import java.util.concurrent.LinkedBlockingQueue; import org.springframework.integration.message.Message; -import org.springframework.integration.message.selector.MessageSelector; +import org.springframework.integration.selector.MessageSelector; /** * A channel implementation that stores messages in a thread-bound queue. In diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/channel/interceptor/MessageSelectingInterceptor.java b/org.springframework.integration/src/main/java/org/springframework/integration/channel/interceptor/MessageSelectingInterceptor.java index 84e51bec23..97366fef00 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/channel/interceptor/MessageSelectingInterceptor.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/channel/interceptor/MessageSelectingInterceptor.java @@ -22,7 +22,7 @@ import java.util.List; import org.springframework.integration.channel.MessageChannel; import org.springframework.integration.message.Message; import org.springframework.integration.message.MessageDeliveryException; -import org.springframework.integration.message.selector.MessageSelector; +import org.springframework.integration.selector.MessageSelector; /** * A {@link org.springframework.integration.channel.ChannelInterceptor} that diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/channel/interceptor/WireTap.java b/org.springframework.integration/src/main/java/org/springframework/integration/channel/interceptor/WireTap.java index 885fe3d5b9..84f08d4e6e 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/channel/interceptor/WireTap.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/channel/interceptor/WireTap.java @@ -24,7 +24,7 @@ import org.springframework.integration.channel.BlockingChannel; import org.springframework.integration.channel.ChannelInterceptor; import org.springframework.integration.channel.MessageChannel; import org.springframework.integration.message.Message; -import org.springframework.integration.message.selector.MessageSelector; +import org.springframework.integration.selector.MessageSelector; import org.springframework.util.Assert; /** diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractChannelParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractChannelParser.java index 2d9d5827ca..cdc5119d36 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractChannelParser.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractChannelParser.java @@ -27,7 +27,7 @@ import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.integration.channel.interceptor.MessageSelectingInterceptor; -import org.springframework.integration.message.selector.PayloadTypeSelector; +import org.springframework.integration.selector.PayloadTypeSelector; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/SelectorChainParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/SelectorChainParser.java index 3447856ddb..43eab36fda 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/SelectorChainParser.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/SelectorChainParser.java @@ -24,7 +24,7 @@ import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.ManagedList; import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; -import org.springframework.integration.message.selector.MessageSelectorChain; +import org.springframework.integration.selector.MessageSelectorChain; /** * Parser for the <selector-chain/> element. diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/AbstractReplyProducingMessageConsumer.java b/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/AbstractReplyProducingMessageConsumer.java index 2a4520feff..6161af68f2 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/AbstractReplyProducingMessageConsumer.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/AbstractReplyProducingMessageConsumer.java @@ -29,7 +29,7 @@ import org.springframework.integration.message.MessageHeaders; import org.springframework.integration.message.MessageProducer; import org.springframework.integration.message.MessageRejectedException; import org.springframework.integration.message.MessagingException; -import org.springframework.integration.message.selector.MessageSelector; +import org.springframework.integration.selector.MessageSelector; import org.springframework.util.Assert; /** diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/filter/MessageFilter.java b/org.springframework.integration/src/main/java/org/springframework/integration/filter/MessageFilter.java index ad911971d8..e46168e53a 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/filter/MessageFilter.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/filter/MessageFilter.java @@ -19,7 +19,7 @@ package org.springframework.integration.filter; import org.springframework.integration.endpoint.AbstractReplyProducingMessageConsumer; import org.springframework.integration.endpoint.ReplyMessageHolder; import org.springframework.integration.message.Message; -import org.springframework.integration.message.selector.MessageSelector; +import org.springframework.integration.selector.MessageSelector; import org.springframework.util.Assert; /** diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/filter/MethodInvokingSelector.java b/org.springframework.integration/src/main/java/org/springframework/integration/filter/MethodInvokingSelector.java index e87ff02518..d523ded1ae 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/filter/MethodInvokingSelector.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/filter/MethodInvokingSelector.java @@ -20,7 +20,7 @@ import java.lang.reflect.Method; import org.springframework.integration.message.Message; import org.springframework.integration.message.MessageMappingMethodInvoker; -import org.springframework.integration.message.selector.MessageSelector; +import org.springframework.integration.selector.MessageSelector; import org.springframework.util.Assert; /** diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/message/selector/MessageSelector.java b/org.springframework.integration/src/main/java/org/springframework/integration/selector/MessageSelector.java similarity index 93% rename from org.springframework.integration/src/main/java/org/springframework/integration/message/selector/MessageSelector.java rename to org.springframework.integration/src/main/java/org/springframework/integration/selector/MessageSelector.java index 88a700ba0d..6808e96ce3 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/message/selector/MessageSelector.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/selector/MessageSelector.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.integration.message.selector; +package org.springframework.integration.selector; import org.springframework.integration.message.Message; diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/message/selector/MessageSelectorChain.java b/org.springframework.integration/src/main/java/org/springframework/integration/selector/MessageSelectorChain.java similarity index 61% rename from org.springframework.integration/src/main/java/org/springframework/integration/message/selector/MessageSelectorChain.java rename to org.springframework.integration/src/main/java/org/springframework/integration/selector/MessageSelectorChain.java index df2957b38a..6282ead2af 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/message/selector/MessageSelectorChain.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/selector/MessageSelectorChain.java @@ -14,12 +14,13 @@ * limitations under the License. */ -package org.springframework.integration.message.selector; +package org.springframework.integration.selector; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import org.springframework.integration.message.Message; +import org.springframework.util.Assert; /** * A message selector implementation that passes incoming messages through a @@ -30,9 +31,19 @@ import org.springframework.integration.message.Message; */ public class MessageSelectorChain implements MessageSelector { + public static enum Strategy { ALL, MORE_THAN_HALF, AT_LEAST_HALF, ANY }; + + + private volatile Strategy strategy = Strategy.ALL; + private final List selectors = new CopyOnWriteArrayList(); + public void setStrategy(Strategy strategy) { + Assert.notNull(strategy, "strategy must not be null"); + this.strategy = strategy; + } + /** * Add a selector to the end of the chain. */ @@ -51,8 +62,11 @@ public class MessageSelectorChain implements MessageSelector { * Initialize the selector chain. Removes any existing selectors. */ public void setSelectors(List selectors) { - this.selectors.clear(); - this.selectors.addAll(selectors); + Assert.notEmpty(selectors, "selectors must not be empty"); + synchronized (this.selectors) { + this.selectors.clear(); + this.selectors.addAll(selectors); + } } /** @@ -61,12 +75,39 @@ public class MessageSelectorChain implements MessageSelector { * If all selectors accept, this method will return 'true'. */ public final boolean accept(Message message) { + int count = 0; + int accepted = 0; for (MessageSelector next : this.selectors) { - if (!next.accept(message)) { + count++; + if (next.accept(message)) { + if (this.strategy.equals(Strategy.ANY)) { + return true; + } + accepted++; + } + else if (this.strategy.equals(Strategy.ALL)) { return false; } } - return true; + return this.decide(accepted, count); + } + + private boolean decide(int accepted, int total) { + if (accepted == 0) { + return false; + } + switch (this.strategy) { + case ANY: + return true; + case ALL: + return (accepted == total); + case MORE_THAN_HALF: + return (2 * accepted) > total; + case AT_LEAST_HALF: + return (2 * accepted) >= total; + default: + throw new IllegalArgumentException("unsupported strategy " + this.strategy); + } } } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/message/selector/PayloadTypeSelector.java b/org.springframework.integration/src/main/java/org/springframework/integration/selector/PayloadTypeSelector.java similarity index 96% rename from org.springframework.integration/src/main/java/org/springframework/integration/message/selector/PayloadTypeSelector.java rename to org.springframework.integration/src/main/java/org/springframework/integration/selector/PayloadTypeSelector.java index 55178fbc45..51bea33099 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/message/selector/PayloadTypeSelector.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/selector/PayloadTypeSelector.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.integration.message.selector; +package org.springframework.integration.selector; import java.util.ArrayList; import java.util.List; diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/message/selector/UnexpiredMessageSelector.java b/org.springframework.integration/src/main/java/org/springframework/integration/selector/UnexpiredMessageSelector.java similarity index 95% rename from org.springframework.integration/src/main/java/org/springframework/integration/message/selector/UnexpiredMessageSelector.java rename to org.springframework.integration/src/main/java/org/springframework/integration/selector/UnexpiredMessageSelector.java index f7404f2bd0..978f8cefd1 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/message/selector/UnexpiredMessageSelector.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/selector/UnexpiredMessageSelector.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.integration.message.selector; +package org.springframework.integration.selector; import org.springframework.integration.message.Message; diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/channel/ChannelPurgerTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/channel/ChannelPurgerTests.java index 38edf5fe84..b9d5855b53 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/channel/ChannelPurgerTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/channel/ChannelPurgerTests.java @@ -26,7 +26,7 @@ import org.junit.Test; import org.springframework.integration.message.Message; import org.springframework.integration.message.StringMessage; -import org.springframework.integration.message.selector.MessageSelector; +import org.springframework.integration.selector.MessageSelector; /** * @author Mark Fisher diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/channel/QueueChannelTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/channel/QueueChannelTests.java index cbb6ac6c5f..4afec61b2a 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/channel/QueueChannelTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/channel/QueueChannelTests.java @@ -34,7 +34,7 @@ import org.springframework.integration.message.GenericMessage; import org.springframework.integration.message.Message; import org.springframework.integration.message.MessageBuilder; import org.springframework.integration.message.StringMessage; -import org.springframework.integration.message.selector.UnexpiredMessageSelector; +import org.springframework.integration.selector.UnexpiredMessageSelector; /** * @author Mark Fisher diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/channel/interceptor/MessageSelectingInterceptorTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/channel/interceptor/MessageSelectingInterceptorTests.java index f52c459250..e098d4381d 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/channel/interceptor/MessageSelectingInterceptorTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/channel/interceptor/MessageSelectingInterceptorTests.java @@ -27,7 +27,7 @@ import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.message.Message; import org.springframework.integration.message.MessageDeliveryException; import org.springframework.integration.message.StringMessage; -import org.springframework.integration.message.selector.MessageSelector; +import org.springframework.integration.selector.MessageSelector; /** * @author Mark Fisher diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/channel/interceptor/WireTapTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/channel/interceptor/WireTapTests.java index bc7a9a222d..c16c5fbc26 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/channel/interceptor/WireTapTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/channel/interceptor/WireTapTests.java @@ -26,7 +26,7 @@ import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.message.Message; import org.springframework.integration.message.MessageBuilder; import org.springframework.integration.message.StringMessage; -import org.springframework.integration.message.selector.MessageSelector; +import org.springframework.integration.selector.MessageSelector; /** * @author Mark Fisher diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/FilterParserTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/config/FilterParserTests.java index cafa13d413..e2b9d424e7 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/config/FilterParserTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/FilterParserTests.java @@ -29,7 +29,7 @@ import org.springframework.integration.channel.MessageChannel; import org.springframework.integration.channel.PollableChannel; import org.springframework.integration.message.Message; import org.springframework.integration.message.StringMessage; -import org.springframework.integration.message.selector.MessageSelector; +import org.springframework.integration.selector.MessageSelector; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.StringUtils; diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/SelectorChainParserTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/config/SelectorChainParserTests.java index 0f812e9df4..ed42b2e96d 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/config/SelectorChainParserTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/SelectorChainParserTests.java @@ -24,8 +24,8 @@ import org.junit.Test; import org.springframework.beans.DirectFieldAccessor; import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.integration.message.selector.MessageSelector; -import org.springframework.integration.message.selector.MessageSelectorChain; +import org.springframework.integration.selector.MessageSelector; +import org.springframework.integration.selector.MessageSelectorChain; /** * @author Mark Fisher diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/StubMessageSelector.java b/org.springframework.integration/src/test/java/org/springframework/integration/config/StubMessageSelector.java index b625949019..9d005858da 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/config/StubMessageSelector.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/StubMessageSelector.java @@ -17,7 +17,7 @@ package org.springframework.integration.config; import org.springframework.integration.message.Message; -import org.springframework.integration.message.selector.MessageSelector; +import org.springframework.integration.selector.MessageSelector; /** * @author Mark Fisher diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/TestSelector.java b/org.springframework.integration/src/test/java/org/springframework/integration/config/TestSelector.java index 82909a5c89..b33c9c610d 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/config/TestSelector.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/TestSelector.java @@ -17,7 +17,7 @@ package org.springframework.integration.config; import org.springframework.integration.message.Message; -import org.springframework.integration.message.selector.MessageSelector; +import org.springframework.integration.selector.MessageSelector; /** * @author Mark Fisher diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/endpointWithSelector.xml b/org.springframework.integration/src/test/java/org/springframework/integration/config/endpointWithSelector.xml index 5bc4bacd19..2b0a3ca82c 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/config/endpointWithSelector.xml +++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/endpointWithSelector.xml @@ -15,7 +15,7 @@ ref="testHandler" selector="typeSelector"> - + diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/dispatcher/SimpleDispatcherTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/dispatcher/SimpleDispatcherTests.java index 2dcf61dd35..1a1e1c7ef4 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/dispatcher/SimpleDispatcherTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/dispatcher/SimpleDispatcherTests.java @@ -34,7 +34,7 @@ import org.springframework.integration.message.MessageDeliveryException; import org.springframework.integration.message.MessageRejectedException; import org.springframework.integration.message.StringMessage; import org.springframework.integration.message.TestHandlers; -import org.springframework.integration.message.selector.MessageSelector; +import org.springframework.integration.selector.MessageSelector; /** * @author Mark Fisher diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/endpoint/ServiceActivatorEndpointTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/endpoint/ServiceActivatorEndpointTests.java index 22a96a20dd..1ae467ba6b 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/endpoint/ServiceActivatorEndpointTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/endpoint/ServiceActivatorEndpointTests.java @@ -37,8 +37,8 @@ import org.springframework.integration.message.MessageRejectedException; import org.springframework.integration.message.MessagingException; import org.springframework.integration.message.StringMessage; import org.springframework.integration.message.TestHandlers; -import org.springframework.integration.message.selector.MessageSelector; -import org.springframework.integration.message.selector.MessageSelectorChain; +import org.springframework.integration.selector.MessageSelector; +import org.springframework.integration.selector.MessageSelectorChain; /** * @author Mark Fisher diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/filter/MessageFilterTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/filter/MessageFilterTests.java index d03a57b061..b1a0e794a0 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/filter/MessageFilterTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/filter/MessageFilterTests.java @@ -29,7 +29,7 @@ import org.springframework.integration.endpoint.SubscribingConsumerEndpoint; import org.springframework.integration.filter.MessageFilter; import org.springframework.integration.message.Message; import org.springframework.integration.message.StringMessage; -import org.springframework.integration.message.selector.MessageSelector; +import org.springframework.integration.selector.MessageSelector; /** * @author Mark Fisher diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/message/selector/PayloadTypeSelectorTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/message/selector/PayloadTypeSelectorTests.java index e5b5474de7..bf5c63e13e 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/message/selector/PayloadTypeSelectorTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/message/selector/PayloadTypeSelectorTests.java @@ -25,6 +25,7 @@ import org.springframework.integration.message.ErrorMessage; import org.springframework.integration.message.GenericMessage; import org.springframework.integration.message.MessagingException; import org.springframework.integration.message.StringMessage; +import org.springframework.integration.selector.PayloadTypeSelector; /** * @author Mark Fisher diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/message/selector/UnexpiredMessageSelectorTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/message/selector/UnexpiredMessageSelectorTests.java index cd295189e3..b699b6801c 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/message/selector/UnexpiredMessageSelectorTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/message/selector/UnexpiredMessageSelectorTests.java @@ -23,6 +23,7 @@ import org.junit.Test; import org.springframework.integration.message.Message; import org.springframework.integration.message.MessageBuilder; +import org.springframework.integration.selector.UnexpiredMessageSelector; /** * @author Mark Fisher diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/selector/MessageSelectorChainTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/selector/MessageSelectorChainTests.java new file mode 100644 index 0000000000..a286e96e30 --- /dev/null +++ b/org.springframework.integration/src/test/java/org/springframework/integration/selector/MessageSelectorChainTests.java @@ -0,0 +1,175 @@ +/* + * Copyright 2002-2008 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.selector; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import org.springframework.integration.message.Message; +import org.springframework.integration.message.StringMessage; + +/** + * @author Mark Fisher + */ +public class MessageSelectorChainTests { + + private final Message message = new StringMessage("test"); + + + @Test + public void anyStrategyAccepts() { + MessageSelectorChain chain = new MessageSelectorChain(); + chain.setStrategy(MessageSelectorChain.Strategy.ANY); + chain.add(new TestSelector(false)); + chain.add(new TestSelector(false)); + chain.add(new TestSelector(true)); + chain.add(new TestSelector(false)); + assertTrue(chain.accept(message)); + } + + @Test + public void anyStrategyRejects() { + MessageSelectorChain chain = new MessageSelectorChain(); + chain.setStrategy(MessageSelectorChain.Strategy.ANY); + chain.add(new TestSelector(false)); + chain.add(new TestSelector(false)); + chain.add(new TestSelector(false)); + chain.add(new TestSelector(false)); + assertFalse(chain.accept(message)); + } + + @Test + public void allStrategyAccepts() { + MessageSelectorChain chain = new MessageSelectorChain(); + chain.setStrategy(MessageSelectorChain.Strategy.ALL); + chain.add(new TestSelector(true)); + chain.add(new TestSelector(true)); + chain.add(new TestSelector(true)); + assertTrue(chain.accept(message)); + } + + @Test + public void allStrategyRejects() { + MessageSelectorChain chain = new MessageSelectorChain(); + chain.setStrategy(MessageSelectorChain.Strategy.ALL); + chain.add(new TestSelector(true)); + chain.add(new TestSelector(false)); + chain.add(new TestSelector(true)); + assertFalse(chain.accept(message)); + } + + @Test + public void atLeastHalfStrategyWithOddNumberAccepts() { + MessageSelectorChain chain = new MessageSelectorChain(); + chain.setStrategy(MessageSelectorChain.Strategy.AT_LEAST_HALF); + chain.add(new TestSelector(true)); + chain.add(new TestSelector(true)); + chain.add(new TestSelector(false)); + assertTrue(chain.accept(message)); + } + + @Test + public void atLeastHalfStrategyWithEvenNumberAccepts() { + MessageSelectorChain chain = new MessageSelectorChain(); + chain.setStrategy(MessageSelectorChain.Strategy.AT_LEAST_HALF); + chain.add(new TestSelector(true)); + chain.add(new TestSelector(true)); + chain.add(new TestSelector(false)); + chain.add(new TestSelector(false)); + assertTrue(chain.accept(message)); + } + + @Test + public void atLeastHalfStrategyWithOddNumberRejects() { + MessageSelectorChain chain = new MessageSelectorChain(); + chain.setStrategy(MessageSelectorChain.Strategy.AT_LEAST_HALF); + chain.add(new TestSelector(false)); + chain.add(new TestSelector(true)); + chain.add(new TestSelector(false)); + assertFalse(chain.accept(message)); + } + + @Test + public void atLeastHalfStrategyWithEvenNumberRejects() { + MessageSelectorChain chain = new MessageSelectorChain(); + chain.setStrategy(MessageSelectorChain.Strategy.AT_LEAST_HALF); + chain.add(new TestSelector(false)); + chain.add(new TestSelector(true)); + chain.add(new TestSelector(false)); + chain.add(new TestSelector(false)); + assertFalse(chain.accept(message)); + } + + @Test + public void moreThanHalfStrategyWithOddNumberAccepts() { + MessageSelectorChain chain = new MessageSelectorChain(); + chain.setStrategy(MessageSelectorChain.Strategy.MORE_THAN_HALF); + chain.add(new TestSelector(true)); + chain.add(new TestSelector(true)); + chain.add(new TestSelector(false)); + assertTrue(chain.accept(message)); + } + + @Test + public void moreThanHalfStrategyWithEvenNumberAccepts() { + MessageSelectorChain chain = new MessageSelectorChain(); + chain.setStrategy(MessageSelectorChain.Strategy.MORE_THAN_HALF); + chain.add(new TestSelector(true)); + chain.add(new TestSelector(true)); + chain.add(new TestSelector(false)); + chain.add(new TestSelector(true)); + assertTrue(chain.accept(message)); + } + + @Test + public void moreThanHalfStrategyWithOddNumberRejects() { + MessageSelectorChain chain = new MessageSelectorChain(); + chain.setStrategy(MessageSelectorChain.Strategy.MORE_THAN_HALF); + chain.add(new TestSelector(false)); + chain.add(new TestSelector(true)); + chain.add(new TestSelector(false)); + assertFalse(chain.accept(message)); + } + + @Test + public void moreThanHalfStrategyWithEvenNumberRejects() { + MessageSelectorChain chain = new MessageSelectorChain(); + chain.setStrategy(MessageSelectorChain.Strategy.MORE_THAN_HALF); + chain.add(new TestSelector(false)); + chain.add(new TestSelector(true)); + chain.add(new TestSelector(true)); + chain.add(new TestSelector(false)); + assertFalse(chain.accept(message)); + } + + + private static class TestSelector implements MessageSelector { + + private final boolean accept; + + private TestSelector(boolean accept) { + this.accept = accept; + } + + public boolean accept(Message message) { + return this.accept; + } + } + +}