Support base class for singleton registries which need to handle
| Method from org.springframework.beans.factory.support.FactoryBeanRegistrySupport Detail: |
protected Object getCachedObjectForFactoryBean(String beanName) {
Object object = this.factoryBeanObjectCache.get(beanName);
return (object != NULL_OBJECT ? object : null);
}
Obtain an object to expose from the given FactoryBean, if available
in cached form. Quick check for minimal synchronization. |
protected FactoryBean getFactoryBean(String beanName,
Object beanInstance) throws BeansException {
if (!(beanInstance instanceof FactoryBean)) {
throw new BeanCreationException(beanName,
"Bean instance of type [" + beanInstance.getClass() + "] is not a FactoryBean");
}
return (FactoryBean) beanInstance;
}
Get a FactoryBean for the given bean if possible. |
protected Object getObjectFromFactoryBean(FactoryBean factory,
String beanName,
boolean shouldPostProcess) {
if (factory.isSingleton() && containsSingleton(beanName)) {
synchronized (getSingletonMutex()) {
Object object = this.factoryBeanObjectCache.get(beanName);
if (object == null) {
object = doGetObjectFromFactoryBean(factory, beanName, shouldPostProcess);
this.factoryBeanObjectCache.put(beanName, (object != null ? object : NULL_OBJECT));
}
return (object != NULL_OBJECT ? object : null);
}
}
else {
return doGetObjectFromFactoryBean(factory, beanName, shouldPostProcess);
}
}
Obtain an object to expose from the given FactoryBean. |
protected Class getTypeForFactoryBean(FactoryBean factoryBean) {
try {
return factoryBean.getObjectType();
}
catch (Throwable ex) {
// Thrown from the FactoryBean's getObjectType implementation.
logger.warn("FactoryBean threw exception from getObjectType, despite the contract saying " +
"that it should return null if the type of its object cannot be determined yet", ex);
return null;
}
}
Determine the type for the given FactoryBean. |
protected Object postProcessObjectFromFactoryBean(Object object,
String beanName) throws BeansException {
return object;
}
Post-process the given object that has been obtained from the FactoryBean.
The resulting object will get exposed for bean references.
The default implementation simply returns the given object as-is.
Subclasses may override this, for example, to apply post-processors. |
protected void removeSingleton(String beanName) {
super.removeSingleton(beanName);
this.factoryBeanObjectCache.remove(beanName);
}
Overridden to clear the FactoryBean object cache as well. |