public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccessor implements BeanDefinition, java.lang.Cloneable
BeanDefinition
classes,
factoring out common properties of GenericBeanDefinition
,
RootBeanDefinition
and ChildBeanDefinition
.
The autowire constants match the ones defined in the
AutowireCapableBeanFactory
interface.
RootBeanDefinition
,
ChildBeanDefinition
,
Serialized FormModifier and Type | Field and Description |
---|---|
private boolean |
abstractFlag |
static int |
AUTOWIRE_AUTODETECT
Deprecated.
as of Spring 3.0: If you are using mixed autowiring strategies,
use annotation-based autowiring for clearer demarcation of autowiring needs.
|
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.
|
private boolean |
autowireCandidate |
private int |
autowireMode |
private java.lang.Object |
beanClass |
private ConstructorArgumentValues |
constructorArgumentValues |
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.
|
private int |
dependencyCheck |
private java.lang.String[] |
dependsOn |
private java.lang.String |
description |
private java.lang.String |
destroyMethodName |
private boolean |
enforceDestroyMethod |
private boolean |
enforceInitMethod |
private java.lang.String |
factoryBeanName |
private java.lang.String |
factoryMethodName |
static java.lang.String |
INFER_METHOD
Constant that indicates the container should attempt to infer the
destroy method name for a bean as opposed to
explicit specification of a method name. |
private java.lang.String |
initMethodName |
private boolean |
lazyInit |
private boolean |
lenientConstructorResolution |
private MethodOverrides |
methodOverrides |
private boolean |
nonPublicAccessAllowed |
private boolean |
primary |
private MutablePropertyValues |
propertyValues |
private java.util.Map<java.lang.String,AutowireCandidateQualifier> |
qualifiers |
private Resource |
resource |
private int |
role |
private java.lang.String |
scope |
static java.lang.String |
SCOPE_DEFAULT
Constant for the default scope name: "", equivalent to singleton status
but to be overridden from a parent bean definition (if applicable).
|
private boolean |
synthetic |
ROLE_APPLICATION, ROLE_INFRASTRUCTURE, ROLE_SUPPORT, SCOPE_PROTOTYPE, SCOPE_SINGLETON
Modifier | Constructor and Description |
---|---|
protected |
AbstractBeanDefinition()
Create a new AbstractBeanDefinition with default settings.
|
protected |
AbstractBeanDefinition(BeanDefinition original)
Create a new AbstractBeanDefinition as a 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.
|
Modifier and Type | Method and Description |
---|---|
void |
addQualifier(AutowireCandidateQualifier qualifier)
Register a qualifier to be used for autowire candidate resolution,
keyed by the qualifier's type name.
|
void |
applyDefaults(BeanDefinitionDefaults defaults)
Apply the provided default values to this bean.
|
java.lang.Object |
clone()
Public declaration of Object's
clone() method. |
abstract AbstractBeanDefinition |
cloneBeanDefinition()
Clone this bean definition.
|
void |
copyQualifiersFrom(AbstractBeanDefinition source)
Copy the qualifiers from the supplied AbstractBeanDefinition to this bean definition.
|
boolean |
equals(java.lang.Object other) |
int |
getAutowireMode()
Return the autowire mode as specified in the bean definition.
|
java.lang.Class<?> |
getBeanClass()
Return the class of the wrapped bean, if already resolved.
|
java.lang.String |
getBeanClassName()
Return the current bean class name of this bean definition.
|
ConstructorArgumentValues |
getConstructorArgumentValues()
Return constructor argument values for this bean (never
null ). |
int |
getDependencyCheck()
Return the dependency check code.
|
java.lang.String[] |
getDependsOn()
Return the bean names that this bean depends on.
|
java.lang.String |
getDescription()
Return a human-readable description of this bean definition.
|
java.lang.String |
getDestroyMethodName()
Return the name of the destroy method.
|
java.lang.String |
getFactoryBeanName()
Return the factory bean name, if any.
|
java.lang.String |
getFactoryMethodName()
Return a factory method, if any.
|
java.lang.String |
getInitMethodName()
Return the name of the initializer method.
|
MethodOverrides |
getMethodOverrides()
Return information about methods to be overridden by the IoC
container.
|
BeanDefinition |
getOriginatingBeanDefinition()
Return the originating BeanDefinition, or
null if none. |
MutablePropertyValues |
getPropertyValues()
Return property values for this bean (never
null ). |
AutowireCandidateQualifier |
getQualifier(java.lang.String typeName)
Return the qualifier mapped to the provided type name.
|
java.util.Set<AutowireCandidateQualifier> |
getQualifiers()
Return all registered qualifiers.
|
int |
getResolvedAutowireMode()
Return the resolved autowire code,
(resolving AUTOWIRE_AUTODETECT to AUTOWIRE_CONSTRUCTOR or AUTOWIRE_BY_TYPE).
|
Resource |
getResource()
Return the resource that this bean definition came from.
|
java.lang.String |
getResourceDescription()
Return a description of the resource that this bean definition
came from (for the purpose of showing context in case of errors).
|
int |
getRole()
Return the role hint for this
BeanDefinition . |
java.lang.String |
getScope()
Return the name of the target scope for the bean.
|
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 |
hasQualifier(java.lang.String typeName)
Return whether this bean has the specified qualifier.
|
boolean |
isAbstract()
Return whether this bean is "abstract", i.e.
|
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.
|
boolean |
isLenientConstructorResolution()
Return whether to resolve constructors in lenient mode or in strict mode.
|
boolean |
isNonPublicAccessAllowed()
Return whether to allow access to non-public constructors and methods.
|
boolean |
isPrimary()
Return whether this bean is a primary autowire candidate.
|
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(BeanDefinition other)
Override settings in this bean definition (presumably a copied parent
from a parent-child inheritance relationship) from the given bean
definition (presumably 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.
|
java.lang.Class<?> |
resolveBeanClass(java.lang.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.
|
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(java.lang.Class<?> beanClass)
Specify the class for this bean.
|
void |
setBeanClassName(java.lang.String beanClassName)
Override the bean class name of this bean definition.
|
void |
setConstructorArgumentValues(ConstructorArgumentValues constructorArgumentValues)
Specify constructor argument values for this bean.
|
void |
setDependencyCheck(int dependencyCheck)
Set the dependency check code.
|
void |
setDependsOn(java.lang.String[] dependsOn)
Set the names of the beans that this bean depends on being initialized.
|
void |
setDescription(java.lang.String description)
Set a human-readable description of this bean definition.
|
void |
setDestroyMethodName(java.lang.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(java.lang.String factoryBeanName)
Specify the factory bean to use, if any.
|
void |
setFactoryMethodName(java.lang.String factoryMethodName)
Specify a factory method, if any.
|
void |
setInitMethodName(java.lang.String initMethodName)
Set the name of the initializer method.
|
void |
setLazyInit(boolean lazyInit)
Set whether this bean should be lazily initialized.
|
void |
setLenientConstructorResolution(boolean lenientConstructorResolution)
Specify whether to resolve constructors in lenient mode (
true ,
which is the default) or to switch to strict resolution (throwing an exception
in case of ambiguous constructors that all match when converting the arguments,
whereas lenient mode would use the one with the 'closest' type matches). |
void |
setMethodOverrides(MethodOverrides methodOverrides)
Specify method overrides for the bean, if any.
|
void |
setNonPublicAccessAllowed(boolean nonPublicAccessAllowed)
Specify whether to allow access to non-public constructors and methods,
for the case of externalized metadata pointing to those.
|
void |
setOriginatingBeanDefinition(BeanDefinition originatingBd)
Set the originating (e.g.
|
void |
setPrimary(boolean primary)
Set whether this bean is a primary autowire candidate.
|
void |
setPropertyValues(MutablePropertyValues propertyValues)
Specify property values for this bean, if any.
|
void |
setResource(Resource resource)
Set the resource that this bean definition came from
(for the purpose of showing context in case of errors).
|
void |
setResourceDescription(java.lang.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(java.lang.String scope)
Set the name of the target scope for the bean.
|
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> ). |
java.lang.String |
toString() |
void |
validate()
Validate this bean definition.
|
addMetadataAttribute, getAttribute, getMetadataAttribute, getSource, removeAttribute, setAttribute, setSource
attributeNames, copyAttributesFrom, hasAttribute
finalize, getClass, notify, notifyAll, wait, wait, wait
getParentName, setParentName
attributeNames, getAttribute, hasAttribute, removeAttribute, setAttribute
getSource
public static final java.lang.String SCOPE_DEFAULT
public static final int AUTOWIRE_NO
setAutowireMode(int)
,
Constant Field Valuespublic static final int AUTOWIRE_BY_NAME
setAutowireMode(int)
,
Constant Field Valuespublic static final int AUTOWIRE_BY_TYPE
setAutowireMode(int)
,
Constant Field Valuespublic static final int AUTOWIRE_CONSTRUCTOR
setAutowireMode(int)
,
Constant Field Values@Deprecated public static final int AUTOWIRE_AUTODETECT
setAutowireMode(int)
,
Constant Field Valuespublic static final int DEPENDENCY_CHECK_NONE
setDependencyCheck(int)
,
Constant Field Valuespublic static final int DEPENDENCY_CHECK_OBJECTS
setDependencyCheck(int)
,
Constant Field Valuespublic static final int DEPENDENCY_CHECK_SIMPLE
public static final int DEPENDENCY_CHECK_ALL
setDependencyCheck(int)
,
Constant Field Valuespublic static final java.lang.String INFER_METHOD
destroy method name
for a bean as opposed to
explicit specification of a method name. The value "(inferred)" is specifically
designed to include characters otherwise illegal in a method name, ensuring
no possibility of collisions with legitimately named methods having the same
name.
Currently, the method names detected during destroy method inference are "close" and "shutdown", if present on the specific bean class.
private volatile java.lang.Object beanClass
private java.lang.String scope
private boolean abstractFlag
private boolean lazyInit
private int autowireMode
private int dependencyCheck
private java.lang.String[] dependsOn
private boolean autowireCandidate
private boolean primary
private final java.util.Map<java.lang.String,AutowireCandidateQualifier> qualifiers
private boolean nonPublicAccessAllowed
private boolean lenientConstructorResolution
private ConstructorArgumentValues constructorArgumentValues
private MutablePropertyValues propertyValues
private MethodOverrides methodOverrides
private java.lang.String factoryBeanName
private java.lang.String factoryMethodName
private java.lang.String initMethodName
private java.lang.String destroyMethodName
private boolean enforceInitMethod
private boolean enforceDestroyMethod
private boolean synthetic
private int role
private java.lang.String description
private Resource resource
protected AbstractBeanDefinition()
protected AbstractBeanDefinition(ConstructorArgumentValues cargs, MutablePropertyValues pvs)
protected AbstractBeanDefinition(BeanDefinition original)
original
- the original bean definition to copy frompublic void overrideFrom(BeanDefinition other)
abstract
, scope
,
lazyInit
, autowireMode
, dependencyCheck
,
and dependsOn
from the given bean definition.
constructorArgumentValues
, propertyValues
,
methodOverrides
from the given bean definition to existing ones.
factoryBeanName
, factoryMethodName
,
initMethodName
, and destroyMethodName
if specified
in the given bean definition.
public void applyDefaults(BeanDefinitionDefaults defaults)
defaults
- the defaults to applypublic boolean hasBeanClass()
public void setBeanClass(java.lang.Class<?> beanClass)
public java.lang.Class<?> getBeanClass() throws java.lang.IllegalStateException
null
if none definedjava.lang.IllegalStateException
- if the bean definition does not define a bean class,
or a specified bean class name has not been resolved into an actual Classpublic void setBeanClassName(java.lang.String beanClassName)
BeanDefinition
The class name can be modified during bean factory post-processing, typically replacing the original class name with a parsed variant of it.
setBeanClassName
in interface BeanDefinition
public java.lang.String getBeanClassName()
BeanDefinition
Note that this does not have to be the actual class name used at runtime, in case of a child definition overriding/inheriting the class name from its parent. Hence, do not consider this to be the definitive bean type at runtime but rather only use it for parsing purposes at the individual bean definition level.
getBeanClassName
in interface BeanDefinition
public java.lang.Class<?> resolveBeanClass(java.lang.ClassLoader classLoader) throws java.lang.ClassNotFoundException
classLoader
- the ClassLoader to use for resolving a (potential) class namejava.lang.ClassNotFoundException
- if the class name could be resolvedpublic void setScope(java.lang.String scope)
Default is singleton status, although this is only applied once a bean definition becomes active in the containing factory. A bean definition may eventually inherit its scope from a parent bean definitionFor this reason, the default scope name is empty (empty String), with singleton status being assumed until a resolved scope will be set.
setScope
in interface BeanDefinition
BeanDefinition.SCOPE_SINGLETON
,
BeanDefinition.SCOPE_PROTOTYPE
public java.lang.String getScope()
getScope
in interface BeanDefinition
public boolean isSingleton()
isSingleton
in interface BeanDefinition
BeanDefinition.SCOPE_SINGLETON
public boolean isPrototype()
isPrototype
in interface BeanDefinition
BeanDefinition.SCOPE_PROTOTYPE
public void setAbstract(boolean abstractFlag)
Default is "false". Specify true to tell the bean factory to not try to instantiate that particular bean in any case.
public boolean isAbstract()
isAbstract
in interface BeanDefinition
public void setLazyInit(boolean lazyInit)
If false
, the bean will get instantiated on startup by bean
factories that perform eager initialization of singletons.
setLazyInit
in interface BeanDefinition
public boolean isLazyInit()
isLazyInit
in interface BeanDefinition
public void setAutowireMode(int autowireMode)
autowireMode
- the autowire mode to set.
Must be one of the constants defined in this class.AUTOWIRE_NO
,
AUTOWIRE_BY_NAME
,
AUTOWIRE_BY_TYPE
,
AUTOWIRE_CONSTRUCTOR
,
AUTOWIRE_AUTODETECT
public int getAutowireMode()
public int getResolvedAutowireMode()
AUTOWIRE_AUTODETECT
,
AUTOWIRE_CONSTRUCTOR
,
AUTOWIRE_BY_TYPE
public void setDependencyCheck(int dependencyCheck)
dependencyCheck
- the code to set.
Must be one of the four constants defined in this class.DEPENDENCY_CHECK_NONE
,
DEPENDENCY_CHECK_OBJECTS
,
DEPENDENCY_CHECK_SIMPLE
,
DEPENDENCY_CHECK_ALL
public int getDependencyCheck()
public void setDependsOn(java.lang.String[] dependsOn)
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.
setDependsOn
in interface BeanDefinition
public java.lang.String[] getDependsOn()
getDependsOn
in interface BeanDefinition
public void setAutowireCandidate(boolean autowireCandidate)
setAutowireCandidate
in interface BeanDefinition
public boolean isAutowireCandidate()
isAutowireCandidate
in interface BeanDefinition
public void setPrimary(boolean primary)
setPrimary
in interface BeanDefinition
public boolean isPrimary()
isPrimary
in interface BeanDefinition
public void addQualifier(AutowireCandidateQualifier qualifier)
AutowireCandidateQualifier.getTypeName()
public boolean hasQualifier(java.lang.String typeName)
public AutowireCandidateQualifier getQualifier(java.lang.String typeName)
public java.util.Set<AutowireCandidateQualifier> getQualifiers()
AutowireCandidateQualifier
objects.public void copyQualifiersFrom(AbstractBeanDefinition source)
source
- the AbstractBeanDefinition to copy frompublic void setNonPublicAccessAllowed(boolean nonPublicAccessAllowed)
true
; switch this to false
for public access only.
This applies to constructor resolution, factory method resolution, and also init/destroy methods. Bean property accessors have to be public in any case and are not affected by this setting.
Note that annotation-driven configuration will still access non-public members as far as they have been annotated. This setting applies to externalized metadata in this bean definition only.
public boolean isNonPublicAccessAllowed()
public void setLenientConstructorResolution(boolean lenientConstructorResolution)
true
,
which is the default) or to switch to strict resolution (throwing an exception
in case of ambiguous constructors that all match when converting the arguments,
whereas lenient mode would use the one with the 'closest' type matches).public boolean isLenientConstructorResolution()
public void setConstructorArgumentValues(ConstructorArgumentValues constructorArgumentValues)
public ConstructorArgumentValues getConstructorArgumentValues()
null
).getConstructorArgumentValues
in interface BeanDefinition
null
)public boolean hasConstructorArgumentValues()
public void setPropertyValues(MutablePropertyValues propertyValues)
public MutablePropertyValues getPropertyValues()
null
).getPropertyValues
in interface BeanDefinition
null
)public void setMethodOverrides(MethodOverrides methodOverrides)
public MethodOverrides getMethodOverrides()
public void setFactoryBeanName(java.lang.String factoryBeanName)
BeanDefinition
setFactoryBeanName
in interface BeanDefinition
public java.lang.String getFactoryBeanName()
BeanDefinition
getFactoryBeanName
in interface BeanDefinition
public void setFactoryMethodName(java.lang.String factoryMethodName)
BeanDefinition
setFactoryMethodName
in interface BeanDefinition
factoryMethodName
- static factory method name,
or null
if normal constructor creation should be usedBeanDefinition.getBeanClassName()
public java.lang.String getFactoryMethodName()
BeanDefinition
getFactoryMethodName
in interface BeanDefinition
public void setInitMethodName(java.lang.String initMethodName)
null
in which case there is no initializer method.public java.lang.String getInitMethodName()
public void setEnforceInitMethod(boolean enforceInitMethod)
false
.setInitMethodName(java.lang.String)
public boolean isEnforceInitMethod()
getInitMethodName()
public void setDestroyMethodName(java.lang.String destroyMethodName)
null
in which case there is no destroy method.public java.lang.String getDestroyMethodName()
public void setEnforceDestroyMethod(boolean enforceDestroyMethod)
false
.setDestroyMethodName(java.lang.String)
public boolean isEnforceDestroyMethod()
getDestroyMethodName()
public void setSynthetic(boolean synthetic)
<aop:config>
).public boolean isSynthetic()
public void setRole(int role)
BeanDefinition
.public int getRole()
BeanDefinition
.getRole
in interface BeanDefinition
BeanDefinition.ROLE_APPLICATION
,
BeanDefinition.ROLE_SUPPORT
,
BeanDefinition.ROLE_INFRASTRUCTURE
public void setDescription(java.lang.String description)
public java.lang.String getDescription()
BeanDefinition
getDescription
in interface BeanDefinition
public void setResource(Resource resource)
public Resource getResource()
public void setResourceDescription(java.lang.String resourceDescription)
public java.lang.String getResourceDescription()
BeanDefinition
getResourceDescription
in interface BeanDefinition
public void setOriginatingBeanDefinition(BeanDefinition originatingBd)
public BeanDefinition getOriginatingBeanDefinition()
BeanDefinition
null
if none.
Allows for retrieving the decorated bean definition, if any.
Note that this method returns the immediate originator. Iterate through the originator chain to find the original BeanDefinition as defined by the user.
getOriginatingBeanDefinition
in interface BeanDefinition
public void validate() throws BeanDefinitionValidationException
BeanDefinitionValidationException
- in case of validation failurepublic void prepareMethodOverrides() throws BeanDefinitionValidationException
BeanDefinitionValidationException
- in case of validation failureprotected void prepareMethodOverride(MethodOverride mo) throws BeanDefinitionValidationException
mo
- the MethodOverride object to validateBeanDefinitionValidationException
- in case of validation failurepublic java.lang.Object clone()
clone()
method.
Delegates to cloneBeanDefinition()
.clone
in class java.lang.Object
Object.clone()
public abstract AbstractBeanDefinition cloneBeanDefinition()
public boolean equals(java.lang.Object other)
equals
in class AttributeAccessorSupport
public int hashCode()
hashCode
in class AttributeAccessorSupport
public java.lang.String toString()
toString
in class java.lang.Object