org.springframework.beans.factory.support
Class AbstractBeanDefinition

java.lang.Object
  extended byorg.springframework.beans.factory.support.AbstractBeanDefinition
All Implemented Interfaces:
BeanDefinition
Direct Known Subclasses:
ChildBeanDefinition, RootBeanDefinition

public abstract class AbstractBeanDefinition
extends Object
implements BeanDefinition

Base class for bean definition objects, factoring out common properties of RootBeanDefinition and ChildBeanDefinition.

The autowire constants match the ones defined in the AutowireCapableBeanFactory interface, adding AUTOWIRE_NO.

Author:
Rod Johnson, Juergen Hoeller
See Also:
RootBeanDefinition, ChildBeanDefinition

Field Summary
static int AUTOWIRE_AUTODETECT
           
static int AUTOWIRE_BY_NAME
           
static int AUTOWIRE_BY_TYPE
           
static int AUTOWIRE_CONSTRUCTOR
           
static int AUTOWIRE_NO
           
static int DEPENDENCY_CHECK_ALL
           
static int DEPENDENCY_CHECK_NONE
           
static int DEPENDENCY_CHECK_OBJECTS
           
static int DEPENDENCY_CHECK_SIMPLE
           
 
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
 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, if any.
 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, if any.
 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.
 boolean hasBeanClass()
          Return whether this definitions specifies a bean class.
 boolean hasConstructorArgumentValues()
          Return if there are constructor argument values defined for this bean.
 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 isLazyInit()
          Return whether this bean should be lazily initialized, i.e. not eagerly instantiated on startup.
 boolean isSingleton()
          Return whether this a Singleton, with a single, shared instance returned on all calls.
 void overrideFrom(AbstractBeanDefinition other)
          Override settings in this bean definition from the given bean definition.
 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 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 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 setSingleton(boolean singleton)
          Set if this a Singleton, with a single, shared instance returned on all calls.
 void validate()
          Validate this bean definition.
protected  void validateMethodOverride(MethodOverride mo)
          Validate the given method override.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AUTOWIRE_NO

public static final int AUTOWIRE_NO
See Also:
Constant Field Values

AUTOWIRE_BY_NAME

public static final int AUTOWIRE_BY_NAME
See Also:
Constant Field Values

AUTOWIRE_BY_TYPE

public static final int AUTOWIRE_BY_TYPE
See Also:
Constant Field Values

AUTOWIRE_CONSTRUCTOR

public static final int AUTOWIRE_CONSTRUCTOR
See Also:
Constant Field Values

AUTOWIRE_AUTODETECT

public static final int AUTOWIRE_AUTODETECT
See Also:
Constant Field Values

DEPENDENCY_CHECK_NONE

public static final int DEPENDENCY_CHECK_NONE
See Also:
Constant Field Values

DEPENDENCY_CHECK_OBJECTS

public static final int DEPENDENCY_CHECK_OBJECTS
See Also:
Constant Field Values

DEPENDENCY_CHECK_SIMPLE

public static final int DEPENDENCY_CHECK_SIMPLE
See Also:
Constant Field Values

DEPENDENCY_CHECK_ALL

public static final int DEPENDENCY_CHECK_ALL
See Also:
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 from the given bean definition.


hasBeanClass

public boolean hasBeanClass()
Return whether this definitions 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.

Specified by:
getBeanClass in interface BeanDefinition
Throws:
IllegalStateException - if the bean definition does not carry a resolved bean class
See Also:
BeanFactory.getType(java.lang.String)

setBeanClassName

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


getBeanClassName

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


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

setSingleton

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

"Singletons" are the commoner type, so the default is true.


isSingleton

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

Specified by:
isSingleton in interface BeanDefinition

setLazyInit

public void setLazyInit(boolean lazyInit)
Set whether this bean should be lazily initialized. Only applicable to a singleton bean. If false, it 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

setConstructorArgumentValues

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


getConstructorArgumentValues

public ConstructorArgumentValues getConstructorArgumentValues()
Return constructor argument values for this bean, if any.

Specified by:
getConstructorArgumentValues in interface BeanDefinition
Returns:
the ConstructorArgumentValues object, or 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, if any.

Specified by:
getPropertyValues in interface BeanDefinition
Returns:
the PropertyValues object, or 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.


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.


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.


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 beanClass.

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.


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.


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.


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

validate

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

Throws:
BeanDefinitionValidationException - in case of validation failure

validateMethodOverride

protected void validateMethodOverride(MethodOverride mo)
                               throws BeanDefinitionValidationException
Validate the given method override. Checks for existence of a method with the specified name.

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


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