private void bindBeanValue(final ExecutionContext executionContext, Fragment source) { final BeanContext beanContext = executionContext.getBeanContext(); Object bean = null; if(wireBeanId != null) { bean = beanContext.getBean(wireBeanId); } if(bean != null) { if(!BeanWiringObserver.isMatchingBean(bean, wireBeanType, wireBeanAnnotation)) { bean = null; } } if(bean == null) { if(logger.isDebugEnabled()) { logger.debug("Registering bean ADD wiring observer for wiring bean '" + wireBeanId + "' onto target bean '" + beanId.getName() + "'."); } // Register the observer which looks for the creation of the selected bean via its beanIdName... beanContext.addObserver(wireByBeanIdObserver); } else { populateAndSetPropertyValue(bean, beanContext, wireBeanId, executionContext, source); } }
public void onBeanLifecycleEvent(BeanContextLifecycleEvent event) { BeanId beanId = event.getBeanId(); BeanLifecycle lifecycle = event.getLifecycle(); if(lifecycle == BeanLifecycle.ADD) { if(watchedBeanId != null && beanId != watchedBeanId) { return; } Object bean = event.getBean(); if(!isMatchingBean(bean, watchedBeanType, watchedBeanAnnotation)) { return; } ExecutionContext executionContext = event.getExecutionContext(); populator.populateAndSetPropertyValue(bean, executionContext.getBeanContext(), watchingBeanId, executionContext, event.getSource()); } else if(beanId == watchingBeanId && lifecycle == BeanLifecycle.REMOVE) { BeanContext beanContext = event.getExecutionContext().getBeanContext(); beanContext.removeObserver(this); // Need to remove the watched bean from the bean context too because it's lifecycle is associated // with the lifecycle of the watching bean, which has been removed... if(watchedBeanId != null) { beanContext.removeBean(watchedBeanId, event.getSource()); } } }