diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/ChannelAdapterParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/ChannelAdapterParser.java deleted file mode 100644 index 1f4f17e0da..0000000000 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/ChannelAdapterParser.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * 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.config; - -import org.w3c.dom.Element; - -import org.springframework.beans.factory.support.AbstractBeanDefinition; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.integration.ConfigurationException; -import org.springframework.integration.endpoint.OutboundChannelAdapter; -import org.springframework.integration.endpoint.SourcePollingChannelAdapter; -import org.springframework.integration.message.MethodInvokingConsumer; -import org.springframework.integration.message.MethodInvokingSource; -import org.springframework.util.StringUtils; -import org.springframework.util.xml.DomUtils; - -/** - * Parser for the <channel-adapter/> element. - * - * @author Mark Fisher - */ -public class ChannelAdapterParser extends AbstractChannelAdapterParser { - - @Override - protected AbstractBeanDefinition doParse(Element element, ParserContext parserContext, String channelName) { - String source = element.getAttribute("source"); - String target = element.getAttribute("target"); - String methodName = element.getAttribute("method"); - Element pollerElement = DomUtils.getChildElementByTagName(element, "poller"); - BeanDefinitionBuilder adapterBuilder = null; - if (StringUtils.hasText(source)) { - if (StringUtils.hasText(target)) { - throw new ConfigurationException("both 'source' and 'target' are not allowed, provide only one"); - } - if (StringUtils.hasText(methodName)) { - BeanDefinitionBuilder invokerBuilder = BeanDefinitionBuilder.genericBeanDefinition(MethodInvokingSource.class); - invokerBuilder.addPropertyReference("object", source); - invokerBuilder.addPropertyValue("methodName", methodName); - source = BeanDefinitionReaderUtils.registerWithGeneratedName(invokerBuilder.getBeanDefinition(), parserContext.getRegistry()); - } - adapterBuilder = BeanDefinitionBuilder.genericBeanDefinition(SourcePollingChannelAdapter.class); - adapterBuilder.addPropertyReference("source", source); - adapterBuilder.addPropertyReference("outputChannel", channelName); - if (pollerElement != null) { - IntegrationNamespaceUtils.configureSchedule(pollerElement, adapterBuilder); - IntegrationNamespaceUtils.setValueIfAttributeDefined(adapterBuilder, pollerElement, "max-messages-per-poll"); - Element txElement = DomUtils.getChildElementByTagName(pollerElement, "transactional"); - if (txElement != null) { - IntegrationNamespaceUtils.configureTransactionAttributes(txElement, adapterBuilder); - } - } - } - else if (StringUtils.hasText(target)) { - if (StringUtils.hasText(methodName)) { - BeanDefinitionBuilder invokerBuilder = BeanDefinitionBuilder.genericBeanDefinition(MethodInvokingConsumer.class); - invokerBuilder.addConstructorArgReference(target); - invokerBuilder.addConstructorArgValue(methodName); - target = BeanDefinitionReaderUtils.registerWithGeneratedName(invokerBuilder.getBeanDefinition(), parserContext.getRegistry()); - } - adapterBuilder = BeanDefinitionBuilder.genericBeanDefinition(OutboundChannelAdapter.class); - adapterBuilder.addConstructorArgReference(target); - if (pollerElement != null) { - if (!StringUtils.hasText(channelName)) { - throw new ConfigurationException("outbound channel-adapter with a 'poller' requires a 'channel' to poll"); - } - IntegrationNamespaceUtils.configureSchedule(pollerElement, adapterBuilder); - Element txElement = DomUtils.getChildElementByTagName(pollerElement, "transactional"); - if (txElement != null) { - IntegrationNamespaceUtils.configureTransactionAttributes(txElement, adapterBuilder); - } - } - adapterBuilder.addPropertyReference("inputChannel", channelName); - } - else { - throw new ConfigurationException("either 'source' or 'target' is required"); - } - return adapterBuilder.getBeanDefinition(); - } - -} diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/IntegrationNamespaceHandler.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/IntegrationNamespaceHandler.java index 4cb53a872a..30c46790ae 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/IntegrationNamespaceHandler.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/IntegrationNamespaceHandler.java @@ -35,14 +35,15 @@ public class IntegrationNamespaceHandler extends NamespaceHandlerSupport { registerBeanDefinitionParser("thread-local-channel", new ThreadLocalChannelParser()); registerBeanDefinitionParser("publish-subscribe-channel", new PublishSubscribeChannelParser()); registerBeanDefinitionParser("service-activator", new ServiceActivatorParser()); - registerBeanDefinitionParser("channel-adapter", new ChannelAdapterParser()); - registerBeanDefinitionParser("gateway", new GatewayParser()); - registerBeanDefinitionParser("selector-chain", new SelectorChainParser()); registerBeanDefinitionParser("transformer", new TransformerParser()); registerBeanDefinitionParser("router", new RouterParser()); registerBeanDefinitionParser("splitter", new SplitterParser()); registerBeanDefinitionParser("aggregator", new AggregatorParser()); registerBeanDefinitionParser("resequencer", new ResequencerParser()); + registerBeanDefinitionParser("inbound-channel-adapter", new MethodInvokingInboundChannelAdapterParser()); + registerBeanDefinitionParser("outbound-channel-adapter", new MethodInvokingOutboundChannelAdapterParser()); + registerBeanDefinitionParser("gateway", new GatewayParser()); + registerBeanDefinitionParser("selector-chain", new SelectorChainParser()); registerBeanDefinitionParser("pool-executor", new PoolExecutorParser()); } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/MethodInvokingInboundChannelAdapterParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/MethodInvokingInboundChannelAdapterParser.java new file mode 100644 index 0000000000..98a941c96e --- /dev/null +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/MethodInvokingInboundChannelAdapterParser.java @@ -0,0 +1,50 @@ +/* + * 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.config; + +import org.w3c.dom.Element; + +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.message.MethodInvokingSource; +import org.springframework.util.Assert; +import org.springframework.util.StringUtils; + +/** + * Parser for the <inbound-channel-adapter/> element. + * + * @author Mark Fisher + */ +public class MethodInvokingInboundChannelAdapterParser extends AbstractPollingInboundChannelAdapterParser { + + @Override + protected String parseSource(Element element, ParserContext parserContext) { + String source = element.getAttribute("source"); + Assert.hasText(source, "The 'source' attribute is required."); + String methodName = element.getAttribute("method"); + if (StringUtils.hasText(methodName)) { + BeanDefinitionBuilder invokerBuilder = BeanDefinitionBuilder.genericBeanDefinition(MethodInvokingSource.class); + invokerBuilder.addPropertyReference("object", source); + invokerBuilder.addPropertyValue("methodName", methodName); + source = BeanDefinitionReaderUtils.registerWithGeneratedName( + invokerBuilder.getBeanDefinition(), parserContext.getRegistry()); + } + return source; + } + +} diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/spring-integration-1.0.xsd b/org.springframework.integration/src/main/java/org/springframework/integration/config/spring-integration-1.0.xsd index 2cbd8234f4..499eb92006 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/spring-integration-1.0.xsd +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/spring-integration-1.0.xsd @@ -163,23 +163,37 @@ - + - Defines a Channel Adapter that is capable of either receiving from a MessageSource and sending - the result to a MessageChannel or receiving from a MessageChannel and sending the result to a - MessageTarget. Therefore, either "source" or "target" should be provided (but never both). + Defines a Channel Adapter that receives from a MessageSource and sends to a MessageChannel. + + + + + + + + + + Defines a Channel Adapter that receives from a MessageChannel and sends to a MessageConsumer. + + + + + + + - diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/ChannelAdapterParserTests-context.xml b/org.springframework.integration/src/test/java/org/springframework/integration/config/ChannelAdapterParserTests-context.xml index 112d2dd73f..46fd4cc36d 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/config/ChannelAdapterParserTests-context.xml +++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/ChannelAdapterParserTests-context.xml @@ -13,13 +13,13 @@ - + - + - + - +