Save This Page
Home » spring-framework-2.5.5-with-dependencies » org.springframework » beans » factory » support » [javadoc | source]
org.springframework.beans.factory.support
abstract public class: AbstractBeanFactory [javadoc | source]
java.lang.Object
   org.springframework.core.SimpleAliasRegistry
      org.springframework.beans.factory.support.DefaultSingletonBeanRegistry
         org.springframework.beans.factory.support.FactoryBeanRegistrySupport
            org.springframework.beans.factory.support.AbstractBeanFactory

All Implemented Interfaces:
    ConfigurableBeanFactory, SingletonBeanRegistry, AliasRegistry

Direct Known Subclasses:
    DefaultListableBeanFactory, AbstractAutowireCapableBeanFactory, XmlBeanFactory

Abstract base class for org.springframework.beans.factory.BeanFactory implementations, providing the full capabilities of the org.springframework.beans.factory.config.ConfigurableBeanFactory SPI. Does not assume a listable bean factory: can therefore also be used as base class for bean factory implementations which obtain bean definitions from some backend resource (where bean definition access is an expensive operation).

This class provides a singleton cache (through its base class org.springframework.beans.factory.support.DefaultSingletonBeanRegistry , singleton/prototype determination, org.springframework.beans.factory.FactoryBean handling, aliases, bean definition merging for child bean definitions, and bean destruction (org.springframework.beans.factory.DisposableBean interface, custom destroy methods). Furthermore, it can manage a bean factory hierarchy (delegating to the parent in case of an unknown bean), through implementing the org.springframework.beans.factory.HierarchicalBeanFactory interface.

The main template methods to be implemented by subclasses are #getBeanDefinition and #createBean , retrieving a bean definition for a given bean name and creating a bean instance for a given bean definition, respectively. Default implementations of those operations can be found in DefaultListableBeanFactory and AbstractAutowireCapableBeanFactory .

Fields inherited from org.springframework.beans.factory.support.DefaultSingletonBeanRegistry:
NULL_OBJECT,  logger
Constructor:
 public AbstractBeanFactory() 
 public AbstractBeanFactory(BeanFactory parentBeanFactory) 
    Create a new AbstractBeanFactory with the given parent.
    Parameters:
    parentBeanFactory - parent bean factory, or null if none
    Also see:
    getBean
Method from org.springframework.beans.factory.support.AbstractBeanFactory Summary:
addBeanPostProcessor,   addPropertyEditorRegistrar,   afterPrototypeCreation,   beforePrototypeCreation,   checkMergedBeanDefinition,   clearMergedBeanDefinition,   containsBean,   containsBeanDefinition,   containsLocalBean,   copyConfigurationFrom,   createBean,   destroyBean,   destroyBean,   destroyScopedBean,   doGetBean,   getAliases,   getBean,   getBean,   getBean,   getBean,   getBeanClassLoader,   getBeanDefinition,   getBeanPostProcessorCount,   getBeanPostProcessors,   getCustomEditors,   getCustomTypeConverter,   getMergedBeanDefinition,   getMergedBeanDefinition,   getMergedBeanDefinition,   getMergedLocalBeanDefinition,   getObjectForBeanInstance,   getParentBeanFactory,   getPropertyEditorRegistrars,   getRegisteredScope,   getRegisteredScopeNames,   getTempClassLoader,   getType,   getTypeConverter,   getTypeForFactoryBean,   hasDestructionAwareBeanPostProcessors,   hasInstantiationAwareBeanPostProcessors,   initBeanWrapper,   isBeanEligibleForMetadataCaching,   isBeanNameInUse,   isCacheBeanMetadata,   isCurrentlyInCreation,   isFactoryBean,   isFactoryBean,   isPrototype,   isPrototypeCurrentlyInCreation,   isSingleton,   isTypeMatch,   markBeanAsCreated,   originalBeanName,   predictBeanType,   registerCustomEditor,   registerCustomEditor,   registerCustomEditors,   registerDisposableBeanIfNecessary,   registerScope,   removeSingletonIfCreatedForTypeCheckOnly,   requiresDestruction,   resolveBeanClass,   resolveBeanClass,   setBeanClassLoader,   setCacheBeanMetadata,   setParentBeanFactory,   setTempClassLoader,   setTypeConverter,   transformedBeanName
Methods from org.springframework.beans.factory.support.FactoryBeanRegistrySupport:
getCachedObjectForFactoryBean,   getFactoryBean,   getObjectFromFactoryBean,   getTypeForFactoryBean,   postProcessObjectFromFactoryBean,   removeSingleton
Methods from org.springframework.beans.factory.support.DefaultSingletonBeanRegistry:
addSingleton,   addSingletonFactory,   afterSingletonCreation,   beforeSingletonCreation,   containsSingleton,   destroyBean,   destroySingleton,   destroySingletons,   getDependenciesForBean,   getDependentBeans,   getSingleton,   getSingleton,   getSingleton,   getSingletonCount,   getSingletonMutex,   getSingletonNames,   hasDependentBean,   isSingletonCurrentlyInCreation,   onSuppressedException,   registerDependentBean,   registerDisposableBean,   registerSingleton,   removeSingleton
Methods from org.springframework.core.SimpleAliasRegistry:
allowAliasOverriding,   canonicalName,   getAliases,   isAlias,   registerAlias,   removeAlias,   resolveAliases
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.springframework.beans.factory.support.AbstractBeanFactory Detail:
 public  void addBeanPostProcessor(BeanPostProcessor beanPostProcessor) 
 public  void addPropertyEditorRegistrar(PropertyEditorRegistrar registrar) 
 protected  void afterPrototypeCreation(String beanName) 
    Callback after prototype creation.

    The default implementation marks the prototype as not in creation anymore.

 protected  void beforePrototypeCreation(String beanName) 
    Callback before prototype creation.

    The default implementation register the prototype as currently in creation.

 protected  void checkMergedBeanDefinition(RootBeanDefinition mbd,
    String beanName,
    Object[] args) throws BeanDefinitionStoreException 
    Check the given merged bean definition, potentially throwing validation exceptions.
 protected  void clearMergedBeanDefinition(String beanName) 
    Remove the merged bean definition for the specified bean, recreating it on next access.
 public boolean containsBean(String name) 
 abstract protected boolean containsBeanDefinition(String beanName)
    Check if this bean factory contains a bean definition with the given name. Does not consider any hierarchy this factory may participate in. Invoked by containsBean when no cached singleton instance is found.

    Depending on the nature of the concrete bean factory implementation, this operation might be expensive (for example, because of directory lookups in external registries). However, for listable bean factories, this usually just amounts to a local hash lookup: The operation is therefore part of the public interface there. The same implementation can serve for both this template method and the public interface method in that case.

 public boolean containsLocalBean(String name) 
 public  void copyConfigurationFrom(ConfigurableBeanFactory otherFactory) 
 abstract protected Object createBean(String beanName,
    RootBeanDefinition mbd,
    Object[] args) throws BeanCreationException
    Create a bean instance for the given bean definition. The bean definition will already have been merged with the parent definition in case of a child definition.

    All the other methods in this class invoke this method, although beans may be cached after being instantiated by this method. All bean instantiation within this class is performed by this method.

 public  void destroyBean(String beanName,
    Object beanInstance) 
 protected  void destroyBean(String beanName,
    Object beanInstance,
    RootBeanDefinition mbd) 
    Destroy the given bean instance (usually a prototype instance obtained from this factory) according to the given bean definition.
 public  void destroyScopedBean(String beanName) 
 protected Object doGetBean(String name,
    Class requiredType,
    Object[] args,
    boolean typeCheckOnly) throws BeansException 
    Return an instance, which may be shared or independent, of the specified bean.
 public String[] getAliases(String name) 
 public Object getBean(String name) throws BeansException 
 public Object getBean(String name,
    Class requiredType) throws BeansException 
 public Object getBean(String name,
    Object[] args) throws BeansException 
 public Object getBean(String name,
    Class requiredType,
    Object[] args) throws BeansException 
    Return an instance, which may be shared or independent, of the specified bean.
 public ClassLoader getBeanClassLoader() 
 abstract protected BeanDefinition getBeanDefinition(String beanName) throws 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 bean definition metadata is needed.

    Depending on the nature of the concrete bean factory implementation, this operation might be expensive (for example, because of directory lookups in external registries). However, for listable bean factories, this usually just amounts to a local hash lookup: The operation is therefore part of the public interface there. The same implementation can serve for both this template method and the public interface method in that case.

 public int getBeanPostProcessorCount() 
 public List getBeanPostProcessors() 
    Return the list of BeanPostProcessors that will get applied to beans created with this factory.
 public Map getCustomEditors() 
    Return the map of custom editors, with Classes as keys and PropertyEditor instances or PropertyEditor classes as values.
 protected TypeConverter getCustomTypeConverter() 
    Return the custom TypeConverter to use, if any.
 public BeanDefinition getMergedBeanDefinition(String name) throws BeansException 
    Return a 'merged' BeanDefinition for the given bean name, merging a child bean definition with its parent if necessary.

    This getMergedBeanDefinition considers bean definition in ancestors as well.

 protected RootBeanDefinition getMergedBeanDefinition(String beanName,
    BeanDefinition bd) throws BeanDefinitionStoreException 
    Return a RootBeanDefinition for the given top-level bean, by merging with the parent if the given bean's definition is a child bean definition.
 protected RootBeanDefinition getMergedBeanDefinition(String beanName,
    BeanDefinition bd,
    BeanDefinition containingBd) throws BeanDefinitionStoreException 
    Return a RootBeanDefinition for the given bean, by merging with the parent if the given bean's definition is a child bean definition.
 protected RootBeanDefinition getMergedLocalBeanDefinition(String beanName) throws BeansException 
    Return a merged RootBeanDefinition, traversing the parent bean definition if the specified bean corresponds to a child bean definition.
 protected Object getObjectForBeanInstance(Object beanInstance,
    String name,
    String beanName,
    RootBeanDefinition mbd) 
    Get the object for the given bean instance, either the bean instance itself or its created object in case of a FactoryBean.
 public BeanFactory getParentBeanFactory() 
 public Set getPropertyEditorRegistrars() 
    Return the set of PropertyEditorRegistrars.
 public Scope getRegisteredScope(String scopeName) 
 public String[] getRegisteredScopeNames() 
 public ClassLoader getTempClassLoader() 
 public Class getType(String name) throws NoSuchBeanDefinitionException 
 public TypeConverter getTypeConverter() 
 protected Class getTypeForFactoryBean(String beanName,
    RootBeanDefinition mbd) 
    Determine the bean type for the given FactoryBean definition, as far as possible. Only called if there is no singleton instance registered for the target bean already.

    The default implementation creates the FactoryBean via getBean to call its getObjectType method. Subclasses are encouraged to optimize this, typically by just instantiating the FactoryBean but not populating it yet, trying whether its getObjectType method already returns a type. If no type found, a full FactoryBean creation as performed by this implementation should be used as fallback.

 protected boolean hasDestructionAwareBeanPostProcessors() 
    Return whether this factory holds a DestructionAwareBeanPostProcessor that will get applied to singleton beans on shutdown.
 protected boolean hasInstantiationAwareBeanPostProcessors() 
    Return whether this factory holds a InstantiationAwareBeanPostProcessor that will get applied to singleton beans on shutdown.
 protected  void initBeanWrapper(BeanWrapper bw) 
    Initialize the given BeanWrapper with the custom editors registered with this factory. To be called for BeanWrappers that will create and populate bean instances.

    The default implementation delegates to registerCustomEditors. Can be overridden in subclasses.

 protected boolean isBeanEligibleForMetadataCaching(String beanName) 
    Determine whether the specified bean is eligible for having its bean definition metadata cached.
 public boolean isBeanNameInUse(String beanName) 
    Determine whether the given bean name is already in use within this factory, i.e. whether there is a local bean or alias registered under this name or an inner bean created with this name.
 public boolean isCacheBeanMetadata() 
 public boolean isCurrentlyInCreation(String beanName) 
 public boolean isFactoryBean(String name) throws NoSuchBeanDefinitionException 
 protected boolean isFactoryBean(String beanName,
    RootBeanDefinition mbd) 
    Check whether the given bean is defined as a FactoryBean .
 public boolean isPrototype(String name) throws NoSuchBeanDefinitionException 
 protected final boolean isPrototypeCurrentlyInCreation(String beanName) 
    Return whether the specified prototype bean is currently in creation (within the current thread).
 public boolean isSingleton(String name) throws NoSuchBeanDefinitionException 
 public boolean isTypeMatch(String name,
    Class targetType) throws NoSuchBeanDefinitionException 
 protected  void markBeanAsCreated(String beanName) 
    Mark the specified bean as already created (or about to be created).

    This allows the bean factory to optimize its caching for repeated creation of the specified bean.

 protected String originalBeanName(String name) 
    Determine the original bean name, resolving locally defined aliases to canonical names.
 protected Class predictBeanType(String beanName,
    RootBeanDefinition mbd,
    Class[] typesToMatch) 
    Predict the eventual bean type (of the processed bean instance) for the specified bean. Called by #getType and #isTypeMatch . Does not need to handle FactoryBeans specifically, since it is only supposed to operate on the raw bean type.

    This implementation is simplistic in that it is not able to handle factory methods and InstantiationAwareBeanPostProcessors. It only predicts the bean type correctly for a standard bean. To be overridden in subclasses, applying more sophisticated type detection.

 public  void registerCustomEditor(Class requiredType,
    Class propertyEditorClass) 
 public  void registerCustomEditor(Class requiredType,
    PropertyEditor propertyEditor) 
 protected  void registerCustomEditors(PropertyEditorRegistry registry) 
    Initialize the given PropertyEditorRegistry with the custom editors registered with this BeanFactory.

    To be called for BeanWrappers that will create and populate bean instances, and for SimpleTypeConverter used for constructor argument and factory method type conversion.

 protected  void registerDisposableBeanIfNecessary(String beanName,
    Object bean,
    RootBeanDefinition mbd) 
    Add the given bean to the list of disposable beans in this factory, registering its DisposableBean interface and/or the given destroy method to be called on factory shutdown (if applicable). Only applies to singletons.
 public  void registerScope(String scopeName,
    Scope scope) 
 protected boolean removeSingletonIfCreatedForTypeCheckOnly(String beanName) 
    Remove the singleton instance (if any) for the given bean name, but only if it hasn't been used for other purposes than type checking.
 protected boolean requiresDestruction(Object bean,
    RootBeanDefinition mbd) 
    Determine whether the given bean requires destruction on shutdown.

    The default implementation checks the DisposableBean interface as well as a specified destroy method and registered DestructionAwareBeanPostProcessors.

 protected Class resolveBeanClass(RootBeanDefinition mbd,
    String beanName) 
    Resolve the bean class for the specified bean definition, resolving a bean class name into a Class reference (if necessary) and storing the resolved Class in the bean definition for further use.
 protected Class resolveBeanClass(RootBeanDefinition mbd,
    String beanName,
    Class[] typesToMatch) throws CannotLoadBeanClassException 
    Resolve the bean class for the specified bean definition, resolving a bean class name into a Class reference (if necessary) and storing the resolved Class in the bean definition for further use.
 public  void setBeanClassLoader(ClassLoader beanClassLoader) 
 public  void setCacheBeanMetadata(boolean cacheBeanMetadata) 
 public  void setParentBeanFactory(BeanFactory parentBeanFactory) 
 public  void setTempClassLoader(ClassLoader tempClassLoader) 
 public  void setTypeConverter(TypeConverter typeConverter) 
 protected String transformedBeanName(String name) 
    Return the bean name, stripping out the factory dereference prefix if necessary, and resolving aliases to canonical names.