Using classnames rather than Class instances in header-value and payoad-type router parsers.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 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.
|
||||
@@ -18,42 +18,45 @@ package org.springframework.integration.config.xml;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||
import org.springframework.beans.factory.support.ManagedMap;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.channel.MapBasedChannelResolver;
|
||||
import org.springframework.integration.router.HeaderValueRouter;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for the <header-value-router/> element.
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Mark Fisher
|
||||
* @since 1.0.3
|
||||
*/
|
||||
public class HeaderValueRouterParser extends RouterParser {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder headerValueRouterBuilder = BeanDefinitionBuilder.genericBeanDefinition(HeaderValueRouter.class);
|
||||
BeanDefinitionBuilder headerValueRouterBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
IntegrationNamespaceUtils.BASE_PACKAGE + ".router.HeaderValueRouter");
|
||||
headerValueRouterBuilder.addConstructorArgValue(element.getAttribute("header-name"));
|
||||
|
||||
BeanDefinitionBuilder mapBasedChannelResolverBuilder = null;
|
||||
// check if mapping is provided otherwise header values will be treated as channel names
|
||||
List<Element> childElements = DomUtils.getChildElementsByTagName(element, "mapping");
|
||||
if (childElements != null && childElements.size() > 0){
|
||||
mapBasedChannelResolverBuilder = BeanDefinitionBuilder.genericBeanDefinition(MapBasedChannelResolver.class);
|
||||
if (childElements != null && childElements.size() > 0) {
|
||||
BeanDefinitionBuilder mapBasedChannelResolverBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
IntegrationNamespaceUtils.BASE_PACKAGE + ".channel.MapBasedChannelResolver");
|
||||
ManagedMap channelMap = new ManagedMap();
|
||||
for (Element childElement : childElements) {
|
||||
channelMap.put(childElement.getAttribute("value"), new RuntimeBeanReference(childElement.getAttribute("channel")));
|
||||
channelMap.put(childElement.getAttribute("value"),
|
||||
new RuntimeBeanReference(childElement.getAttribute("channel")));
|
||||
}
|
||||
mapBasedChannelResolverBuilder.addPropertyValue("channelMap", channelMap);
|
||||
String resolverBeanName = BeanDefinitionReaderUtils.registerWithGeneratedName(
|
||||
mapBasedChannelResolverBuilder.getBeanDefinition(), parserContext.getRegistry());
|
||||
headerValueRouterBuilder.addPropertyReference("channelResolver", resolverBeanName);
|
||||
}
|
||||
if (mapBasedChannelResolverBuilder != null){
|
||||
headerValueRouterBuilder.addPropertyValue("channelResolver", mapBasedChannelResolverBuilder.getBeanDefinition());
|
||||
}
|
||||
|
||||
BeanDefinitionBuilder rootBuilder = this.createBuilder();
|
||||
rootBuilder.addPropertyValue("targetObject", headerValueRouterBuilder.getBeanDefinition());
|
||||
return this.doParse(element, parserContext, rootBuilder);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 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.
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package org.springframework.integration.config.xml;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
@@ -23,8 +26,6 @@ import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||
import org.springframework.beans.factory.xml.NamespaceHandler;
|
||||
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
/**
|
||||
* Namespace handler for the integration namespace.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 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.
|
||||
@@ -18,39 +18,44 @@ package org.springframework.integration.config.xml;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.ManagedMap;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.router.PayloadTypeRouter;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for the <payload-type-router/> element.
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Mark Fisher
|
||||
* @since 1.0.3
|
||||
*/
|
||||
public class PayloadTypeRouterParser extends RouterParser {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder payloadTypeRouterBuilder = BeanDefinitionBuilder.genericBeanDefinition(PayloadTypeRouter.class);
|
||||
|
||||
BeanDefinitionBuilder payloadTypeRouterBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
IntegrationNamespaceUtils.BASE_PACKAGE + ".router.PayloadTypeRouter");
|
||||
List<Element> childElements = DomUtils.getChildElementsByTagName(element, "mapping");
|
||||
Assert.notEmpty(childElements, "Type mapping must be provided (e.g., <mapping type=\"X\" channel=\"channel1\"/>)");
|
||||
|
||||
Assert.notEmpty(childElements,
|
||||
"Type mapping must be provided (e.g., <mapping type=\"X\" channel=\"channel1\"/>)");
|
||||
ManagedMap channelMap = new ManagedMap();
|
||||
for (Element childElement : childElements) {
|
||||
String typeName = childElement.getAttribute("type");
|
||||
Assert.isTrue(ClassUtils.isPresent(typeName, ClassUtils.getDefaultClassLoader()), typeName + " can not be loaded");
|
||||
ClassLoader classLoader = parserContext.getReaderContext().getBeanClassLoader();
|
||||
if (classLoader == null) {
|
||||
classLoader = ClassUtils.getDefaultClassLoader();
|
||||
}
|
||||
Assert.isTrue(ClassUtils.isPresent(typeName, classLoader), typeName + " can not be loaded");
|
||||
channelMap.put(typeName, new RuntimeBeanReference(childElement.getAttribute("channel")));
|
||||
}
|
||||
|
||||
payloadTypeRouterBuilder.addPropertyValue("payloadTypeChannelMap", channelMap);
|
||||
|
||||
BeanDefinitionBuilder rootBuilder = this.createBuilder();
|
||||
rootBuilder.addPropertyValue("targetObject", payloadTypeRouterBuilder.getBeanDefinition());
|
||||
return this.doParse(element, parserContext, rootBuilder);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 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.
|
||||
@@ -41,14 +41,8 @@ public class RouterParser extends AbstractConsumerEndpointParser {
|
||||
builder.addPropertyReference("targetObject", ref);
|
||||
return doParse(element, parserContext, builder);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param element
|
||||
* @param parserContext
|
||||
* @return
|
||||
*/
|
||||
|
||||
protected BeanDefinitionBuilder doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
|
||||
if (StringUtils.hasText(element.getAttribute(METHOD_ATTRIBUTE))) {
|
||||
String method = element.getAttribute(METHOD_ATTRIBUTE);
|
||||
builder.addPropertyValue("targetMethodName", method);
|
||||
@@ -63,12 +57,10 @@ public class RouterParser extends AbstractConsumerEndpointParser {
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "ignore-channel-name-resolution-failures");
|
||||
return builder;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
BeanDefinitionBuilder createBuilder(){
|
||||
return BeanDefinitionBuilder.genericBeanDefinition(IntegrationNamespaceUtils.BASE_PACKAGE + ".config.RouterFactoryBean");
|
||||
|
||||
BeanDefinitionBuilder createBuilder() {
|
||||
return BeanDefinitionBuilder.genericBeanDefinition(
|
||||
IntegrationNamespaceUtils.BASE_PACKAGE + ".config.RouterFactoryBean");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -830,12 +830,15 @@
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
|
||||
<xsd:element name="header-value-router">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines a Header Value Router.
|
||||
</xsd:documentation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Defines a Header Value Router. The 'header-name' attribute specifies which
|
||||
header value to lookup. That header value can then provide the name of a
|
||||
channel to be resolved. Alternatively, 1 or more 'mapping' sub-elements
|
||||
may be provided with expected header values mapped to channels.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:complexContent>
|
||||
@@ -848,8 +851,14 @@
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="default-output-channel"
|
||||
type="xsd:string">
|
||||
<xsd:attribute name="header-name" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Name of the header whose value to use.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="default-output-channel" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
@@ -859,22 +868,19 @@
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="resolution-required"
|
||||
type="xsd:boolean" />
|
||||
<xsd:attribute
|
||||
name="ignore-channel-name-resolution-failures" type="xsd:boolean" />
|
||||
<xsd:attribute name="header-name"
|
||||
type="xsd:string">
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="resolution-required" type="xsd:string"/>
|
||||
<xsd:attribute name="ignore-channel-name-resolution-failures" type="xsd:string"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="payload-type-router">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines a Header Value Router.
|
||||
</xsd:documentation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Defines a Payload Type Router. The 'mapping' sub-elements specify the
|
||||
associations between Java types and target channels.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:complexContent>
|
||||
@@ -887,8 +893,7 @@
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="default-output-channel"
|
||||
type="xsd:string">
|
||||
<xsd:attribute name="default-output-channel" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
@@ -898,22 +903,18 @@
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="resolution-required"
|
||||
type="xsd:boolean" />
|
||||
<xsd:attribute
|
||||
name="ignore-channel-name-resolution-failures" type="xsd:boolean" />
|
||||
<xsd:attribute name="header-name"
|
||||
type="xsd:string">
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="resolution-required" type="xsd:string"/>
|
||||
<xsd:attribute name="ignore-channel-name-resolution-failures" type="xsd:string"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="router">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines a Router.
|
||||
</xsd:documentation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Defines a Router.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:complexContent>
|
||||
@@ -932,15 +933,14 @@
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="java.lang.Object" />
|
||||
<tool:expected-type type="java.lang.Object"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="method" type="xsd:string" />
|
||||
<xsd:attribute name="resolution-required" type="xsd:boolean" />
|
||||
<xsd:attribute name="ignore-channel-name-resolution-failures"
|
||||
type="xsd:boolean" />
|
||||
<xsd:attribute name="method" type="xsd:string"/>
|
||||
<xsd:attribute name="resolution-required" type="xsd:string"/>
|
||||
<xsd:attribute name="ignore-channel-name-resolution-failures" type="xsd:string"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
|
||||
Reference in New Issue
Block a user