Simplified AbstractHandlerEndpointParser and renamed AbstractEndpoint's setMessageSelector to setSelector (for consistency with setSource, setTarget, etc).
This commit is contained in:
@@ -50,8 +50,6 @@ public abstract class AbstractHandlerEndpointParser extends AbstractSingleBeanDe
|
||||
|
||||
protected static final String OUTPUT_CHANNEL_ATTRIBUTE = "output-channel";
|
||||
|
||||
protected static final String OUTPUT_CHANNEL_PROPERTY = "outputChannelName";
|
||||
|
||||
protected static final String RETURN_ADDRESS_OVERRIDES_ATTRIBUTE = "return-address-overrides";
|
||||
|
||||
private static final String PERIOD_ATTRIBUTE = "period";
|
||||
@@ -62,8 +60,6 @@ public abstract class AbstractHandlerEndpointParser extends AbstractSingleBeanDe
|
||||
|
||||
private static final String SELECTOR_ATTRIBUTE = "selector";
|
||||
|
||||
private static final String SELECTOR_PROPERTY = "messageSelector";
|
||||
|
||||
private static final String INTERCEPTORS_ELEMENT = "interceptors";
|
||||
|
||||
|
||||
@@ -100,7 +96,6 @@ public abstract class AbstractHandlerEndpointParser extends AbstractSingleBeanDe
|
||||
else {
|
||||
builder.addConstructorArgReference(ref);
|
||||
}
|
||||
String inputChannelName = element.getAttribute(INPUT_CHANNEL_ATTRIBUTE);
|
||||
Schedule schedule = null;
|
||||
NodeList childNodes = element.getChildNodes();
|
||||
for (int i = 0; i < childNodes.getLength(); i++) {
|
||||
@@ -122,20 +117,14 @@ public abstract class AbstractHandlerEndpointParser extends AbstractSingleBeanDe
|
||||
}
|
||||
}
|
||||
}
|
||||
if (StringUtils.hasText(inputChannelName)) {
|
||||
builder.addPropertyValue("inputChannelName", inputChannelName);
|
||||
}
|
||||
if (schedule != null) {
|
||||
builder.addPropertyValue("schedule", schedule);
|
||||
}
|
||||
String selectorRef = element.getAttribute(SELECTOR_ATTRIBUTE);
|
||||
if (StringUtils.hasText(selectorRef)) {
|
||||
builder.addPropertyReference(SELECTOR_PROPERTY, selectorRef);
|
||||
}
|
||||
String outputChannel = element.getAttribute(OUTPUT_CHANNEL_ATTRIBUTE);
|
||||
if (StringUtils.hasText(outputChannel)) {
|
||||
builder.addPropertyValue(OUTPUT_CHANNEL_PROPERTY, outputChannel);
|
||||
}
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(
|
||||
builder, element, INPUT_CHANNEL_ATTRIBUTE, "inputChannelName");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(
|
||||
builder, element, OUTPUT_CHANNEL_ATTRIBUTE, "outputChannelName");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, SELECTOR_ATTRIBUTE);
|
||||
String returnAddressOverridesAttribute = element.getAttribute(RETURN_ADDRESS_OVERRIDES_ATTRIBUTE);
|
||||
boolean returnAddressOverrides = "true".equals(returnAddressOverridesAttribute);
|
||||
builder.addPropertyValue("returnAddressOverrides", returnAddressOverrides);
|
||||
|
||||
@@ -40,35 +40,76 @@ import org.springframework.util.xml.DomUtils;
|
||||
public abstract class IntegrationNamespaceUtils {
|
||||
|
||||
/**
|
||||
* Populates the bean definition property corresponding to the specified
|
||||
* attributeName with the value of that attribute if it is defined in the
|
||||
* given element. The property name will be the camel-case equivalent of
|
||||
* the lower case hyphen separated attribute (e.g. the "foo-bar" attribute
|
||||
* would match the "fooBar" property).
|
||||
* Populates the specified bean definition property with the value
|
||||
* of the attribute whose name is provided if that attribute is
|
||||
* defined in the given element.
|
||||
*
|
||||
* @param beanDefinition - the bean definition to be configured
|
||||
* @param element - the XML element where the attribute should be defined
|
||||
* @param attributeName - the name of the attribute whose value will be set
|
||||
* on the property
|
||||
*
|
||||
* @see Conventions#attributeNameToPropertyName(String)
|
||||
* @param beanDefinition the bean definition to be configured
|
||||
* @param element the XML element where the attribute should be defined
|
||||
* @param attributeName the name of the attribute whose value will be
|
||||
* used to populate the property
|
||||
* @param propertyName the name of the property to be populated
|
||||
*/
|
||||
public static void setValueIfAttributeDefined(BeanDefinitionBuilder builder,
|
||||
Element element, String attributeName) {
|
||||
Element element, String attributeName, String propertyName) {
|
||||
String attributeValue = element.getAttribute(attributeName);
|
||||
String propertyName = Conventions.attributeNameToPropertyName(attributeName);
|
||||
if (StringUtils.hasText(attributeValue)) {
|
||||
builder.addPropertyValue(propertyName, attributeValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the bean definition property corresponding to the specified
|
||||
* attributeName with the value of that attribute if it is defined in the
|
||||
* given element.
|
||||
*
|
||||
* <p>The property name will be the camel-case equivalent of the lower
|
||||
* case hyphen separated attribute (e.g. the "foo-bar" attribute would
|
||||
* match the "fooBar" property).
|
||||
*
|
||||
* @see Conventions#attributeNameToPropertyName(String)
|
||||
*
|
||||
* @param beanDefinition - the bean definition to be configured
|
||||
* @param element - the XML element where the attribute should be defined
|
||||
* @param attributeName - the name of the attribute whose value will be set
|
||||
* on the property
|
||||
*/
|
||||
public static void setValueIfAttributeDefined(BeanDefinitionBuilder builder,
|
||||
Element element, String attributeName) {
|
||||
setValueIfAttributeDefined(builder, element, attributeName,
|
||||
Conventions.attributeNameToPropertyName(attributeName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the specified bean definition property with the reference
|
||||
* to a bean. The bean reference is identified by the value from the
|
||||
* attribute whose name is provided if that attribute is defined in
|
||||
* the given element.
|
||||
*
|
||||
* @param beanDefinition the bean definition to be configured
|
||||
* @param element the XML element where the attribute should be defined
|
||||
* @param attributeName the name of the attribute whose value will be
|
||||
* used as a bean reference to populate the property
|
||||
* @param propertyName the name of the property to be populated
|
||||
*/
|
||||
public static void setReferenceIfAttributeDefined(BeanDefinitionBuilder builder,
|
||||
Element element, String attributeName, String propertyName) {
|
||||
String attributeValue = element.getAttribute(attributeName);
|
||||
if (StringUtils.hasText(attributeValue)) {
|
||||
builder.addPropertyReference(propertyName, attributeValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the bean definition property corresponding to the specified
|
||||
* attributeName with the reference to a bean identified by the value of
|
||||
* that attribute if the attribute is defined in the given element. The
|
||||
* property name will be the camel-case equivalent of the lower case
|
||||
* hyphen separated attribute (e.g. the "foo-bar" attribute would match
|
||||
* the "fooBar" property).
|
||||
* that attribute if the attribute is defined in the given element.
|
||||
*
|
||||
* <p>The property name will be the camel-case equivalent of the lower
|
||||
* case hyphen separated attribute (e.g. the "foo-bar" attribute would
|
||||
* match the "fooBar" property).
|
||||
*
|
||||
* @see Conventions#attributeNameToPropertyName(String)
|
||||
*
|
||||
* @param beanDefinition - the bean definition to be configured
|
||||
* @param element - the XML element where the attribute should be defined
|
||||
@@ -79,11 +120,8 @@ public abstract class IntegrationNamespaceUtils {
|
||||
*/
|
||||
public static void setReferenceIfAttributeDefined(BeanDefinitionBuilder builder,
|
||||
Element element, String attributeName) {
|
||||
String attributeValue = element.getAttribute(attributeName);
|
||||
String propertyName = Conventions.attributeNameToPropertyName(attributeName);
|
||||
if (StringUtils.hasText(attributeValue)) {
|
||||
builder.addPropertyReference(propertyName, attributeValue);
|
||||
}
|
||||
setReferenceIfAttributeDefined(builder, element, attributeName,
|
||||
Conventions.attributeNameToPropertyName(attributeName));
|
||||
}
|
||||
|
||||
public static String parseBeanDefinitionElement(Element element, ParserContext parserContext) {
|
||||
|
||||
@@ -158,7 +158,7 @@ public abstract class AbstractEndpoint implements MessageEndpoint, ChannelRegist
|
||||
return this.channelRegistry;
|
||||
}
|
||||
|
||||
public void setMessageSelector(MessageSelector selector) {
|
||||
public void setSelector(MessageSelector selector) {
|
||||
this.selector = selector;
|
||||
}
|
||||
|
||||
|
||||
@@ -76,9 +76,9 @@ public class SimpleDispatcherTests {
|
||||
HandlerEndpoint endpoint1 = createEndpoint(TestHandlers.countingCountDownHandler(counter1, latch));
|
||||
HandlerEndpoint endpoint2 = createEndpoint(TestHandlers.countingCountDownHandler(counter2, latch));
|
||||
HandlerEndpoint endpoint3 = createEndpoint(TestHandlers.countingCountDownHandler(counter3, latch));
|
||||
endpoint1.setMessageSelector(new TestMessageSelector(selectorCounter, false));
|
||||
endpoint2.setMessageSelector(new TestMessageSelector(selectorCounter, false));
|
||||
endpoint3.setMessageSelector(new TestMessageSelector(selectorCounter, true));
|
||||
endpoint1.setSelector(new TestMessageSelector(selectorCounter, false));
|
||||
endpoint2.setSelector(new TestMessageSelector(selectorCounter, false));
|
||||
endpoint3.setSelector(new TestMessageSelector(selectorCounter, true));
|
||||
dispatcher.addTarget(endpoint1);
|
||||
dispatcher.addTarget(endpoint2);
|
||||
dispatcher.addTarget(endpoint3);
|
||||
@@ -103,9 +103,9 @@ public class SimpleDispatcherTests {
|
||||
HandlerEndpoint endpoint1 = createEndpoint(TestHandlers.countingCountDownHandler(counter1, latch));
|
||||
HandlerEndpoint endpoint2 = createEndpoint(TestHandlers.countingCountDownHandler(counter2, latch));
|
||||
HandlerEndpoint endpoint3 = createEndpoint(TestHandlers.countingCountDownHandler(counter3, latch));
|
||||
endpoint1.setMessageSelector(new TestMessageSelector(selectorCounter, false));
|
||||
endpoint2.setMessageSelector(new TestMessageSelector(selectorCounter, false));
|
||||
endpoint3.setMessageSelector(new TestMessageSelector(selectorCounter, false));
|
||||
endpoint1.setSelector(new TestMessageSelector(selectorCounter, false));
|
||||
endpoint2.setSelector(new TestMessageSelector(selectorCounter, false));
|
||||
endpoint3.setSelector(new TestMessageSelector(selectorCounter, false));
|
||||
dispatcher.addTarget(endpoint1);
|
||||
dispatcher.addTarget(endpoint2);
|
||||
dispatcher.addTarget(endpoint3);
|
||||
|
||||
@@ -158,7 +158,7 @@ public class HandlerEndpointTests {
|
||||
@Test(expected=MessageRejectedException.class)
|
||||
public void testEndpointWithSelectorRejecting() {
|
||||
HandlerEndpoint endpoint = new HandlerEndpoint(TestHandlers.nullHandler());
|
||||
endpoint.setMessageSelector(new MessageSelector() {
|
||||
endpoint.setSelector(new MessageSelector() {
|
||||
public boolean accept(Message<?> message) {
|
||||
return false;
|
||||
}
|
||||
@@ -170,7 +170,7 @@ public class HandlerEndpointTests {
|
||||
public void testEndpointWithSelectorAccepting() throws InterruptedException {
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
HandlerEndpoint endpoint = new HandlerEndpoint(TestHandlers.countDownHandler(latch));
|
||||
endpoint.setMessageSelector(new MessageSelector() {
|
||||
endpoint.setSelector(new MessageSelector() {
|
||||
public boolean accept(Message<?> message) {
|
||||
return true;
|
||||
}
|
||||
@@ -197,7 +197,7 @@ public class HandlerEndpointTests {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
endpoint.setMessageSelector(selectorChain);
|
||||
endpoint.setSelector(selectorChain);
|
||||
boolean exceptionWasThrown = false;
|
||||
try {
|
||||
endpoint.send(new StringMessage("test"));
|
||||
@@ -227,7 +227,7 @@ public class HandlerEndpointTests {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
endpoint.setMessageSelector(selectorChain);
|
||||
endpoint.setSelector(selectorChain);
|
||||
boolean exceptionWasThrown = false;
|
||||
try {
|
||||
endpoint.send(new StringMessage("test"));
|
||||
@@ -257,7 +257,7 @@ public class HandlerEndpointTests {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
endpoint.setMessageSelector(selectorChain);
|
||||
endpoint.setSelector(selectorChain);
|
||||
assertTrue(endpoint.send(new StringMessage("test")));
|
||||
assertEquals("both selectors and handler should have been invoked", 3, counter.get());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user