diff --git a/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/config/JmsTargetAdapterParser.java b/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/config/JmsTargetAdapterParser.java new file mode 100644 index 0000000000..2190397258 --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/integration/adapter/jms/config/JmsTargetAdapterParser.java @@ -0,0 +1,82 @@ +/* + * Copyright 2002-2007 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.adapter.jms.config; + +import org.w3c.dom.Element; + +import org.springframework.beans.factory.BeanCreationException; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; +import org.springframework.integration.adapter.jms.JmsTargetAdapter; +import org.springframework.util.StringUtils; + +/** + * Parser for the <jms-target/> element. + * + * @author Mark Fisher + */ +public class JmsTargetAdapterParser extends AbstractSingleBeanDefinitionParser { + + private static final String JMS_TEMPLATE_ATTRIBUTE = "jms-template"; + + private static final String JMS_TEMPLATE_PROPERTY = "jmsTemplate"; + + private static final String CONNECTION_FACTORY_ATTRIBUTE = "connection-factory"; + + private static final String CONNECTION_FACTORY_PROPERTY = "connectionFactory"; + + private static final String DESTINATION_ATTRIBUTE = "destination"; + + private static final String DESTINATION_PROPERTY = "destination"; + + private static final String CHANNEL_ATTRIBUTE = "channel"; + + private static final String CHANNEL_PROPERTY = "channel"; + + + protected Class getBeanClass(Element element) { + return JmsTargetAdapter.class; + } + + protected boolean shouldGenerateId() { + return true; + } + + protected void doParse(Element element, BeanDefinitionBuilder builder) { + String jmsTemplate = element.getAttribute(JMS_TEMPLATE_ATTRIBUTE); + String connectionFactory = element.getAttribute(CONNECTION_FACTORY_ATTRIBUTE); + String destination = element.getAttribute(DESTINATION_ATTRIBUTE); + if (StringUtils.hasText(jmsTemplate)) { + if (StringUtils.hasText(connectionFactory) || StringUtils.hasText(destination)) { + throw new BeanCreationException("when providing a 'jms-template' reference, neither " + + "'connection-factory' or 'destination' should be provided."); + } + builder.addPropertyReference(JMS_TEMPLATE_PROPERTY, jmsTemplate); + } + else if (StringUtils.hasText(connectionFactory) && StringUtils.hasText(destination)) { + builder.addPropertyReference(CONNECTION_FACTORY_PROPERTY, connectionFactory); + builder.addPropertyReference(DESTINATION_PROPERTY, destination); + } + else { + throw new BeanCreationException("either a 'jms-template' reference or both " + + "'connection-factory' and 'destination' references must be provided."); + } + String channel = element.getAttribute(CHANNEL_ATTRIBUTE); + builder.addPropertyReference(CHANNEL_PROPERTY, channel); + } + +} 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 3f6c09ed0d..4d17bb7bb6 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 @@ -19,6 +19,7 @@ package org.springframework.integration.config; import org.springframework.beans.factory.xml.NamespaceHandlerSupport; import org.springframework.integration.adapter.file.config.FileSourceAdapterParser; import org.springframework.integration.adapter.file.config.FileTargetAdapterParser; +import org.springframework.integration.adapter.jms.config.JmsTargetAdapterParser; /** * Namespace handler for the integration namespace. @@ -36,6 +37,7 @@ public class IntegrationNamespaceHandler extends NamespaceHandlerSupport { registerBeanDefinitionParser("endpoint", new EndpointParser()); registerBeanDefinitionParser("file-source", new FileSourceAdapterParser()); registerBeanDefinitionParser("file-target", new FileTargetAdapterParser()); + registerBeanDefinitionParser("jms-target", new JmsTargetAdapterParser()); } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/spring-integration-1.0.xsd b/spring-integration-core/src/main/java/org/springframework/integration/config/spring-integration-1.0.xsd index 7616728793..2d527797f8 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/spring-integration-1.0.xsd +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/spring-integration-1.0.xsd @@ -159,4 +159,18 @@ + + + + + Defines a jms-based target channel adapter. + + + + + + + + + \ No newline at end of file