FactoryBean implementations that
creates a singleton or a prototype object, depending on a flag.
If the "singleton" flag is true (the default),
this class will create the object that it creates exactly once
on initialization and subsequently return said singleton instance
on all calls to the getObject() method.
Else, this class will create a new instance every time the
getObject() method is invoked. Subclasses are responsible
for implementing the abstract createInstance() template
method to actually create the object(s) to expose.
setSingleton, createInstance()
| Modifier and Type | Class and Description |
|---|---|
| private class | AbstractFactoryBean.
Reflective InvocationHandler for lazy access to the actual singleton object. |
| Modifier and Type | Field and Description |
|---|---|
| private ClassLoader | |
| private BeanFactory | |
| private T | |
| private boolean | |
| protected final Log | logger
Logger available to subclasses. |
| private boolean | |
| private T |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | afterPropertiesSet()
Implements org. Eagerly create the singleton instance, if necessary. |
| protected abstract T | Returns: the object returned by this factoryTemplate method that subclasses must override to construct the object returned by this factory. |
| public void | destroy()
Implements org. Destroy the singleton instance, if any. |
| protected void | destroyInstance(T
the singleton instance, as returned by
instance)createInstance()Callback for destroying a singleton instance. |
| protected BeanFactory | |
| protected TypeConverter | getBeanTypeConverter()
Obtain a bean type converter from the BeanFactory that this bean runs in. This is typically a fresh instance for each call, since TypeConverters are usually not thread-safe. |
| private T | getEarlySingletonInstance()
Determine an 'early singleton' instance, exposed in case of a circular reference. |
| protected Class | Returns: the interfaces to use for 'early singletons', ornull to indicate a FactoryBeanNotInitializedExceptionReturn an array of interfaces that a singleton object exposed by this FactoryBean is supposed to implement, for use with an 'early singleton proxy' that will be exposed in case of a circular reference. |
| public final T | getObject()
Implements org. Expose the singleton instance or create a new prototype instance. |
| public abstract Class | getObjectType()
Redeclares org. This abstract method declaration mirrors the method in the FactoryBean interface, for a consistent offering of abstract template methods. |
| private T | Returns: the singleton instance that this FactoryBean holdsExpose the singleton instance (for access through the 'early singleton' proxy). |
| public boolean | isSingleton()
Overrides default org. Is the object managed by this factory a singleton? |
| public void | setBeanClassLoader(ClassLoader
the owning class loader classLoader)Implements org. Callback that supplies the bean |
| public void | setBeanFactory(BeanFactory
owning BeanFactory (never beanFactory)null).
The bean can immediately call methods on the factory.Implements org. Callback that supplies the owning factory to a bean instance. |
| public void | setSingleton(boolean singleton)
Set if a singleton should be created, or a new object on each request otherwise. |
| beanClassLoader | back to summary |
|---|---|
| private ClassLoader beanClassLoader
| |
| beanFactory | back to summary |
|---|---|
| private BeanFactory beanFactory
| |
| earlySingletonInstance | back to summary |
|---|---|
| private T earlySingletonInstance
| |
| initialized | back to summary |
|---|---|
| private boolean initialized | |
| logger | back to summary |
|---|---|
| protected final Log logger Logger available to subclasses. | |
| singleton | back to summary |
|---|---|
| private boolean singleton | |
| singletonInstance | back to summary |
|---|---|
| private T singletonInstance
| |
| AbstractFactoryBean | back to summary |
|---|---|
| public AbstractFactoryBean() | |
| afterPropertiesSet | back to summary |
|---|---|
| public void afterPropertiesSet() throws Exception Implements org. Eagerly create the singleton instance, if necessary.
| |
| createInstance | back to summary |
|---|---|
| protected abstract T createInstance() throws Exception Template method that subclasses must override to construct the object returned by this factory. Invoked on initialization of this FactoryBean in case of
a singleton; else, on each
| |
| destroy | back to summary |
|---|---|
| public void destroy() throws Exception Implements org. Destroy the singleton instance, if any.
| |
| destroyInstance | back to summary |
|---|---|
| protected void destroyInstance(T instance) throws Exception Callback for destroying a singleton instance. Subclasses may override this to destroy the previously created instance. The default implementation is empty.
| |
| getBeanFactory | back to summary |
|---|---|
| protected BeanFactory getBeanFactory() Return the BeanFactory that this bean runs in.
| |
| getBeanTypeConverter | back to summary |
|---|---|
| protected TypeConverter getBeanTypeConverter() Obtain a bean type converter from the BeanFactory that this bean runs in. This is typically a fresh instance for each call, since TypeConverters are usually not thread-safe. Falls back to a SimpleTypeConverter when not running in a BeanFactory. | |
| getEarlySingletonInstance | back to summary |
|---|---|
| private T getEarlySingletonInstance() throws Exception Determine an 'early singleton' instance, exposed in case of a circular reference. Not called in a non-circular scenario.
| |
| getEarlySingletonInterfaces | back to summary |
|---|---|
| protected Class Return an array of interfaces that a singleton object exposed by this FactoryBean is supposed to implement, for use with an 'early singleton proxy' that will be exposed in case of a circular reference. The default implementation returns this FactoryBean's object type,
provided that it is an interface, or
| |
| getObject | back to summary |
|---|---|
| public final T getObject() throws Exception Implements org. Expose the singleton instance or create a new prototype instance.
| |
| getObjectType | back to summary |
|---|---|
| public abstract Class Redeclares org. This abstract method declaration mirrors the method in the FactoryBean interface, for a consistent offering of abstract template methods.
| |
| getSingletonInstance | back to summary |
|---|---|
| private T getSingletonInstance() throws IllegalStateException Expose the singleton instance (for access through the 'early singleton' proxy).
| |
| isSingleton | back to summary |
|---|---|
| public boolean isSingleton() Overrides default org. Doc from org. Is the object managed by this factory a singleton? That is,
will Note If a FactoryBean indicates to hold a singleton object,
the object returned from The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory; usually, it has to be defined as singleton there. Note This method returning The default implementation returns
| |
| setBeanClassLoader | back to summary |
|---|---|
| public void setBeanClassLoader(ClassLoader classLoader) Implements org. Doc from org. Callback that supplies the bean Invoked after the population of normal bean properties but
before an initialization callback such as
| |
| setBeanFactory | back to summary |
|---|---|
| public void setBeanFactory(BeanFactory beanFactory) Implements org. Doc from org. Callback that supplies the owning factory to a bean instance. Invoked after the population of normal bean properties
but before an initialization callback such as
| |
| setSingleton | back to summary |
|---|---|
| public void setSingleton(boolean singleton) Set if a singleton should be created, or a new object on each request
otherwise. Default is | |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public Object | invoke(Object
the proxy instance that the method was invoked on proxy, Method the method, Object[] Method instance corresponding to
the interface method invoked on the proxy instance. The declaring
class of the Method object will be the interface that
the method was declared in, which may be a superinterface of the
proxy interface that the proxy class inherits the method through.an array of objects containing the values of the
arguments passed in the method invocation on the proxy instance,
or args)null if interface method takes no arguments.
Arguments of primitive types are wrapped in instances of the
appropriate primitive wrapper class, such as
java.lang.Integer or java.lang.Boolean.Implements java. Processes a method invocation on a proxy instance and returns the result. |
| EarlySingletonInvocationHandler | back to summary |
|---|---|
| private EarlySingletonInvocationHandler() | |
| invoke | back to summary |
|---|---|
| public Object invoke(Object proxy, Method method, Object[] args) throws Throwable Implements java. Doc from java. Processes a method invocation on a proxy instance and returns the result. This method will be invoked on an invocation handler when a method is invoked on a proxy instance that it is associated with.
| |