protected Object getObjectForBeanInstance(
Object beanInstance, String name, String beanName, @Nullable RootBeanDefinition mbd) {
// Don"t let calling code try to dereference the factory if the bean isn"t a factory.
if (BeanFactoryUtils.isFactoryDereference(name) && !(beanInstance instanceof FactoryBean)) {
throw new BeanIsNotAFactoryException(transformedBeanName(name), beanInstance.getClass());
}
// Now we have the bean instance, which may be a normal bean or a FactoryBean.
// If it"s a FactoryBean, we use it to create a bean instance, unless the
// caller actually wants a reference to the factory.
if (!(beanInstance instanceof FactoryBean) || BeanFactoryUtils.isFactoryDereference(name)) {
return beanInstance;
}
//BeanBean
//BeanBean
Object object = null;
if (mbd == null) {
//BeanBean
object = getCachedObjectForFactoryBean(beanName);
}
//BeanBean
if (object == null) {
// Return bean instance from factory.
FactoryBean<?> factory = (FactoryBean<?>) beanInstance;
// Caches object obtained from FactoryBean if it is a singleton.
//BeanBean
if (mbd == null && containsBeanDefinition(beanName)) {
//Bean
mbd = getMergedLocalBeanDefinition(beanName);
}
//BeanBean
//BeanBean
boolean synthetic = (mbd != null && mbd.isSynthetic());
//FactoryBeanRegistrySupportgetObjectFromFactoryBean
//BeanBean
object = getObjectFromFactoryBean(factory, beanName, !synthetic);
}
return object;
}
if (BeanFactoryUtils.isFactoryDereference(name) && !(beanInstance instanceof FactoryBean)) {
throw new BeanIsNotAFactoryException(transformedBeanName(name), beanInstance.getClass());
}
if (!(beanInstance instanceof FactoryBean) || BeanFactoryUtils.isFactoryDereference(name)) {
return beanInstance;
}
if