use of org.springframework.beans.factory.BeanNameAware in project spring-integration by spring-projects.
the class AbstractSimpleMessageHandlerFactoryBean method createHandlerInternal.
protected final H createHandlerInternal() {
synchronized (this.initializationMonitor) {
if (this.initialized) {
// There was a problem when this method was called already
return null;
}
this.handler = createHandler();
if (this.handler instanceof ApplicationContextAware && this.applicationContext != null) {
((ApplicationContextAware) this.handler).setApplicationContext(this.applicationContext);
}
if (this.handler instanceof BeanFactoryAware && getBeanFactory() != null) {
((BeanFactoryAware) this.handler).setBeanFactory(getBeanFactory());
}
if (this.handler instanceof BeanNameAware && this.beanName != null) {
((BeanNameAware) this.handler).setBeanName(this.beanName);
}
if (this.handler instanceof ApplicationEventPublisherAware && this.applicationEventPublisher != null) {
((ApplicationEventPublisherAware) this.handler).setApplicationEventPublisher(this.applicationEventPublisher);
}
if (this.handler instanceof MessageProducer && this.outputChannel != null) {
((MessageProducer) this.handler).setOutputChannel(this.outputChannel);
}
Object actualHandler = extractTarget(this.handler);
if (actualHandler == null) {
actualHandler = this.handler;
}
if (actualHandler instanceof IntegrationObjectSupport) {
if (this.componentName != null) {
((IntegrationObjectSupport) actualHandler).setComponentName(this.componentName);
}
if (this.channelResolver != null) {
((IntegrationObjectSupport) actualHandler).setChannelResolver(this.channelResolver);
}
}
if (!CollectionUtils.isEmpty(this.adviceChain)) {
if (actualHandler instanceof AbstractReplyProducingMessageHandler) {
((AbstractReplyProducingMessageHandler) actualHandler).setAdviceChain(this.adviceChain);
} else if (this.logger.isDebugEnabled()) {
String name = this.componentName;
if (name == null && actualHandler instanceof NamedComponent) {
name = ((NamedComponent) actualHandler).getComponentName();
}
this.logger.debug("adviceChain can only be set on an AbstractReplyProducingMessageHandler" + (name == null ? "" : (", " + name)) + ".");
}
}
if (this.async != null) {
if (actualHandler instanceof AbstractMessageProducingHandler) {
((AbstractMessageProducingHandler) actualHandler).setAsync(this.async);
}
}
if (this.handler instanceof Orderable && this.order != null) {
((Orderable) this.handler).setOrder(this.order);
}
this.initialized = true;
}
if (this.handler instanceof InitializingBean) {
try {
((InitializingBean) this.handler).afterPropertiesSet();
} catch (Exception e) {
throw new BeanInitializationException("failed to initialize MessageHandler", e);
}
}
return this.handler;
}
use of org.springframework.beans.factory.BeanNameAware in project spring-integration by spring-projects.
the class TestUtils method registerBean.
private static void registerBean(String beanName, Object bean, BeanFactory beanFactory) {
Assert.notNull(beanName, "bean name must not be null");
ConfigurableListableBeanFactory configurableListableBeanFactory = null;
if (beanFactory instanceof ConfigurableListableBeanFactory) {
configurableListableBeanFactory = (ConfigurableListableBeanFactory) beanFactory;
} else if (beanFactory instanceof GenericApplicationContext) {
configurableListableBeanFactory = ((GenericApplicationContext) beanFactory).getBeanFactory();
}
if (bean instanceof BeanNameAware) {
((BeanNameAware) bean).setBeanName(beanName);
}
if (bean instanceof BeanFactoryAware) {
((BeanFactoryAware) bean).setBeanFactory(beanFactory);
}
if (bean instanceof InitializingBean) {
try {
((InitializingBean) bean).afterPropertiesSet();
} catch (Exception e) {
throw new FatalBeanException("failed to register bean with test context", e);
}
}
// NOSONAR false positive
configurableListableBeanFactory.registerSingleton(beanName, bean);
}
Aggregations