diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/channel/NullChannel.java b/org.springframework.integration/src/main/java/org/springframework/integration/channel/NullChannel.java index 8492cdc702..71ca57ead3 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/channel/NullChannel.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/channel/NullChannel.java @@ -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. @@ -21,6 +21,7 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.beans.factory.BeanNameAware; import org.springframework.integration.core.Message; import org.springframework.integration.selector.MessageSelector; @@ -32,16 +33,19 @@ import org.springframework.integration.selector.MessageSelector; * * @author Mark Fisher */ -public class NullChannel implements PollableChannel { +public class NullChannel implements PollableChannel, BeanNameAware { - private Log logger = LogFactory.getLog(this.getClass()); + private final Log logger = LogFactory.getLog(this.getClass()); + + private volatile String beanName; - /** - * Always returns null. - */ + public void setBeanName(String beanName) { + this.beanName = beanName; + } + public String getName() { - return null; + return this.beanName; } public List> clear() { @@ -54,7 +58,7 @@ public class NullChannel implements PollableChannel { public Message receive() { if (logger.isDebugEnabled()) { - logger.debug("receive called on null-channel"); + logger.debug("receive called on null channel"); } return null; } @@ -65,7 +69,7 @@ public class NullChannel implements PollableChannel { public boolean send(Message message) { if (logger.isDebugEnabled()) { - logger.debug("message sent to null-channel: " + message); + logger.debug("message sent to null channel: " + message); } return true; } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/DefaultConfiguringBeanFactoryPostProcessor.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/DefaultConfiguringBeanFactoryPostProcessor.java index 2adf51f3af..ec4573c279 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/DefaultConfiguringBeanFactoryPostProcessor.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/DefaultConfiguringBeanFactoryPostProcessor.java @@ -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. @@ -33,7 +33,8 @@ import org.springframework.integration.context.IntegrationContextUtils; /** * A {@link BeanFactoryPostProcessor} implementation that provides default * beans for the error handling and task scheduling if those beans have not - * already been explicitly defined within the registry. + * already been explicitly defined within the registry. It also registers a + * single null channel with the bean name "nullChannel". * * @author Mark Fisher */ @@ -45,6 +46,7 @@ class DefaultConfiguringBeanFactoryPostProcessor implements BeanFactoryPostProce public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { if (beanFactory instanceof BeanDefinitionRegistry) { BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; + this.registerNullChannel(registry); this.registerErrorChannelIfNecessary(registry); this.registerTaskSchedulerIfNecessary(registry); } @@ -55,6 +57,22 @@ class DefaultConfiguringBeanFactoryPostProcessor implements BeanFactoryPostProce } } + /** + * Register a null channel in the given BeanDefinitionRegistry. The bean name is + * defined by the constant {@link IntegrationContextUtils#NULL_CHANNEL_BEAN_NAME}. + */ + private void registerNullChannel(BeanDefinitionRegistry registry) { + if (registry.isBeanNameInUse(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME)) { + throw new IllegalStateException("The bean name '" + + IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME + "' is reserved."); + } + RootBeanDefinition nullChannelDef = new RootBeanDefinition(); + nullChannelDef.setBeanClassName(IntegrationNamespaceUtils.BASE_PACKAGE + ".channel.NullChannel"); + BeanDefinitionHolder nullChannelHolder = new BeanDefinitionHolder( + nullChannelDef, IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME); + BeanDefinitionReaderUtils.registerBeanDefinition(nullChannelHolder, registry); + } + /** * Register an error channel in the given BeanDefinitionRegistry if not yet present. * The bean name for which this is checking is defined by the constant diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/context/IntegrationContextUtils.java b/org.springframework.integration/src/main/java/org/springframework/integration/context/IntegrationContextUtils.java index 15860ab5dd..96a9dc3971 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/context/IntegrationContextUtils.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/context/IntegrationContextUtils.java @@ -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. @@ -36,6 +36,8 @@ public abstract class IntegrationContextUtils { public static final String ERROR_CHANNEL_BEAN_NAME = "errorChannel"; + public static final String NULL_CHANNEL_BEAN_NAME = "nullChannel"; + public static final String DEFAULT_POLLER_METADATA_BEAN_NAME = "org.springframework.integration.context.defaultPollerMetadata";