Skip to content

Commit

Permalink
INT-1363 JmsOutboundChannelAdapterParser now allows a JmsTemplate ref…
Browse files Browse the repository at this point in the history
…erence along with a Destination or destinationName (but the latter 2 are still mutually exclusive)
  • Loading branch information
markfisher committed Sep 13, 2010
1 parent bf0da16 commit 965b51d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

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;
Expand Down Expand Up @@ -71,17 +70,17 @@ protected String parseSource(Element element, ParserContext parserContext) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,33 @@ protected AbstractBeanDefinition parseConsumer(Element element, ParserContext pa
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -69,13 +69,7 @@ public void adapterWithConnectionFactoryAndDestinationName() {

@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)
Expand Down

0 comments on commit 965b51d

Please sign in to comment.