/**
* Return the (raw) singleton object registered under the given name.
* <p>Checks already instantiated singletons and also allows for an early
* reference to a currently created singleton (resolving a circular reference).
* @param beanName the name of the bean to look for
* @param allowEarlyReference whether early references should be created or not
* @return the registered singleton object, or <code>null</code> if none found
*/
protected
Object getSingleton(String beanName,
boolean
allowEarlyReference) {
Object singletonObject =
this
.singletonObjects.get(beanName);
if
(singletonObject ==
null
) {
synchronized
(
this
.singletonObjects) {
singletonObject =
this
.earlySingletonObjects.get(beanName);
if
(singletonObject ==
null
&& allowEarlyReference) {
ObjectFactory singletonFactory =
this
.singletonFactories.get(beanName);
if
(singletonFactory !=
null
) {
singletonObject = singletonFactory.getObject();
this
.earlySingletonObjects.put(beanName, singletonObject);
this
.singletonFactories.remove(beanName);
}
}
}
}
return
(singletonObject != NULL_OBJECT ? singletonObject :
null
);
}