Removed MessageBusAware and MessageBusAwareBeanPostProcessor.

This commit is contained in:
Mark Fisher
2008-10-31 23:30:02 +00:00
parent 14d892e044
commit dae343a07f
7 changed files with 6 additions and 162 deletions

View File

@@ -1,28 +0,0 @@
/*
* Copyright 2002-2008 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.bus;
/**
* Interface to be implemented by classes which need access to the {@link MessageBus}.
*
* @author Marius Bogoevici
*/
public interface MessageBusAware {
public void setMessageBus(MessageBus messageBus);
}

View File

@@ -1,56 +0,0 @@
/*
* Copyright 2002-2008 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.bus;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.util.Assert;
/**
* A bean post processor which injects all {@link MessageBusAware} beans with a
* reference to the {@link MessageBus}.
*
* @author Marius Bogoevici
* @author Mark Fisher
*/
public class MessageBusAwareBeanPostProcessor implements BeanPostProcessor {
private final MessageBus messageBus;
public MessageBusAwareBeanPostProcessor(MessageBus messageBus) {
Assert.notNull(messageBus, "'messageBus' must not be null");
this.messageBus = messageBus;
}
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
return postProcessIfNecessary(bean);
}
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
return postProcessIfNecessary(bean);
}
private Object postProcessIfNecessary(Object bean) {
if (bean instanceof MessageBusAware) {
((MessageBusAware) bean).setMessageBus(this.messageBus);
}
return bean;
}
}

View File

@@ -24,7 +24,6 @@ import org.w3c.dom.Element;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
@@ -36,7 +35,6 @@ import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.core.task.TaskExecutor;
import org.springframework.integration.bus.ApplicationContextMessageBus;
import org.springframework.integration.bus.MessageBus;
import org.springframework.integration.bus.MessageBusAwareBeanPostProcessor;
import org.springframework.integration.channel.MessagePublishingErrorHandler;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor;
@@ -58,9 +56,6 @@ public class MessageBusParser extends AbstractSimpleBeanDefinitionParser {
public static final String TASK_SCHEDULER_BEAN_NAME = "taskScheduler";
public static final String MESSAGE_BUS_AWARE_POST_PROCESSOR_BEAN_NAME =
"internal.MessageBusAwareBeanPostProcessor";
private static final String MESSAGING_ANNOTATION_POST_PROCESSOR_BEAN_NAME =
"internal.MessagingAnnotationPostProcessor";
@@ -150,24 +145,16 @@ public class MessageBusParser extends AbstractSimpleBeanDefinitionParser {
* Adds extra post-processors to the context, to inject the objects configured by the MessageBus
*/
private void addPostProcessors(Element element, ParserContext parserContext) {
this.registerMessageBusAwarePostProcessor(parserContext);
if ("true".equals(element.getAttribute("enable-annotations").toLowerCase())) {
this.registerMessagingAnnotationPostProcessor(parserContext);
}
}
private void registerMessageBusAwarePostProcessor(ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MessageBusAwareBeanPostProcessor.class);
builder.addConstructorArgReference(MessageBusParser.MESSAGE_BUS_BEAN_NAME);
builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
parserContext.getRegistry().registerBeanDefinition(MESSAGE_BUS_AWARE_POST_PROCESSOR_BEAN_NAME, builder.getBeanDefinition());
}
private void registerMessagingAnnotationPostProcessor(ParserContext parserContext) {
BeanDefinition bd = new RootBeanDefinition(MessagingAnnotationPostProcessor.class);
BeanComponentDefinition bcd = new BeanComponentDefinition(
bd, MESSAGING_ANNOTATION_POST_PROCESSOR_BEAN_NAME);
parserContext.registerBeanComponent(bcd);
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MessagingAnnotationPostProcessor.class);
builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
parserContext.getRegistry().registerBeanDefinition(
MESSAGING_ANNOTATION_POST_PROCESSOR_BEAN_NAME, builder.getBeanDefinition());
}
}