org.springframework.beans.factory
Interface FactoryBean

All Known Implementing Classes:
ProxyFactoryBean, CommonsLogFactoryBean, ListFactoryBean, MapFactoryBean, MethodInvokingFactoryBean, PropertiesFactoryBean, ResourceFactoryBean, SetFactoryBean, LocalStatelessSessionProxyFactoryBean, SimpleRemoteStatelessSessionProxyFactoryBean, JndiObjectFactoryBean, LocalSessionFactoryBean, SqlMapFactoryBean, LocalPersistenceManagerFactoryBean, BurlapProxyFactoryBean, HessianProxyFactoryBean, JaxRpcPortProxyFactoryBean, LocalJaxRpcServiceFactoryBean, RmiProxyFactoryBean, TransactionProxyFactoryBean, JotmFactoryBean, WebSphereTransactionManagerFactoryBean, VelocityEngineFactoryBean

public interface FactoryBean

Interface to be implemented by objects used within a BeanFactory that are themselves factories. If a bean implements this interface, it is used as a factory, not directly as a bean.

NB: A bean that implements this interface cannot be used as a normal bean.

FactoryBeans can support singletons and prototypes.

Author:
Rod Johnson, Juergen Hoeller
Version: $Id: FactoryBean.java,v 1.7 2004/01/20 11:26:43 jhoeller Exp $
Since: March 08, 2003
See Also: BeanFactory

Method Summary
 ObjectgetObject()
          Return an instance (possibly shared or independent) of the object managed by this factory.
 ClassgetObjectType()
          Return the type of object that this FactoryBean creates, or null if not known in advance.
 booleanisSingleton()
          Is the bean managed by this factory a singleton or a prototype? That is, will getObject() always return the same object? The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory.

Method Detail

getObject

public Object getObject()
throws java.lang.Exception
Return an instance (possibly shared or independent) of the object managed by this factory. As with a BeanFactory, this allows support for both the Singleton and Prototype design pattern.
Returns: an instance of the bean (should never be null)
Throws:
Exception - in case of creation errors

getObjectType

public Class getObjectType()
Return the type of object that this FactoryBean creates, or null if not known in advance. This allows to check for specific types of beans without instantiating objects, e.g. on autowiring.

For a singleton, this can simply return getObject().getClass(), or even null, as autowiring will always check the actual objects for singletons. For prototypes, returning a meaningful type here is highly advisable, as autowiring will simply ignore them else.

Returns: the type of object that this FactoryBean creates, or null
See Also:
ListableBeanFactory.getBeansOfType(java.lang.Class,boolean,boolean)

isSingleton

public boolean isSingleton()
Is the bean managed by this factory a singleton or a prototype? That is, will getObject() always return the same object?

The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory.

Returns: if this bean is a singleton