org.springframework.beans.factory.support
Class AbstractBeanFactory

Direct Known Subclasses:
DefaultListableBeanFactory

public abstract class AbstractBeanFactory
implements AutowireCapableBeanFactory, ConfigurableBeanFactory

Abstract superclass that makes implementing a BeanFactory very easy.

This class uses the Template Method design pattern. Subclasses must implement only the getBeanDefinition(name) method.

This class handles resolution of runtime bean references, FactoryBean dereferencing, and management of collection properties. It also allows for management of a bean factory hierarchy, implementing the HierarchicalBeanFactory interface.

Supports "inner bean definitions": Singleton flags and names of such "inner beans" are always ignored: Inner beans are anonymous prototypes.

Author:
Rod Johnson, Juergen Hoeller
Version: $Id: AbstractBeanFactory.java,v 1.46 2004/02/11 10:50:06 jhoeller Exp $
Since: 15 April 2001

Field Summary
 final static StringFACTORY_BEAN_PREFIX
          Used to dereference a FactoryBean and distinguish it from beans created by the factory.

Constructor Summary
AbstractBeanFactory()
          Create a new AbstractBeanFactory.
AbstractBeanFactory(BeanFactory parentBeanFactory)
          Create a new AbstractBeanFactory with the given parent.

Method Summary
 voidaddBeanPostProcessor(BeanPostProcessor beanPostProcessor)
           
 ObjectapplyBeanPostProcessorsAfterInitialization(Object bean, String name)
           
 ObjectapplyBeanPostProcessorsBeforeInitialization(Object bean, String name)
           
 Objectautowire(Class beanClass, int autowireMode, boolean dependencyCheck)
           
 voidautowireBeanProperties(Object existingBean, int autowireMode, boolean dependencyCheck)
           
 booleancontainsBean(String name)
           
 voiddestroySingletons()
           
 String[]getAliases(String name)
           
 ObjectgetBean(String name)
          Return the bean with the given name, checking the parent bean factory if not found.
 ObjectgetBean(String name, Class requiredType)
           
 abstract AbstractBeanDefinitiongetBeanDefinition(String beanName)
          Return the bean definition for the given bean name.
 ListgetBeanPostProcessors()
          Return the list of BeanPostProcessors that will get applied to beans created with this factory.
 ConstructorArgumentValuesgetConstructorArgumentValues(String beanName)
           
 MapgetCustomEditors()
          Return the map of custom editors, with Classes as keys and PropertyEditors as values.
 SetgetIgnoredDependencyTypes()
          Return the set of classes that will get ignored for autowiring.
 RootBeanDefinitiongetMergedBeanDefinition(String beanName, boolean includingAncestors)
          Return a RootBeanDefinition, even by traversing parent if the parameter is a child definition.
 BeanFactorygetParentBeanFactory()
           
 MutablePropertyValuesgetPropertyValues(String beanName)
           
 String[]getSingletonNames(Class type)
          Return the names of beans in the singleton cache that match the given object type (including subclasses).
 voidignoreDependencyType(Class type)
           
 booleanisSingleton(String name)
           
 voidregisterAlias(String beanName, String alias)
           
 voidregisterCustomEditor(Class requiredType, PropertyEditor propertyEditor)
           
 voidregisterSingleton(String beanName, Object singletonObject)
           
 voidsetParentBeanFactory(BeanFactory parentBeanFactory)
           

Field Detail

FACTORY_BEAN_PREFIX

public final static String FACTORY_BEAN_PREFIX
Used to dereference a FactoryBean and distinguish it from beans created by the factory. For example, if the bean named myEjb is a factory, getting &myEjb will return the factory, not the instance returned by the factory.
Constructor Detail

AbstractBeanFactory

public AbstractBeanFactory()
Create a new AbstractBeanFactory.

AbstractBeanFactory

public AbstractBeanFactory(BeanFactory parentBeanFactory)
Create a new AbstractBeanFactory with the given parent.
Parameters:
parentBeanFactory - parent bean factory, or null if none
See Also:
getBean(java.lang.String)
Method Detail

addBeanPostProcessor

public void addBeanPostProcessor(BeanPostProcessor beanPostProcessor)

applyBeanPostProcessorsAfterInitialization

public Object applyBeanPostProcessorsAfterInitialization(Object bean, String name)
throws org.springframework.beans.BeansException

applyBeanPostProcessorsBeforeInitialization

public Object applyBeanPostProcessorsBeforeInitialization(Object bean, String name)
throws org.springframework.beans.BeansException

autowire

public Object autowire(Class beanClass, int autowireMode, boolean dependencyCheck)
throws org.springframework.beans.BeansException

autowireBeanProperties

public void autowireBeanProperties(Object existingBean, int autowireMode, boolean dependencyCheck)
throws org.springframework.beans.BeansException

containsBean

public boolean containsBean(String name)

destroySingletons

public void destroySingletons()

getAliases

public String[] getAliases(String name)
throws org.springframework.beans.factory.NoSuchBeanDefinitionException

getBean

public Object getBean(String name)
throws org.springframework.beans.BeansException
Return the bean with the given name, checking the parent bean factory if not found.
Parameters:
name - name of the bean to retrieve

getBean

public Object getBean(String name, Class requiredType)
throws org.springframework.beans.BeansException

getBeanDefinition

public abstract AbstractBeanDefinition getBeanDefinition(String beanName)
throws org.springframework.beans.BeansException
Return the bean definition for the given bean name. Subclasses should normally implement caching, as this method is invoked by this class every time a bean is requested.
Parameters:
beanName - name of the bean to find a definition for
Returns: the BeanDefinition for this prototype name. Must never return null.
Throws:
NoSuchBeanDefinitionException - if the bean definition cannot be resolved
BeansException - in case of errors

getBeanPostProcessors

public List getBeanPostProcessors()
Return the list of BeanPostProcessors that will get applied to beans created with this factory.

getConstructorArgumentValues

public ConstructorArgumentValues getConstructorArgumentValues(String beanName)
throws org.springframework.beans.BeansException

getCustomEditors

public Map getCustomEditors()
Return the map of custom editors, with Classes as keys and PropertyEditors as values.

getIgnoredDependencyTypes

public Set getIgnoredDependencyTypes()
Return the set of classes that will get ignored for autowiring.

getMergedBeanDefinition

public RootBeanDefinition getMergedBeanDefinition(String beanName, boolean includingAncestors)
throws org.springframework.beans.BeansException
Return a RootBeanDefinition, even by traversing parent if the parameter is a child definition. Will ask the parent bean factory if not found in this instance.
Returns: a merged RootBeanDefinition with overridden properties

getParentBeanFactory

public BeanFactory getParentBeanFactory()

getPropertyValues

public MutablePropertyValues getPropertyValues(String beanName)
throws org.springframework.beans.BeansException

getSingletonNames

public String[] getSingletonNames(Class type)
Return the names of beans in the singleton cache that match the given object type (including subclasses). Will not consider FactoryBeans as the type of their created objects is not known before instantiation.

Does not consider any hierarchy this factory may participate in.

Parameters:
type - class or interface to match, or null for all bean names
Returns: the names of beans in the singleton cache that match the given object type (including subclasses), or an empty array if none

ignoreDependencyType

public void ignoreDependencyType(Class type)

isSingleton

public boolean isSingleton(String name)
throws org.springframework.beans.factory.NoSuchBeanDefinitionException

registerAlias

public void registerAlias(String beanName, String alias)
throws org.springframework.beans.factory.BeanDefinitionStoreException

registerCustomEditor

public void registerCustomEditor(Class requiredType, PropertyEditor propertyEditor)

registerSingleton

public void registerSingleton(String beanName, Object singletonObject)
throws org.springframework.beans.factory.BeanDefinitionStoreException

setParentBeanFactory

public void setParentBeanFactory(BeanFactory parentBeanFactory)

Association Links

to Class java.lang.String

Used to dereference a FactoryBean and distinguish it from beans created by the factory. For example, if the bean named myEjb is a factory, getting &myEjb will return the factory, not the instance returned by the factory.

to Class org.springframework.beans.factory.BeanFactory

Parent bean factory, for bean inheritance support

to Class java.util.Map

to Class java.util.List

BeanPostProcessors to apply on createBean

to Class java.util.Set

Dependency types to ignore on dependency check and autowire

to Class java.util.Map

Cache of singletons: bean name --> bean instance

to Class java.util.Map

Map from alias to canonical bean name