From 965b51d2a694f64ac447a1c31f51fa9a4837e290 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Mon, 13 Sep 2010 18:07:38 -0400 Subject: [PATCH] INT-1363 JmsOutboundChannelAdapterParser now allows a JmsTemplate reference along with a Destination or destinationName (but the latter 2 are still mutually exclusive) --- .../JmsInboundChannelAdapterParser.java | 9 +++---- .../JmsOutboundChannelAdapterParser.java | 25 ++++++++++++------- .../JmsInboundChannelAdapterParserTests.java | 10 ++------ 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParser.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParser.java index 3e893f87c8..8c18d5129d 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParser.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParser.java @@ -18,7 +18,6 @@ package org.springframework.integration.jms.config; import org.w3c.dom.Element; -import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.parsing.BeanComponentDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; @@ -71,17 +70,17 @@ public class JmsInboundChannelAdapterParser extends AbstractPollingInboundChanne parserContext.getReaderContext().error("The 'destination-name' " + "and 'destination' attributes are mutually exclusive.", parserContext.extractSource(element)); } - builder.addPropertyReference("destination", destination); + builder.addPropertyReference(JmsAdapterParserUtils.DESTINATION_PROPERTY, destination); } else if (hasDestinationName) { - builder.addPropertyValue("destinationName", destinationName); + builder.addPropertyValue(JmsAdapterParserUtils.DESTINATION_NAME_PROPERTY, destinationName); } } else if (!hasJmsTemplate) { - throw new BeanCreationException("either a '" + JmsAdapterParserUtils.JMS_TEMPLATE_ATTRIBUTE + + parserContext.getReaderContext().error("either a '" + JmsAdapterParserUtils.JMS_TEMPLATE_ATTRIBUTE + "' or one of '" + JmsAdapterParserUtils.DESTINATION_ATTRIBUTE + "' or '" + JmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE + - "' attributes must be provided for a polling JMS adapter"); + "' attributes must be provided for a polling JMS adapter", parserContext.extractSource(element)); } if (StringUtils.hasText(headerMapper)) { builder.addPropertyReference(JmsAdapterParserUtils.HEADER_MAPPER_PROPERTY, headerMapper); diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsOutboundChannelAdapterParser.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsOutboundChannelAdapterParser.java index 88fef7075c..8e2241c076 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsOutboundChannelAdapterParser.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsOutboundChannelAdapterParser.java @@ -40,26 +40,33 @@ public class JmsOutboundChannelAdapterParser extends AbstractOutboundChannelAdap String destination = element.getAttribute(JmsAdapterParserUtils.DESTINATION_ATTRIBUTE); String destinationName = element.getAttribute(JmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE); String headerMapper = element.getAttribute(JmsAdapterParserUtils.HEADER_MAPPER_ATTRIBUTE); + boolean hasJmsTemplate = StringUtils.hasText(jmsTemplate); boolean hasDestinationRef = StringUtils.hasText(destination); boolean hasDestinationName = StringUtils.hasText(destinationName); - if (StringUtils.hasText(jmsTemplate)) { + if (hasJmsTemplate) { JmsAdapterParserUtils.verifyNoJmsTemplateAttributes(element, parserContext); builder.addConstructorArgReference(jmsTemplate); } - else if (hasDestinationRef ^ hasDestinationName) { + else { builder.addConstructorArgValue(JmsAdapterParserUtils.parseJmsTemplateBeanDefinition(element, parserContext)); - if (StringUtils.hasText(destination)) { + } + if (hasDestinationRef || hasDestinationName) { + if (hasDestinationRef) { + if (hasDestinationName) { + parserContext.getReaderContext().error("The 'destination-name' " + + "and 'destination' attributes are mutually exclusive.", parserContext.extractSource(element)); + } builder.addPropertyReference(JmsAdapterParserUtils.DESTINATION_PROPERTY, destination); } - else { + else if (hasDestinationName) { builder.addPropertyValue(JmsAdapterParserUtils.DESTINATION_NAME_PROPERTY, destinationName); - IntegrationNamespaceUtils.setValueIfAttributeDefined( - builder, element, JmsAdapterParserUtils.PUB_SUB_DOMAIN_ATTRIBUTE); } } - else { - parserContext.getReaderContext().error("Either a 'jms-template' reference " + - "or one of 'destination' or 'destination-name' must be provided.", parserContext.extractSource(element)); + else if (!hasJmsTemplate) { + parserContext.getReaderContext().error("either a '" + JmsAdapterParserUtils.JMS_TEMPLATE_ATTRIBUTE + + "' or one of '" + JmsAdapterParserUtils.DESTINATION_ATTRIBUTE + "' or '" + + JmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE + + "' attributes must be provided", parserContext.extractSource(element)); } if (StringUtils.hasText(headerMapper)) { builder.addPropertyReference(JmsAdapterParserUtils.HEADER_MAPPER_PROPERTY, headerMapper); diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParserTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParserTests.java index 888323d13e..56e977081b 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParserTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 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. @@ -69,13 +69,7 @@ public class JmsInboundChannelAdapterParserTests { @Test(expected = BeanDefinitionStoreException.class) public void adapterWithConnectionFactoryOnly() { - try { - new ClassPathXmlApplicationContext("jmsInboundWithConnectionFactoryOnly.xml", this.getClass()); - } - catch (RuntimeException e) { - assertEquals(BeanCreationException.class, e.getCause().getClass()); - throw e; - } + new ClassPathXmlApplicationContext("jmsInboundWithConnectionFactoryOnly.xml", this.getClass()); } @Test(expected = BeanCreationException.class)