org.springframework.beans.factory
Interface FactoryBean

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

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.

Since:
March 08, 2003
Version:
$Id: FactoryBean.java,v 1.8 2004/03/18 02:46:07 trisberg Exp $
Author:
Rod Johnson, Juergen Hoeller
See Also:
BeanFactory

Method Summary
 java.lang.Object getObject()
          Return an instance (possibly shared or independent) of the object managed by this factory.
 java.lang.Class getObjectType()
          Return the type of object that this FactoryBean creates, or null if not known in advance.
 boolean isSingleton()
          Is the bean managed by this factory a singleton or a prototype? That is, will getObject() always return the same object?
 

Method Detail

getObject

public java.lang.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:
java.lang.Exception - in case of creation errors

getObjectType

public java.lang.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


Copyright (C) 2003-2004 The Spring Framework Project.