站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Spring Framework 2.0.5 API 文档英文版

AbstractBeanDefinition (Spring Framework API 2.0) - Spring Framework 2.0.5 API 文档英文版

The Spring Framework

org.springframework.beans.factory.support
Class AbstractBeanDefinition

java.lang.Object
  extended by org.springframework.core.AttributeAccessorSupport
      extended by org.springframework.beans.factory.support.AbstractBeanDefinition
All Implemented Interfaces:
Serializable, BeanMetadataElement, BeanDefinition, AttributeAccessor
Direct Known Subclasses:
ChildBeanDefinition, RootBeanDefinition

public abstract class AbstractBeanDefinition
extends AttributeAccessorSupport
implements BeanDefinition

Base class for concrete, full-fledged BeanDefinition classes, factoring out common properties of RootBeanDefinition and ChildBeanDefinition.

The autowire constants match the ones defined in the AutowireCapableBeanFactory interface.

Author:
Rod Johnson, Juergen Hoeller, Rob Harrop
See Also:
RootBeanDefinition, ChildBeanDefinition, Serialized Form

Field Summary
static int AUTOWIRE_AUTODETECT
          Constant that indicates determining an appropriate autowire strategy through introspection of the bean class.
static int AUTOWIRE_BY_NAME
          Constant that indicates autowiring bean properties by name.
static int AUTOWIRE_BY_TYPE
          Constant that indicates autowiring bean properties by type.
static int AUTOWIRE_CONSTRUCTOR
          Constant that indicates autowiring a constructor.
static int AUTOWIRE_NO
          Constant that indicates no autowiring at all.
static int DEPENDENCY_CHECK_ALL
          Constant that indicates dependency checking for all properties (object references as well as "simple" properties).
static int DEPENDENCY_CHECK_NONE
          Constant that indicates no dependency check at all.
static int DEPENDENCY_CHECK_OBJECTS
          Constant that indicates dependency checking for object references.
static int DEPENDENCY_CHECK_SIMPLE
          Constant that indicates dependency checking for "simple" properties.
 
Fields inherited from interface org.springframework.beans.factory.config.BeanDefinition
ROLE_APPLICATION, ROLE_INFRASTRUCTURE, ROLE_SUPPORT, SCOPE_PROTOTYPE, SCOPE_SINGLETON
 
Constructor Summary
protected AbstractBeanDefinition()
          Create a new AbstractBeanDefinition with default settings.
protected AbstractBeanDefinition(AbstractBeanDefinition original)
          Create a new AbstractBeanDefinition as deep copy of the given bean definition.
protected AbstractBeanDefinition(ConstructorArgumentValues cargs, MutablePropertyValues pvs)
          Create a new AbstractBeanDefinition with the given constructor argument values and property values.
 
Method Summary
 boolean equals(Object other)
           
 int getAutowireMode()
          Return the autowire mode as specified in the bean definition.
 Class getBeanClass()
          Return the class of the wrapped bean.
 String getBeanClassName()
          Return the class name of the wrapped bean.
 ConstructorArgumentValues getConstructorArgumentValues()
          Return constructor argument values for this bean (never null).
 int getDependencyCheck()
          Return the dependency check code.
 String[] getDependsOn()
          Return the bean names that this bean depends on.
 String getDestroyMethodName()
          Return the name of the destroy method.
 String getFactoryBeanName()
          Returns the factory bean name, if any.
 String getFactoryMethodName()
          Return a factory method, if any.
 String getInitMethodName()
          Return the name of the initializer method.
 MethodOverrides getMethodOverrides()
          Return information about methods to be overridden by the IoC container.
 MutablePropertyValues getPropertyValues()
          Return property values for this bean (never null).
 int getResolvedAutowireMode()
          Return the resolved autowire code, (resolving AUTOWIRE_AUTODETECT to AUTOWIRE_CONSTRUCTOR or AUTOWIRE_BY_TYPE).
 String getResourceDescription()
          Return a description of the resource that this bean definition came from.
 int getRole()
          Return the role hint for this BeanDefinition.
 String getScope()
          Return the name of the target scope for the bean.
 Object getSource()
          Return the configuration source Object for this metadata element (may be null).
 boolean hasBeanClass()
          Return whether this definition specifies a bean class.
 boolean hasConstructorArgumentValues()
          Return if there are constructor argument values defined for this bean.
 int hashCode()
           
 boolean isAbstract()
          Return whether this bean is "abstract", i.e. not meant to be instantiated itself but rather just serving as parent for concrete child bean definitions.
 boolean isAutowireCandidate()
          Return whether this bean is a candidate for getting autowired into some other bean.
 boolean isEnforceDestroyMethod()
          Indicate whether the configured destroy method is the default.
 boolean isEnforceInitMethod()
          Indicate whether the configured init method is the default.
 boolean isLazyInit()
          Return whether this bean should be lazily initialized, i.e. not eagerly instantiated on startup.
 boolean isPrototype()
          Return whether this a Prototype, with an independent instance returned for each call.
 boolean isSingleton()
          Return whether this a Singleton, with a single shared instance returned from all calls.
 boolean isSynthetic()
          Return whether this bean definition is 'synthetic', that is, not defined by the application itself.
 void overrideFrom(AbstractBeanDefinition other)
          Override settings in this bean definition (assumably a copied parent from a parent-child inheritance relationship) from the given bean definition (assumably the child).
protected  void prepareMethodOverride(MethodOverride mo)
          Validate and prepare the given method override.
 void prepareMethodOverrides()
          Validate and prepare the method overrides defined for this bean.
 Class resolveBeanClass(ClassLoader classLoader)
          Determine the class of the wrapped bean, resolving it from a specified class name if necessary.
 void setAbstract(boolean abstractFlag)
          Set if this bean is "abstract", i.e. not meant to be instantiated itself but rather just serving as parent for concrete child bean definitions.
 void setAutowireCandidate(boolean autowireCandidate)
          Set whether this bean is a candidate for getting autowired into some other bean.
 void setAutowireMode(int autowireMode)
          Set the autowire mode.
 void setBeanClass(Class beanClass)
          Specify the class for this bean.
 void setBeanClassName(String beanClassName)
          Specify the class name for this bean.
 void setConstructorArgumentValues(ConstructorArgumentValues constructorArgumentValues)
          Specify constructor argument values for this bean.
 void setDependencyCheck(int dependencyCheck)
          Set the dependency check code.
 void setDependsOn(String[] dependsOn)
          Set the names of the beans that this bean depends on being initialized.
 void setDestroyMethodName(String destroyMethodName)
          Set the name of the destroy method.
 void setEnforceDestroyMethod(boolean enforceDestroyMethod)
          Specify whether or not the configured destroy method is the default.
 void setEnforceInitMethod(boolean enforceInitMethod)
          Specify whether or not the configured init method is the default.
 void setFactoryBeanName(String factoryBeanName)
          Specify the factory bean to use, if any.
 void setFactoryMethodName(String factoryMethodName)
          Specify a factory method, if any.
 void setInitMethodName(String initMethodName)
          Set the name of the initializer method.
 void setLazyInit(boolean lazyInit)
          Set whether this bean should be lazily initialized.
 void setMethodOverrides(MethodOverrides methodOverrides)
          Specify method overrides for the bean, if any.
 void setPropertyValues(MutablePropertyValues propertyValues)
          Specify property values for this bean, if any.
 void setResourceDescription(String resourceDescription)
          Set a description of the resource that this bean definition came from (for the purpose of showing context in case of errors).
 void setRole(int role)
          Set the role hint for this BeanDefinition.
 void setScope(String scope)
          Set the name of the target scope for the bean.
 void setSingleton(boolean singleton)
          Set if this a Singleton, with a single, shared instance returned on all calls.
 void setSource(Object source)
          Set the configuration source Object for this metadata element.
 void setSynthetic(boolean synthetic)
          Set whether this bean definition is 'synthetic', that is, not defined by the application itself (for example, an infrastructure bean such as a helper for auto-proxying, created through <aop:config>).
 String toString()
           
 void validate()
          Validate this bean definition.
 
Methods inherited from class org.springframework.core.AttributeAccessorSupport
attributeNames, copyAttributesFrom, getAttribute, hasAttribute, removeAttribute, setAttribute
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.springframework.core.AttributeAccessor
attributeNames, getAttribute, hasAttribute, removeAttribute, setAttribute
 

Field Detail

AUTOWIRE_NO

public static final int AUTOWIRE_NO
Constant that indicates no autowiring at all.

See Also:
setAutowireMode(int), Constant Field Values

AUTOWIRE_BY_NAME

public static final int AUTOWIRE_BY_NAME
Constant that indicates autowiring bean properties by name.

See Also:
setAutowireMode(int), Constant Field Values

AUTOWIRE_BY_TYPE

public static final int AUTOWIRE_BY_TYPE
Constant that indicates autowiring bean properties by type.

See Also:
setAutowireMode(int), Constant Field Values

AUTOWIRE_CONSTRUCTOR

public static final int AUTOWIRE_CONSTRUCTOR
Constant that indicates autowiring a constructor.

See Also:
setAutowireMode(int), Constant Field Values

AUTOWIRE_AUTODETECT

public static final int AUTOWIRE_AUTODETECT
Constant that indicates determining an appropriate autowire strategy through introspection of the bean class.

See Also:
setAutowireMode(int), Constant Field Values

DEPENDENCY_CHECK_NONE

public static final int DEPENDENCY_CHECK_NONE
Constant that indicates no dependency check at all.

See Also:
setDependencyCheck(int), Constant Field Values

DEPENDENCY_CHECK_OBJECTS

public static final int DEPENDENCY_CHECK_OBJECTS
Constant that indicates dependency checking for object references.

See Also:
setDependencyCheck(int), Constant Field Values

DEPENDENCY_CHECK_SIMPLE

public static final int DEPENDENCY_CHECK_SIMPLE
Constant that indicates dependency checking for "simple" properties.

See Also:
setDependencyCheck(int), BeanUtils.isSimpleProperty(java.lang.Class), Constant Field Values

DEPENDENCY_CHECK_ALL

public static final int DEPENDENCY_CHECK_ALL
Constant that indicates dependency checking for all properties (object references as well as "simple" properties).

See Also:
setDependencyCheck(int), Constant Field Values
Constructor Detail

AbstractBeanDefinition

protected AbstractBeanDefinition()
Create a new AbstractBeanDefinition with default settings.


AbstractBeanDefinition

protected AbstractBeanDefinition(ConstructorArgumentValues cargs,
                                 MutablePropertyValues pvs)
Create a new AbstractBeanDefinition with the given constructor argument values and property values.


AbstractBeanDefinition

protected AbstractBeanDefinition(AbstractBeanDefinition original)
Create a new AbstractBeanDefinition as deep copy of the given bean definition.

Parameters:
original - the original bean definition to copy from
Method Detail

overrideFrom

public void overrideFrom(AbstractBeanDefinition other)
Override settings in this bean definition (assumably a copied parent from a parent-child inheritance relationship) from the given bean definition (assumably the child).
  • Will override beanClass if specified in the given bean definition.
  • Will always take abstract, scope, lazyInit, autowireMode, dependencyCheck, and dependsOn from the given bean definition.
  • Will add constructorArgumentValues, propertyValues, methodOverrides from the given bean definition to existing ones.
  • Will override factoryBeanName, factoryMethodName, initMethodName, and destroyMethodName if specified in the given bean definition.


hasBeanClass

public boolean hasBeanClass()
Return whether this definition specifies a bean class.


setBeanClass

public void setBeanClass(Class beanClass)
Specify the class for this bean.


getBeanClass

public Class getBeanClass()
                   throws IllegalStateException
Return the class of the wrapped bean.

Throws:
IllegalStateException - if the bean definition does not define a bean class, or a specified bean class name has not been resolved into an actual Class

setBeanClassName

public void setBeanClassName(String beanClassName)
Specify the class name for this bean.

Specified by:
setBeanClassName in interface BeanDefinition

getBeanClassName

public String getBeanClassName()
Return the class name of the wrapped bean.

Specified by:
getBeanClassName in interface BeanDefinition

resolveBeanClass

public Class resolveBeanClass(ClassLoader classLoader)
                       throws ClassNotFoundException
Determine the class of the wrapped bean, resolving it from a specified class name if necessary. Will also reload a specified Class from its name when called with the bean class already resolved.

Parameters:
classLoader - the ClassLoader to use for resolving a (potential) class name
Returns:
the resolved bean class
Throws:
ClassNotFoundException - if the class name could be resolved

setScope

public void setScope(String scope)
Set the name of the target scope for the bean.

Default is "singleton"; the out-of-the-box alternative is "prototype". Extended bean factories might support further scopes.

Specified by:
setScope in interface BeanDefinition
See Also:
BeanDefinition.SCOPE_SINGLETON, BeanDefinition.SCOPE_PROTOTYPE

getScope

public String getScope()
Return the name of the target scope for the bean.

Specified by:
getScope in interface BeanDefinition

setSingleton

public void setSingleton(boolean singleton)
Set if this a Singleton, with a single, shared instance returned on all calls. In case of "false", the BeanFactory will apply the Prototype design pattern, with each caller requesting an instance getting an independent instance. How this is exactly defined will depend on the BeanFactory.

"Singletons" are the commoner type, so the default is "true". Note that as of Spring 2.0, this flag is just an alternative way to specify scope="singleton" or scope="prototype".

See Also:
setScope(java.lang.String), BeanDefinition.SCOPE_SINGLETON, BeanDefinition.SCOPE_PROTOTYPE

isSingleton

public boolean isSingleton()
Return whether this a Singleton, with a single shared instance returned from all calls.

Specified by:
isSingleton in interface BeanDefinition
See Also:
BeanDefinition.SCOPE_SINGLETON

isPrototype

public boolean isPrototype()
Return whether this a Prototype, with an independent instance returned for each call.

See Also:
BeanDefinition.SCOPE_PROTOTYPE

setAbstract

public void setAbstract(boolean abstractFlag)
Set if this bean is "abstract", i.e. not meant to be instantiated itself but rather just serving as parent for concrete child bean definitions.

Default is "false". Specify true to tell the bean factory to not try to instantiate that particular bean in any case.


isAbstract

public boolean isAbstract()
Return whether this bean is "abstract", i.e. not meant to be instantiated itself but rather just serving as parent for concrete child bean definitions.

Specified by:
isAbstract in interface BeanDefinition

setLazyInit

public void setLazyInit(boolean lazyInit)
Set whether this bean should be lazily initialized.

If false, the bean will get instantiated on startup by bean factories that perform eager initialization of singletons.


isLazyInit

public boolean isLazyInit()
Return whether this bean should be lazily initialized, i.e. not eagerly instantiated on startup. Only applicable to a singleton bean.

Specified by:
isLazyInit in interface BeanDefinition

setAutowireCandidate

public void setAutowireCandidate(boolean autowireCandidate)
Set whether this bean is a candidate for getting autowired into some other bean.


isAutowireCandidate

public boolean isAutowireCandidate()
Return whether this bean is a candidate for getting autowired into some other bean.


setAutowireMode

public void setAutowireMode(int autowireMode)
Set the autowire mode. This determines whether any automagical detection and setting of bean references will happen. Default is AUTOWIRE_NO, which means there's no autowire.

Parameters:
autowireMode - the autowire mode to set. Must be one of the constants defined in this class.
See Also:
AUTOWIRE_NO, AUTOWIRE_BY_NAME, AUTOWIRE_BY_TYPE, AUTOWIRE_CONSTRUCTOR, AUTOWIRE_AUTODETECT

getAutowireMode

public int getAutowireMode()
Return the autowire mode as specified in the bean definition.


getResolvedAutowireMode

public int getResolvedAutowireMode()
Return the resolved autowire code, (resolving AUTOWIRE_AUTODETECT to AUTOWIRE_CONSTRUCTOR or AUTOWIRE_BY_TYPE).

See Also:
AUTOWIRE_AUTODETECT, AUTOWIRE_CONSTRUCTOR, AUTOWIRE_BY_TYPE

setDependencyCheck

public void setDependencyCheck(int dependencyCheck)
Set the dependency check code.

Parameters:
dependencyCheck - the code to set. Must be one of the four constants defined in this class.
See Also:
DEPENDENCY_CHECK_NONE, DEPENDENCY_CHECK_OBJECTS, DEPENDENCY_CHECK_SIMPLE, DEPENDENCY_CHECK_ALL

getDependencyCheck

public int getDependencyCheck()
Return the dependency check code.


setDependsOn

public void setDependsOn(String[] dependsOn)
Set the names of the beans that this bean depends on being initialized. The bean factory will guarantee that these beans get initialized before.

Note that dependencies are normally expressed through bean properties or constructor arguments. This property should just be necessary for other kinds of dependencies like statics (*ugh*) or database preparation on startup.


getDependsOn

public String[] getDependsOn()
Return the bean names that this bean depends on.


setConstructorArgumentValues

public void setConstructorArgumentValues(ConstructorArgumentValues constructorArgumentValues)
Specify constructor argument values for this bean.


getConstructorArgumentValues

public ConstructorArgumentValues getConstructorArgumentValues()
Return constructor argument values for this bean (never null).

Specified by:
getConstructorArgumentValues in interface BeanDefinition
Returns:
the ConstructorArgumentValues object (never null)

hasConstructorArgumentValues

public boolean hasConstructorArgumentValues()
Return if there are constructor argument values defined for this bean.


setPropertyValues

public void setPropertyValues(MutablePropertyValues propertyValues)
Specify property values for this bean, if any.


getPropertyValues

public MutablePropertyValues getPropertyValues()
Return property values for this bean (never null).

Specified by:
getPropertyValues in interface BeanDefinition
Returns:
the MutablePropertyValues object (never null)

setMethodOverrides

public void setMethodOverrides(MethodOverrides methodOverrides)
Specify method overrides for the bean, if any.


getMethodOverrides

public MethodOverrides getMethodOverrides()
Return information about methods to be overridden by the IoC container. This will be empty if there are no method overrides. Never returns null.


setFactoryBeanName

public void setFactoryBeanName(String factoryBeanName)
Specify the factory bean to use, if any.


getFactoryBeanName

public String getFactoryBeanName()
Returns the factory bean name, if any.


setFactoryMethodName

public void setFactoryMethodName(String factoryMethodName)
Specify a factory method, if any. This method will be invoked with constructor arguments, or with no arguments if none are specified. The static method will be invoked on the specifed factory bean, if any, or on the local bean class else.

Parameters:
factoryMethodName - static factory method name, or null if normal constructor creation should be used
See Also:
getBeanClass()

getFactoryMethodName

public String getFactoryMethodName()
Return a factory method, if any.


setInitMethodName

public void setInitMethodName(String initMethodName)
Set the name of the initializer method. The default is null in which case there is no initializer method.


getInitMethodName

public String getInitMethodName()
Return the name of the initializer method.


setEnforceInitMethod

public void setEnforceInitMethod(boolean enforceInitMethod)
Specify whether or not the configured init method is the default. Default value is false.

See Also:
setInitMethodName(java.lang.String)

isEnforceInitMethod

public boolean isEnforceInitMethod()
Indicate whether the configured init method is the default.

See Also:
getInitMethodName()

setDestroyMethodName

public void setDestroyMethodName(String destroyMethodName)
Set the name of the destroy method. The default is null in which case there is no destroy method.


getDestroyMethodName

public String getDestroyMethodName()
Return the name of the destroy method.


setEnforceDestroyMethod

public void setEnforceDestroyMethod(boolean enforceDestroyMethod)
Specify whether or not the configured destroy method is the default. Default value is false.

See Also:
setDestroyMethodName(java.lang.String)

isEnforceDestroyMethod

public boolean isEnforceDestroyMethod()
Indicate whether the configured destroy method is the default.

See Also:
getDestroyMethodName()

setSynthetic

public void setSynthetic(boolean synthetic)
Set whether this bean definition is 'synthetic', that is, not defined by the application itself (for example, an infrastructure bean such as a helper for auto-proxying, created through <aop:config>).


isSynthetic

public boolean isSynthetic()
Return whether this bean definition is 'synthetic', that is, not defined by the application itself.


setResourceDescription

public void setResourceDescription(String resourceDescription)
Set a description of the resource that this bean definition came from (for the purpose of showing context in case of errors).


getResourceDescription

public String getResourceDescription()
Return a description of the resource that this bean definition came from.

Specified by:
getResourceDescription in interface BeanDefinition

setSource

public void setSource(Object source)
Set the configuration source Object for this metadata element.

The exact type of the object will depend on the configuration mechanism used.


getSource

public Object getSource()
Description copied from interface: BeanMetadataElement
Return the configuration source Object for this metadata element (may be null).

Specified by:
getSource in interface BeanMetadataElement

setRole

public void setRole(int role)
Set the role hint for this BeanDefinition.


getRole

public int getRole()
Return the role hint for this BeanDefinition.

Specified by:
getRole in interface BeanDefinition
See Also:
BeanDefinition.ROLE_APPLICATION, BeanDefinition.ROLE_INFRASTRUCTURE, BeanDefinition.ROLE_SUPPORT

validate

public void validate()
              throws BeanDefinitionValidationException
Validate this bean definition.

Throws:
BeanDefinitionValidationException - in case of validation failure

prepareMethodOverrides

public void prepareMethodOverrides()
                            throws BeanDefinitionValidationException
Validate and prepare the method overrides defined for this bean. Checks for existence of a method with the specified name.

Throws:
BeanDefinitionValidationException - in case of validation failure

prepareMethodOverride

protected void prepareMethodOverride(MethodOverride mo)
                              throws BeanDefinitionValidationException
Validate and prepare the given method override. Checks for existence of a method with the specified name, marking it as not overloaded if none found.

Parameters:
mo - the MethodOverride object to validate
Throws:
BeanDefinitionValidationException - in case of validation failure

equals

public boolean equals(Object other)
Overrides:
equals in class AttributeAccessorSupport

hashCode

public int hashCode()
Overrides:
hashCode in class AttributeAccessorSupport

toString

public String toString()
Overrides:
toString in class Object

The Spring Framework

Copyright © 2002-2007 The Spring Framework.