Added namespace support for the 'chain' element to create a Message Endpoint that delegates to a MessageHandlerChain (INT-391).
This commit is contained in:
@@ -19,9 +19,10 @@ package org.springframework.integration.config.xml;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||
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.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.config.ConsumerEndpointFactoryBean;
|
||||
@@ -33,7 +34,7 @@ import org.springframework.util.xml.DomUtils;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public abstract class AbstractConsumerEndpointParser extends AbstractSingleBeanDefinitionParser {
|
||||
public abstract class AbstractConsumerEndpointParser extends AbstractBeanDefinitionParser {
|
||||
|
||||
protected static final String REF_ATTRIBUTE = "ref";
|
||||
|
||||
@@ -46,11 +47,6 @@ public abstract class AbstractConsumerEndpointParser extends AbstractSingleBeanD
|
||||
private static final String SELECTOR_ATTRIBUTE = "selector";
|
||||
|
||||
|
||||
@Override
|
||||
protected final Class<?> getBeanClass(Element element) {
|
||||
return ConsumerEndpointFactoryBean.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateId() {
|
||||
return false;
|
||||
@@ -62,7 +58,7 @@ public abstract class AbstractConsumerEndpointParser extends AbstractSingleBeanD
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the MessageConsumer.
|
||||
* Parse the MessageHandler.
|
||||
*/
|
||||
protected abstract BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext);
|
||||
|
||||
@@ -71,13 +67,18 @@ public abstract class AbstractConsumerEndpointParser extends AbstractSingleBeanD
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
BeanDefinitionBuilder consumerBuilder = this.parseHandler(element, parserContext);
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(consumerBuilder, element, OUTPUT_CHANNEL_ATTRIBUTE);
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(consumerBuilder, element, SELECTOR_ATTRIBUTE);
|
||||
String consumerBeanName = BeanDefinitionReaderUtils.registerWithGeneratedName(
|
||||
consumerBuilder.getBeanDefinition(), parserContext.getRegistry());
|
||||
builder.addConstructorArgReference(consumerBeanName);
|
||||
protected final AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder handlerBuilder = this.parseHandler(element, parserContext);
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(handlerBuilder, element, OUTPUT_CHANNEL_ATTRIBUTE);
|
||||
AbstractBeanDefinition handlerBeanDefinition = handlerBuilder.getBeanDefinition();
|
||||
if (!element.hasAttribute(this.getInputChannelAttributeName())) {
|
||||
return handlerBeanDefinition;
|
||||
}
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ConsumerEndpointFactoryBean.class);
|
||||
String handlerBeanName = BeanDefinitionReaderUtils.registerWithGeneratedName(handlerBeanDefinition, parserContext.getRegistry());
|
||||
builder.addConstructorArgReference(handlerBeanName);
|
||||
// TODO: remove the 'selector'
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(handlerBuilder, element, SELECTOR_ATTRIBUTE);
|
||||
String inputChannelAttributeName = this.getInputChannelAttributeName();
|
||||
String inputChannelName = element.getAttribute(inputChannelAttributeName);
|
||||
Assert.hasText(inputChannelName, "the '" + inputChannelAttributeName + "' attribute is required");
|
||||
@@ -98,13 +99,7 @@ public abstract class AbstractConsumerEndpointParser extends AbstractSingleBeanD
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, pollerElement, "task-executor");
|
||||
}
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "auto-startup");
|
||||
this.postProcess(element, parserContext, builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses may implement this method to provide additional configuration.
|
||||
*/
|
||||
protected void postProcess(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
return builder.getBeanDefinition();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.xml;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
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.support.ManagedList;
|
||||
import org.springframework.beans.factory.xml.NamespaceHandler;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.handler.MessageHandlerChain;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Parser for the <chain> element.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ChainParser extends AbstractConsumerEndpointParser {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MessageHandlerChain.class);
|
||||
ManagedList handlerList = new ManagedList();
|
||||
NodeList children = element.getChildNodes();
|
||||
for (int i = 0; i < children.getLength(); i++) {
|
||||
Node child = children.item(i);
|
||||
if (child.getNodeType() == Node.ELEMENT_NODE) {
|
||||
String childBeanName = this.parseChild((Element) child, parserContext);
|
||||
handlerList.add(new RuntimeBeanReference(childBeanName));
|
||||
}
|
||||
}
|
||||
builder.addPropertyValue("handlers", handlerList);
|
||||
return builder;
|
||||
}
|
||||
|
||||
private String parseChild(Element element, ParserContext parserContext) {
|
||||
NamespaceHandler handler = parserContext.getReaderContext().getNamespaceHandlerResolver().resolve(element.getNamespaceURI());
|
||||
BeanDefinition beanDefinition = handler.parse(element, parserContext);
|
||||
Assert.notNull(beanDefinition, "BeanDefinition must not be null");
|
||||
Assert.isInstanceOf(AbstractBeanDefinition.class, beanDefinition);
|
||||
return BeanDefinitionReaderUtils.registerWithGeneratedName(
|
||||
(AbstractBeanDefinition) beanDefinition, parserContext.getRegistry());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -108,6 +108,7 @@ public class IntegrationNamespaceHandler implements NamespaceHandler {
|
||||
registerBeanDefinitionParser("inbound-channel-adapter", new MethodInvokingInboundChannelAdapterParser());
|
||||
registerBeanDefinitionParser("outbound-channel-adapter", new MethodInvokingOutboundChannelAdapterParser());
|
||||
registerBeanDefinitionParser("gateway", new GatewayParser());
|
||||
registerBeanDefinitionParser("chain", new ChainParser());
|
||||
registerBeanDefinitionParser("selector-chain", new SelectorChainParser());
|
||||
registerBeanDefinitionParser("annotation-config", new AnnotationConfigParser());
|
||||
registerBeanDefinitionParser("application-event-multicaster", new ApplicationEventMulticasterParser());
|
||||
|
||||
@@ -214,10 +214,10 @@
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="beans:identifiedType">
|
||||
<xsd:all>
|
||||
<xsd:extension base="handlerType">
|
||||
<xsd:sequence>
|
||||
<xsd:element ref="poller" minOccurs="0" maxOccurs="1"/>
|
||||
</xsd:all>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="input-channel" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
@@ -227,14 +227,58 @@
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="ref" type="xsd:string"/>
|
||||
<xsd:attribute name="method" type="xsd:string"/>
|
||||
<xsd:attribute name="selector" type="xsd:string"/>
|
||||
<xsd:attribute name="auto-startup" type="xsd:string"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="handlerType">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Base type for Message Handlers.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="beans:identifiedType">
|
||||
<xsd:attribute name="ref" type="xsd:string"/>
|
||||
<xsd:attribute name="method" type="xsd:string"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:element name="chain">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines an endpoint composed of a chain of Message Handlers.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="inputOutputEndpointType">
|
||||
<xsd:sequence>
|
||||
<xsd:choice minOccurs="1" maxOccurs="unbounded">
|
||||
<xsd:element name="filter" type="handlerType"/>
|
||||
<xsd:element name="transformer" type="handlerType"/>
|
||||
<xsd:element name="service-activator" type="handlerType"/>
|
||||
<xsd:element name="splitter" type="handlerType"/>
|
||||
<xsd:any namespace="##other" processContents="strict" minOccurs="0" maxOccurs="unbounded"/>
|
||||
</xsd:choice>
|
||||
<xsd:element name="router" minOccurs="0" maxOccurs="1">
|
||||
<xsd:complexType>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="handlerType">
|
||||
<xsd:attribute name="default-output-channel" type="xsd:string"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:sequence>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="poller">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
|
||||
Reference in New Issue
Block a user