From 6f207bc2d74e43f1008ef626aa9b800a035ecf2f Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Tue, 20 May 2008 16:51:12 +0000 Subject: [PATCH] Added namespace support for ThreadLocalChannel (INT-222). --- .../config/ThreadLocalChannelParser.java | 41 +++++++++++++++++++ .../config/IntegrationNamespaceHandler.java | 2 + .../config/spring-integration-core-1.0.xsd | 2 + .../config/ThreadLocalChannelParserTests.java | 40 ++++++++++++++++++ .../config/threadLocalChannelParserTests.xml | 12 ++++++ 5 files changed, 97 insertions(+) create mode 100644 spring-integration-core/src/main/java/org/springframework/integration/channel/config/ThreadLocalChannelParser.java create mode 100644 spring-integration-core/src/test/java/org/springframework/integration/channel/config/ThreadLocalChannelParserTests.java create mode 100644 spring-integration-core/src/test/java/org/springframework/integration/channel/config/threadLocalChannelParserTests.xml diff --git a/spring-integration-core/src/main/java/org/springframework/integration/channel/config/ThreadLocalChannelParser.java b/spring-integration-core/src/main/java/org/springframework/integration/channel/config/ThreadLocalChannelParser.java new file mode 100644 index 0000000000..38fe4d5821 --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/integration/channel/config/ThreadLocalChannelParser.java @@ -0,0 +1,41 @@ +/* + * 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.channel.config; + +import org.w3c.dom.Element; + +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.integration.channel.DispatcherPolicy; +import org.springframework.integration.channel.ThreadLocalChannel; + +/** + * Parser for the <thread-local-channel> element. + * + * @author Mark Fisher + */ +public class ThreadLocalChannelParser extends AbstractChannelParser { + + @Override + protected Class getBeanClass(Element element) { + return ThreadLocalChannel.class; + } + + @Override + protected void configureConstructorArgs(BeanDefinitionBuilder builder, Element element, DispatcherPolicy dispatcherPolicy) { + } + +} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationNamespaceHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationNamespaceHandler.java index 2da47959ae..8224d6f8f1 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationNamespaceHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationNamespaceHandler.java @@ -33,6 +33,7 @@ import org.springframework.integration.channel.config.DirectChannelParser; import org.springframework.integration.channel.config.PriorityChannelParser; import org.springframework.integration.channel.config.QueueChannelParser; import org.springframework.integration.channel.config.RendezvousChannelParser; +import org.springframework.integration.channel.config.ThreadLocalChannelParser; import org.springframework.integration.router.config.SplitterParser; import org.springframework.util.ClassUtils; @@ -58,6 +59,7 @@ public class IntegrationNamespaceHandler extends NamespaceHandlerSupport { registerBeanDefinitionParser("direct-channel", new DirectChannelParser()); registerBeanDefinitionParser("priority-channel", new PriorityChannelParser()); registerBeanDefinitionParser("rendezvous-channel", new RendezvousChannelParser()); + registerBeanDefinitionParser("thread-local-channel", new ThreadLocalChannelParser()); registerBeanDefinitionParser("source-adapter", new MethodInvokingAdapterParser()); registerBeanDefinitionParser("target-adapter", new MethodInvokingAdapterParser()); registerBeanDefinitionParser("source-endpoint", new SourceEndpointParser()); 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 9fed29d416..bc19a253dd 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 @@ -94,6 +94,8 @@ + + diff --git a/spring-integration-core/src/test/java/org/springframework/integration/channel/config/ThreadLocalChannelParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/channel/config/ThreadLocalChannelParserTests.java new file mode 100644 index 0000000000..7e9005f497 --- /dev/null +++ b/spring-integration-core/src/test/java/org/springframework/integration/channel/config/ThreadLocalChannelParserTests.java @@ -0,0 +1,40 @@ +/* + * 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.channel.config; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.integration.channel.MessageChannel; +import org.springframework.integration.channel.ThreadLocalChannel; + +/** + * @author Mark Fisher + */ +public class ThreadLocalChannelParserTests { + + @Test + public void testChannelType() { + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( + "threadLocalChannelParserTests.xml", ThreadLocalChannelParserTests.class); + MessageChannel channel = (MessageChannel) context.getBean("channel"); + assertEquals(ThreadLocalChannel.class, channel.getClass()); + } + +} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/channel/config/threadLocalChannelParserTests.xml b/spring-integration-core/src/test/java/org/springframework/integration/channel/config/threadLocalChannelParserTests.xml new file mode 100644 index 0000000000..e577e3a503 --- /dev/null +++ b/spring-integration-core/src/test/java/org/springframework/integration/channel/config/threadLocalChannelParserTests.xml @@ -0,0 +1,12 @@ + + + + + +