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 3d9fe3d4f0..4cb53a872a 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 @@ -38,6 +38,7 @@ public class IntegrationNamespaceHandler extends NamespaceHandlerSupport { 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()); diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/TransformerParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/TransformerParser.java new file mode 100644 index 0000000000..bafeafba18 --- /dev/null +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/TransformerParser.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.config; + +import org.springframework.integration.endpoint.MessageEndpoint; +import org.springframework.integration.transformer.MethodInvokingTransformer; +import org.springframework.integration.transformer.TransformerEndpoint; + +/** + * Parser for the <transformer/> element. + * + * @author Mark Fisher + */ +public class TransformerParser extends AbstractEndpointParser { + + @Override + protected Class getEndpointClass() { + return TransformerEndpoint.class; + } + + @Override + protected Class getMethodInvokingAdapterClass() { + return MethodInvokingTransformer.class; + } + +} 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 083cc43c03..2cbd8234f4 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 @@ -305,6 +305,14 @@ + + + + Defines a Transformer. + + + + diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/transformer/TestBean.java b/org.springframework.integration/src/test/java/org/springframework/integration/transformer/TestBean.java new file mode 100644 index 0000000000..b9a2bd4b48 --- /dev/null +++ b/org.springframework.integration/src/test/java/org/springframework/integration/transformer/TestBean.java @@ -0,0 +1,28 @@ +/* + * 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.transformer; + +/** + * @author Mark Fisher + */ +public class TestBean { + + public String upperCase(String input) { + return input.toUpperCase(); + } + +} diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/transformer/TransformerContextTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/transformer/TransformerContextTests.java new file mode 100644 index 0000000000..5cdf8bdd6f --- /dev/null +++ b/org.springframework.integration/src/test/java/org/springframework/integration/transformer/TransformerContextTests.java @@ -0,0 +1,46 @@ +/* + * 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.transformer; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.integration.channel.MessageChannel; +import org.springframework.integration.channel.PollableChannel; +import org.springframework.integration.message.Message; +import org.springframework.integration.message.StringMessage; + +/** + * @author Mark Fisher + */ +public class TransformerContextTests { + + @Test + public void methodInvokingTransformer() { + ApplicationContext context = new ClassPathXmlApplicationContext( + "transformerContextTests.xml", this.getClass()); + MessageChannel input = (MessageChannel) context.getBean("input"); + PollableChannel output = (PollableChannel) context.getBean("output"); + input.send(new StringMessage("foo")); + Message reply = output.receive(0); + assertEquals("FOO", reply.getPayload()); + } + +} \ No newline at end of file diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/transformer/transformerContextTests.xml b/org.springframework.integration/src/test/java/org/springframework/integration/transformer/transformerContextTests.xml new file mode 100644 index 0000000000..35be06cddd --- /dev/null +++ b/org.springframework.integration/src/test/java/org/springframework/integration/transformer/transformerContextTests.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + +