From cb3c4fbdc3e9208069abd83bf688d7d9f72860f6 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Tue, 22 Apr 2008 17:44:23 +0000 Subject: [PATCH] Removed support for sub-element for since the 'handler-ref' attribute is sufficient. --- .../integration/config/EndpointParser.java | 60 ++++--------------- .../config/spring-integration-core-1.0.xsd | 3 +- .../config/EndpointParserTests.java | 13 ---- .../endpointWithHandlerChildElement.xml | 23 ------- .../config/endpointWithSelectors.xml | 3 +- 5 files changed, 12 insertions(+), 90 deletions(-) delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/config/endpointWithHandlerChildElement.xml diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/EndpointParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/EndpointParser.java index 37f9e8be93..0389cf2d48 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/EndpointParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/EndpointParser.java @@ -16,9 +16,6 @@ package org.springframework.integration.config; -import java.util.ArrayList; -import java.util.List; - import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -34,7 +31,6 @@ import org.springframework.integration.ConfigurationException; import org.springframework.integration.endpoint.ConcurrencyPolicy; import org.springframework.integration.endpoint.HandlerEndpoint; import org.springframework.integration.handler.DefaultMessageHandlerAdapter; -import org.springframework.integration.handler.MessageHandlerChain; import org.springframework.integration.scheduling.PollingSchedule; import org.springframework.integration.scheduling.Schedule; import org.springframework.integration.scheduling.Subscription; @@ -61,14 +57,8 @@ public class EndpointParser implements BeanDefinitionParser { private static final String SELECTORS_PROPERTY = "messageSelectors"; - private static final String HANDLER_ELEMENT = "handler"; - private static final String REF_ATTRIBUTE = "ref"; - private static final String METHOD_ATTRIBUTE = "method"; - - private static final String HANDLERS_PROPERTY = "handlers"; - private static final String HANDLER_REF_ATTRIBUTE = "handler-ref"; private static final String HANDLER_METHOD_ATTRIBUTE = "handler-method"; @@ -95,6 +85,10 @@ public class EndpointParser implements BeanDefinitionParser { public BeanDefinition parse(Element element, ParserContext parserContext) { + String handlerRef = element.getAttribute(HANDLER_REF_ATTRIBUTE); + if (!StringUtils.hasText(handlerRef)) { + throw new ConfigurationException("The 'handler-ref' attribute is required."); + } RootBeanDefinition endpointDef = new RootBeanDefinition(HandlerEndpoint.class); endpointDef.setSource(parserContext.extractSource(element)); String inputChannel = element.getAttribute(INPUT_CHANNEL_ATTRIBUTE); @@ -104,7 +98,6 @@ public class EndpointParser implements BeanDefinitionParser { endpointDef.getPropertyValues().addPropertyValue(DEFAULT_OUTPUT_CHANNEL_PROPERTY, defaultOutputChannel); } ManagedList selectors = new ManagedList(); - List childHandlerRefs = new ArrayList(); NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node child = childNodes.item(i); @@ -117,16 +110,6 @@ public class EndpointParser implements BeanDefinitionParser { String ref = ((Element) child).getAttribute(REF_ATTRIBUTE); selectors.add(new RuntimeBeanReference(ref)); } - else if (HANDLER_ELEMENT.equals(localName)) { - String ref = ((Element) child).getAttribute(REF_ATTRIBUTE); - String method = ((Element) child).getAttribute(METHOD_ATTRIBUTE); - if (StringUtils.hasText(method)) { - childHandlerRefs.add(this.parseHandlerAdapter(ref, method, parserContext)); - } - else { - childHandlerRefs.add(ref); - } - } else if (SCHEDULE_ELEMENT.equals(localName)) { schedule = this.parseSchedule((Element) child); } @@ -145,36 +128,13 @@ public class EndpointParser implements BeanDefinitionParser { if (selectors.size() > 0) { endpointDef.getPropertyValues().addPropertyValue(SELECTORS_PROPERTY, selectors); } - if (childHandlerRefs.size() > 0) { - if (childHandlerRefs.size() == 1) { - endpointDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(childHandlerRefs.get(0))); - } - else { - RootBeanDefinition handlerChainDef = new RootBeanDefinition(MessageHandlerChain.class); - List handlerList = new ManagedList(); - for (String ref : childHandlerRefs) { - handlerList.add(new RuntimeBeanReference(ref)); - } - handlerChainDef.getPropertyValues().addPropertyValue(HANDLERS_PROPERTY, handlerList); - String chainBeanName = parserContext.getReaderContext().generateBeanName(handlerChainDef); - parserContext.registerBeanComponent(new BeanComponentDefinition(handlerChainDef, chainBeanName)); - endpointDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(chainBeanName)); - } + String handlerMethod = element.getAttribute(HANDLER_METHOD_ATTRIBUTE); + if (StringUtils.hasText(handlerMethod)) { + String adapterBeanName = this.parseHandlerAdapter(handlerRef, handlerMethod, parserContext); + endpointDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(adapterBeanName)); } - String handlerRef = element.getAttribute(HANDLER_REF_ATTRIBUTE); - if (StringUtils.hasText(handlerRef)) { - if (childHandlerRefs.size() > 0) { - throw new ConfigurationException( - "The 'handler-ref' attribute is only supported when no 'handler' child elements are present"); - } - String handlerMethod = element.getAttribute(HANDLER_METHOD_ATTRIBUTE); - if (StringUtils.hasText(handlerMethod)) { - String adapterBeanName = this.parseHandlerAdapter(handlerRef, handlerMethod, parserContext); - endpointDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(adapterBeanName)); - } - else { - endpointDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(handlerRef)); - } + else { + endpointDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(handlerRef)); } String errorHandlerRef = element.getAttribute(ERROR_HANDLER_ATTRIBUTE); if (StringUtils.hasText(errorHandlerRef)) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/spring-integration-core-1.0.xsd b/spring-integration-core/src/main/java/org/springframework/integration/config/spring-integration-core-1.0.xsd index 3f9bb45240..2db48435de 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/spring-integration-core-1.0.xsd +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/spring-integration-core-1.0.xsd @@ -136,11 +136,10 @@ - - + diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/EndpointParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/EndpointParserTests.java index cc4a0dc2c0..06f4dd6ce8 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/EndpointParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/EndpointParserTests.java @@ -55,19 +55,6 @@ public class EndpointParserTests { assertEquals("test", handler.getMessageString()); } - @Test - public void testEndpointWithChildHandler() throws InterruptedException { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - "endpointWithHandlerChildElement.xml", this.getClass()); - context.start(); - MessageChannel channel = (MessageChannel) context.getBean("testChannel"); - TestHandler handler = (TestHandler) context.getBean("testHandler"); - assertNull(handler.getMessageString()); - channel.send(new GenericMessage(1, "test")); - handler.getLatch().await(50, TimeUnit.MILLISECONDS); - assertEquals("test", handler.getMessageString()); - } - @Test public void testHandlerAdapterEndpoint() throws InterruptedException { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/endpointWithHandlerChildElement.xml b/spring-integration-core/src/test/java/org/springframework/integration/config/endpointWithHandlerChildElement.xml deleted file mode 100644 index b527467757..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/endpointWithHandlerChildElement.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/endpointWithSelectors.xml b/spring-integration-core/src/test/java/org/springframework/integration/config/endpointWithSelectors.xml index 5b296a5fd4..9c0a54c39a 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/endpointWithSelectors.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/endpointWithSelectors.xml @@ -11,10 +11,9 @@ - + -