AMQP-160: adjust binding parser so values can be externalized

This commit is contained in:
Dave Syer
2011-04-20 18:10:33 +01:00
parent 96de0bf559
commit ecdb0d5717
4 changed files with 13 additions and 10 deletions

View File

@@ -18,6 +18,7 @@ import java.util.Collections;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Binding.DestinationType;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.beans.factory.config.TypedStringValue;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
@@ -41,14 +42,14 @@ public class DirectExchangeParser extends AbstractExchangeParser {
protected AbstractBeanDefinition parseBinding(String exchangeName, Element binding,
ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(Binding.class);
builder.addConstructorArgValue(binding.getAttribute(BINDING_QUEUE_ATTR));
builder.addConstructorArgValue(new TypedStringValue(binding.getAttribute(BINDING_QUEUE_ATTR)));
builder.addConstructorArgValue(DestinationType.EXCHANGE);
builder.addConstructorArgValue(exchangeName);
builder.addConstructorArgValue(new TypedStringValue(exchangeName));
String bindingKey = binding.getAttribute(BINDING_KEY_ATTR);
if (!StringUtils.hasText(bindingKey)) {
bindingKey = "";
}
builder.addConstructorArgValue(bindingKey);
builder.addConstructorArgValue(new TypedStringValue(bindingKey));
builder.addConstructorArgValue(Collections.<String, Object>emptyMap());
return builder.getBeanDefinition();
}

View File

@@ -18,6 +18,7 @@ import java.util.Collections;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Binding.DestinationType;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.beans.factory.config.TypedStringValue;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
@@ -37,9 +38,9 @@ public class FanoutExchangeParser extends AbstractExchangeParser {
@Override
protected AbstractBeanDefinition parseBinding(String exchangeName, Element binding, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(Binding.class);
builder.addConstructorArgValue(binding.getAttribute(BINDING_QUEUE_ATTR));
builder.addConstructorArgValue(new TypedStringValue(binding.getAttribute(BINDING_QUEUE_ATTR)));
builder.addConstructorArgValue(DestinationType.EXCHANGE);
builder.addConstructorArgValue(exchangeName);
builder.addConstructorArgValue(new TypedStringValue(exchangeName));
builder.addConstructorArgValue("");
builder.addConstructorArgValue(Collections.<String, Object>emptyMap());
return builder.getBeanDefinition();

View File

@@ -40,9 +40,9 @@ public class HeadersExchangeParser extends AbstractExchangeParser {
@Override
protected AbstractBeanDefinition parseBinding(String exchangeName, Element binding, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(Binding.class);
builder.addConstructorArgValue(binding.getAttribute(BINDING_QUEUE_ATTR));
builder.addConstructorArgValue(new TypedStringValue(binding.getAttribute(BINDING_QUEUE_ATTR)));
builder.addConstructorArgValue(DestinationType.EXCHANGE);
builder.addConstructorArgValue(exchangeName);
builder.addConstructorArgValue(new TypedStringValue(exchangeName));
builder.addConstructorArgValue("");
ManagedMap<TypedStringValue, TypedStringValue> map = new ManagedMap<TypedStringValue, TypedStringValue>();
String key = binding.getAttribute("key");

View File

@@ -21,6 +21,7 @@ import java.util.Collections;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Binding.DestinationType;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.config.TypedStringValue;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
@@ -42,10 +43,10 @@ public class TopicExchangeParser extends AbstractExchangeParser {
@Override
protected AbstractBeanDefinition parseBinding(String exchangeName, Element binding, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(Binding.class);
builder.addConstructorArgValue(binding.getAttribute(BINDING_QUEUE_ATTR));
builder.addConstructorArgValue(new TypedStringValue(binding.getAttribute(BINDING_QUEUE_ATTR)));
builder.addConstructorArgValue(DestinationType.EXCHANGE);
builder.addConstructorArgValue(exchangeName);
builder.addConstructorArgValue(binding.getAttribute(BINDING_PATTERN_ATTR));
builder.addConstructorArgValue(new TypedStringValue(exchangeName));
builder.addConstructorArgValue(new TypedStringValue(binding.getAttribute(BINDING_PATTERN_ATTR)));
builder.addConstructorArgValue(Collections.<String, Object>emptyMap());
return builder.getBeanDefinition();
}