This commit is contained in:
Mark Fisher
2009-06-29 20:30:27 +00:00
parent 39a6beefef
commit 914dfed1ef
3 changed files with 34 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@@ -43,8 +43,12 @@ public class PointToPointChannelParser extends AbstractChannelParser {
Element queueElement = null;
if ((queueElement = DomUtils.getChildElementByTagName(element, "queue")) != null) {
builder = BeanDefinitionBuilder.genericBeanDefinition(CHANNEL_PACKAGE + ".QueueChannel");
this.parseQueueCapacity(builder, queueElement);
this.parseQueueRef(builder, queueElement);
boolean hasCapacity = this.parseQueueCapacity(builder, queueElement);
boolean hasQueueRef = this.parseQueueRef(builder, queueElement);
if (hasCapacity && hasQueueRef) {
parserContext.getReaderContext().error("The 'capacity' attribute is not allowed" +
" when providing a 'ref' to a custom queue.", element);
}
}
else if ((queueElement = DomUtils.getChildElementByTagName(element, "priority-queue")) != null) {
builder = BeanDefinitionBuilder.genericBeanDefinition(CHANNEL_PACKAGE + ".PriorityChannel");
@@ -78,17 +82,22 @@ public class PointToPointChannelParser extends AbstractChannelParser {
// rely on the default for round-robin
}
private void parseQueueCapacity(BeanDefinitionBuilder builder, Element queueElement) {
private boolean parseQueueCapacity(BeanDefinitionBuilder builder, Element queueElement) {
String capacity = queueElement.getAttribute("capacity");
if (StringUtils.hasText(capacity)) {
builder.addConstructorArgValue(capacity);
return true;
}
return false;
}
private void parseQueueRef(BeanDefinitionBuilder builder, Element queueElement) {
private boolean parseQueueRef(BeanDefinitionBuilder builder, Element queueElement) {
String queueRef = queueElement.getAttribute("ref");
if (StringUtils.hasText(queueRef)){
builder.addConstructorArgReference(queueRef);
return true;
}
return false;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@@ -20,6 +20,7 @@ import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@@ -33,6 +34,7 @@ import org.springframework.core.task.TaskExecutor;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.channel.PollableChannel;
import org.springframework.integration.channel.PublishSubscribeChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.config.TestChannelInterceptor;
import org.springframework.integration.core.Message;
import org.springframework.integration.core.MessageChannel;
@@ -115,6 +117,17 @@ public class ChannelParserTests {
assertEquals(taskExecutorBean, innerExecutor);
}
@Test
public void channelWithCustomQueue() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"channelParserTests.xml", this.getClass());
Object customQueue = context.getBean("customQueue");
Object channelWithCustomQueue = context.getBean("channelWithCustomQueue");
assertEquals(QueueChannel.class, channelWithCustomQueue.getClass());
Object actualQueue = new DirectFieldAccessor(channelWithCustomQueue).getPropertyValue("queue");
assertSame(customQueue, actualQueue);
}
@Test
public void testDatatypeChannelWithCorrectType() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("channelParserTests.xml", this

View File

@@ -14,6 +14,12 @@
<channel id="failOverChannel" dispatcher="failover"/>
<channel id="channelWithCustomQueue">
<queue ref="customQueue"/>
</channel>
<beans:bean id="customQueue" class="java.util.concurrent.LinkedBlockingQueue"/>
<publish-subscribe-channel id="publishSubscribeChannel" />
<publish-subscribe-channel id="publishSubscribeChannelWithTaskExecutorRef"