Publisher annotation interceptor now delegates to a ChannelResolver instance rather than a ChannelRegistry.

This commit is contained in:
Mark Fisher
2008-10-13 02:03:31 +00:00
parent b0c809cac7
commit 8419b48dcd
7 changed files with 54 additions and 81 deletions

View File

@@ -23,7 +23,7 @@ import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.support.AopUtils;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.integration.channel.ChannelRegistry;
import org.springframework.integration.channel.ChannelResolver;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.util.Assert;
@@ -39,17 +39,17 @@ public class AnnotationAwareMessagePublishingInterceptor extends MessagePublishi
private String channelAttributeName;
private ChannelRegistry channelRegistry;
private ChannelResolver channelResolver;
public AnnotationAwareMessagePublishingInterceptor(Class<? extends Annotation> publisherAnnotationType,
String channelAttributeName, ChannelRegistry channelRegistry) {
String channelAttributeName, ChannelResolver channelResolver) {
Assert.notNull(publisherAnnotationType, "'publisherAnnotationType' must not be null");
Assert.notNull(channelAttributeName, "'channelAttributeName' must not be null");
Assert.notNull(channelRegistry, "'channelRegistry' must not be null");
Assert.notNull(channelResolver, "'channelResolver' must not be null");
this.publisherAnnotationType = publisherAnnotationType;
this.channelAttributeName = channelAttributeName;
this.channelRegistry = channelRegistry;
this.channelResolver = channelResolver;
}
@@ -57,7 +57,7 @@ public class AnnotationAwareMessagePublishingInterceptor extends MessagePublishi
protected MessageChannel resolveChannel(MethodInvocation invocation) {
String channelName = this.extractAnnotationValue(invocation, this.channelAttributeName, String.class);
if (channelName != null) {
MessageChannel channel = this.channelRegistry.lookupChannel(channelName);
MessageChannel channel = this.channelResolver.resolveChannelName(channelName);
if (channel != null) {
return channel;
}

View File

@@ -23,7 +23,7 @@ import org.aopalliance.aop.Advice;
import org.springframework.aop.Pointcut;
import org.springframework.aop.support.AbstractPointcutAdvisor;
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
import org.springframework.integration.channel.ChannelRegistry;
import org.springframework.integration.channel.ChannelResolver;
import org.springframework.util.Assert;
/**
@@ -42,18 +42,18 @@ public class PublisherAnnotationAdvisor extends AbstractPointcutAdvisor {
private AnnotationMatchingPointcut pointcut;
public PublisherAnnotationAdvisor(ChannelRegistry channelRegistry) {
this(Publisher.class, "channel", channelRegistry);
public PublisherAnnotationAdvisor(ChannelResolver channelResolver) {
this(Publisher.class, "channel", channelResolver);
}
public PublisherAnnotationAdvisor(Class<? extends Annotation> publisherAnnotationType, String channelNameAttribute,
ChannelRegistry channelRegistry) {
public PublisherAnnotationAdvisor(Class<? extends Annotation> publisherAnnotationType,
String channelNameAttribute, ChannelResolver channelResolver) {
Assert.notNull(publisherAnnotationType, "'publisherAnnotationType' must not be null");
Assert.notNull(channelNameAttribute, "'channelNameAttribute' must not be null");
Assert.notNull(channelRegistry, "'channelRegistry' must not be null");
Assert.notNull(channelResolver, "'channelResolver' must not be null");
this.pointcut = AnnotationMatchingPointcut.forMethodAnnotation(publisherAnnotationType);
this.advice = new AnnotationAwareMessagePublishingInterceptor(publisherAnnotationType, channelNameAttribute,
channelRegistry);
this.advice = new AnnotationAwareMessagePublishingInterceptor(
publisherAnnotationType, channelNameAttribute, channelResolver);
}

View File

@@ -26,11 +26,13 @@ import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.integration.aop.Publisher;
import org.springframework.integration.aop.PublisherAnnotationAdvisor;
import org.springframework.integration.channel.ChannelRegistry;
import org.springframework.integration.channel.BeanFactoryChannelResolver;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
@@ -40,19 +42,23 @@ import org.springframework.util.ReflectionUtils;
*
* @author Mark Fisher
*/
public class PublisherAnnotationPostProcessor implements BeanPostProcessor, BeanClassLoaderAware {
public class PublisherAnnotationPostProcessor implements BeanPostProcessor, BeanFactoryAware, BeanClassLoaderAware {
private volatile Class<? extends Annotation> publisherAnnotationType = Publisher.class;
private volatile String channelNameAttribute = "channel";
private ChannelRegistry channelRegistry;
private volatile Advisor advisor;
private Advisor advisor;
private volatile BeanFactory beanFactory;
private ClassLoader beanClassLoader;
private volatile ClassLoader beanClassLoader;
public void setBeanFactory(BeanFactory beanFactory) {
this.beanFactory = beanFactory;
}
public void setBeanClassLoader(ClassLoader beanClassLoader) {
Assert.notNull(beanClassLoader, "'beanClassLoader' must not be null");
this.beanClassLoader = beanClassLoader;
@@ -68,17 +74,10 @@ public class PublisherAnnotationPostProcessor implements BeanPostProcessor, Bean
this.channelNameAttribute = channelNameAttribute;
}
public void setChannelRegistry(ChannelRegistry channelRegistry) {
Assert.notNull(channelRegistry, "'channelRegistry' must not be null");
this.channelRegistry = channelRegistry;
}
private void createAdvisor() {
if (this.channelRegistry == null) {
throw new IllegalStateException("'channelRegistry' is required");
}
Assert.state(this.beanFactory != null, "BeanFactory is required");
this.advisor = new PublisherAnnotationAdvisor(this.publisherAnnotationType, this.channelNameAttribute,
this.channelRegistry);
new BeanFactoryChannelResolver(this.beanFactory));
}
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {

View File

@@ -178,10 +178,7 @@ public class MessageBusParser extends AbstractSimpleBeanDefinitionParser {
private void registerPublisherPostProcessor(ParserContext parserContext) {
BeanDefinition bd = new RootBeanDefinition(PublisherAnnotationPostProcessor.class);
bd.getPropertyValues().addPropertyValue("channelRegistry",
new RuntimeBeanReference(MessageBusParser.MESSAGE_BUS_BEAN_NAME));
BeanComponentDefinition bcd = new BeanComponentDefinition(
bd, PUBLISHER_ANNOTATION_POST_PROCESSOR_BEAN_NAME);
BeanComponentDefinition bcd = new BeanComponentDefinition(bd, PUBLISHER_ANNOTATION_POST_PROCESSOR_BEAN_NAME);
parserContext.registerBeanComponent(bcd);
}