Top Description Inners Fields Constructors Methods
org.springframework.beans.factory.support

public Class BeanDefinitionValueResolver

extends Object
Class Inheritance
Imports
java.lang.reflect.Array, java.util.ArrayList, .LinkedHashSet, .List, .Map, .Properties, .Set, java.util.function.BiFunction, org.springframework.beans.BeanWrapper, .BeanWrapperImpl, .BeansException, .TypeConverter, org.springframework.beans.factory.BeanCreationException, .BeanDefinitionStoreException, .BeanFactory, .BeanFactoryUtils, .FactoryBean, org.springframework.beans.factory.config.BeanDefinition, .BeanDefinitionHolder, .DependencyDescriptor, .NamedBeanHolder, .RuntimeBeanNameReference, .RuntimeBeanReference, .TypedStringValue, org.springframework.lang.Nullable, org.springframework.util.ClassUtils, .CollectionUtils, .ObjectUtils, .StringUtils

Helper class for use in bean factory implementations, resolving values contained in bean definition objects into the actual values applied to the target bean instance.

Operates on an AbstractBeanFactory and a plain org.springframework.beans.factory.config.BeanDefinition object. Used by AbstractAutowireCapableBeanFactory.

Authors
Juergen Hoeller, Sam Brannen, Stephane Nicoll
Since
1.2
See Also
AbstractAutowireCapableBeanFactory

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
BeanDefinitionValueResolver.KeyedArgName

Holder class used for delayed toString building.

Field Summary

Modifier and TypeField and Description
private final BeanDefinition
private final AbstractAutowireCapableBeanFactory
private final String
private final TypeConverter

Constructor Summary

AccessConstructor and Description
public
BeanDefinitionValueResolver(AbstractAutowireCapableBeanFactory
the BeanFactory to resolve against
beanFactory
,
String
the name of the bean that we work on
beanName
,
BeanDefinition
the BeanDefinition of the bean that we work on
beanDefinition
,
TypeConverter
the TypeConverter to use for resolving TypedStringValues
typeConverter
)

Create a BeanDefinitionValueResolver for the given BeanFactory and BeanDefinition, using the given TypeConverter.

public
BeanDefinitionValueResolver(AbstractAutowireCapableBeanFactory
the BeanFactory to resolve against
beanFactory
,
String
the name of the bean that we work on
beanName
,
BeanDefinition
the BeanDefinition of the bean that we work on
beanDefinition
)

Create a BeanDefinitionValueResolver for the given BeanFactory and BeanDefinition using a default TypeConverter.

Method Summary

Modifier and TypeMethod and Description
private String

Returns:

the adapted name for the inner bean
adaptInnerBeanName
(String
the original name for the inner bean
innerBeanName
)

Checks the given bean name whether it is unique.

private Object

Returns:

the resolved value if necessary, or the original String value
doEvaluate
(String
the original value (may be an expression)
value
)

Evaluate the given String value as an expression, if necessary.

protected Object

Returns:

the resolved value
evaluate
(TypedStringValue
the candidate value (may be an expression)
value
)

Evaluate the given value as an expression, if necessary.

protected Object

Returns:

the resolved value if necessary, or the original value
evaluate
(Object
the original value (may be an expression)
value
)

Evaluate the given value as an expression, if necessary.

public <
the type of the resolution
T
>
T

Returns:

a resolved inner bean, as a result of applying the resolver
resolveInnerBean
(String
the inner bean name (or null to assign one)
innerBeanName
,
BeanDefinition
the inner raw bean definition
innerBd
,
BiFunction<String, RootBeanDefinition, T>
the function to invoke to resolve
resolver
)

Resolve an inner bean definition and invoke the specified resolver on its merged bean definition.

private Object

Returns:

the resolved inner bean instance
resolveInnerBeanValue
(Object
the name of the argument that the inner bean is defined for
argName
,
String
the name of the inner bean
innerBeanName
,
RootBeanDefinition
the merged bean definition for the inner bean
mbd
)

Resolve an inner bean definition.

private Object
resolveManagedArray(Object argName, List<?> ml, Class<?> elementType)

For each element in the managed array, resolve reference if necessary.

private List<?>
resolveManagedList(Object argName, List<?> ml)

For each element in the managed list, resolve reference if necessary.

private Map<?, ?>
resolveManagedMap(Object argName, Map<?, ?> mm)

For each element in the managed map, resolve reference if necessary.

private Set<?>
resolveManagedSet(Object argName, Set<?> ms)

For each element in the managed set, resolve reference if necessary.

private Object
resolveReference(Object argName, RuntimeBeanReference ref)

Resolve a reference to another bean in the factory.

protected Class<?>

Returns:

the resolved target type (or null if none specified)
resolveTargetType
(TypedStringValue
the TypedStringValue to resolve
value
)

Resolve the target type in the given TypedStringValue.

public Object

Returns:

the resolved object
resolveValueIfNecessary
(Object
the name of the argument that the value is defined for
argName
,
Object
the value object to resolve
value
)

Given a PropertyValue, return a value, resolving any references to other beans in the factory if necessary.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

beanDefinitionback to summary
private final BeanDefinition beanDefinition
beanFactoryback to summary
private final AbstractAutowireCapableBeanFactory beanFactory
beanNameback to summary
private final String beanName
typeConverterback to summary
private final TypeConverter typeConverter

Constructor Detail

BeanDefinitionValueResolverback to summary
public BeanDefinitionValueResolver(AbstractAutowireCapableBeanFactory beanFactory, String beanName, BeanDefinition beanDefinition, TypeConverter typeConverter)

Create a BeanDefinitionValueResolver for the given BeanFactory and BeanDefinition, using the given TypeConverter.

Parameters
beanFactory:AbstractAutowireCapableBeanFactory

the BeanFactory to resolve against

beanName:String

the name of the bean that we work on

beanDefinition:BeanDefinition

the BeanDefinition of the bean that we work on

typeConverter:TypeConverter

the TypeConverter to use for resolving TypedStringValues

BeanDefinitionValueResolverback to summary
public BeanDefinitionValueResolver(AbstractAutowireCapableBeanFactory beanFactory, String beanName, BeanDefinition beanDefinition)

Create a BeanDefinitionValueResolver for the given BeanFactory and BeanDefinition using a default TypeConverter.

Parameters
beanFactory:AbstractAutowireCapableBeanFactory

the BeanFactory to resolve against

beanName:String

the name of the bean that we work on

beanDefinition:BeanDefinition

the BeanDefinition of the bean that we work on

Method Detail

adaptInnerBeanNameback to summary
private String adaptInnerBeanName(String innerBeanName)

Checks the given bean name whether it is unique. If not already unique, a counter is added, increasing the counter until the name is unique.

Parameters
innerBeanName:String

the original name for the inner bean

Returns:String

the adapted name for the inner bean

doEvaluateback to summary
private Object doEvaluate(String value)

Evaluate the given String value as an expression, if necessary.

Parameters
value:String

the original value (may be an expression)

Returns:Object

the resolved value if necessary, or the original String value

Annotations
@Nullable
evaluateback to summary
protected Object evaluate(TypedStringValue value)

Evaluate the given value as an expression, if necessary.

Parameters
value:TypedStringValue

the candidate value (may be an expression)

Returns:Object

the resolved value

Annotations
@Nullable
evaluateback to summary
protected Object evaluate(Object value)

Evaluate the given value as an expression, if necessary.

Parameters
value:Object

the original value (may be an expression)

Returns:Object

the resolved value if necessary, or the original value

Annotations
@Nullable
resolveInnerBeanback to summary
public <T> T resolveInnerBean(String innerBeanName, BeanDefinition innerBd, BiFunction<String, RootBeanDefinition, T> resolver)

Resolve an inner bean definition and invoke the specified resolver on its merged bean definition.

Parameters
<T>
the type of the resolution
innerBeanName:String

the inner bean name (or null to assign one)

innerBd:BeanDefinition

the inner raw bean definition

resolver:BiFunction<String, RootBeanDefinition, T>

the function to invoke to resolve

Returns:T

a resolved inner bean, as a result of applying the resolver

Since
6.0
resolveInnerBeanValueback to summary
private Object resolveInnerBeanValue(Object argName, String innerBeanName, RootBeanDefinition mbd)

Resolve an inner bean definition.

Parameters
argName:Object

the name of the argument that the inner bean is defined for

innerBeanName:String

the name of the inner bean

mbd:RootBeanDefinition

the merged bean definition for the inner bean

Returns:Object

the resolved inner bean instance

Annotations
@Nullable
resolveManagedArrayback to summary
private Object resolveManagedArray(Object argName, List<?> ml, Class<?> elementType)

For each element in the managed array, resolve reference if necessary.

resolveManagedListback to summary
private List<?> resolveManagedList(Object argName, List<?> ml)

For each element in the managed list, resolve reference if necessary.

resolveManagedMapback to summary
private Map<?, ?> resolveManagedMap(Object argName, Map<?, ?> mm)

For each element in the managed map, resolve reference if necessary.

resolveManagedSetback to summary
private Set<?> resolveManagedSet(Object argName, Set<?> ms)

For each element in the managed set, resolve reference if necessary.

resolveReferenceback to summary
private Object resolveReference(Object argName, RuntimeBeanReference ref)

Resolve a reference to another bean in the factory.

Annotations
@Nullable
resolveTargetTypeback to summary
protected Class<?> resolveTargetType(TypedStringValue value) throws ClassNotFoundException

Resolve the target type in the given TypedStringValue.

Parameters
value:TypedStringValue

the TypedStringValue to resolve

Returns:Class<?>

the resolved target type (or null if none specified)

Annotations
@Nullable
Exceptions
ClassNotFoundException:
if the specified type cannot be resolved
See Also
TypedStringValue#resolveTargetType
resolveValueIfNecessaryback to summary
public Object resolveValueIfNecessary(Object argName, Object value)

Given a PropertyValue, return a value, resolving any references to other beans in the factory if necessary. The value could be:

  • A BeanDefinition, which leads to the creation of a corresponding new bean instance. Singleton flags and names of such "inner beans" are always ignored: Inner beans are anonymous prototypes.
  • A RuntimeBeanReference, which must be resolved.
  • A ManagedList. This is a special collection that may contain RuntimeBeanReferences or Collections that will need to be resolved.
  • A ManagedSet. May also contain RuntimeBeanReferences or Collections that will need to be resolved.
  • A ManagedMap. In this case the value may be a RuntimeBeanReference or Collection that will need to be resolved.
  • An ordinary object or null, in which case it's left alone.
    Parameters
    argName:Object

    the name of the argument that the value is defined for

    value:Object

    the value object to resolve

    Returns:Object

    the resolved object

    Annotations
    @Nullable
  • org.springframework.beans.factory.support back to summary

    private Class BeanDefinitionValueResolver.KeyedArgName

    extends Object
    Class Inheritance
    • java.lang.Object
    • org.springframework.beans.factory.support.BeanDefinitionValueResolver.KeyedArgName

    Holder class used for delayed toString building.

    Field Summary

    Modifier and TypeField and Description
    private final Object
    private final Object

    Constructor Summary

    AccessConstructor and Description
    public
    KeyedArgName(Object argName, Object key)

    Method Summary

    Modifier and TypeMethod and Description
    public String
    toString()

    Overrides java.lang.Object.toString.

    Returns a string representation of the object.

    Inherited from java.lang.Object:
    cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

    Field Detail

    argNameback to summary
    private final Object argName
    keyback to summary
    private final Object key

    Constructor Detail

    KeyedArgNameback to summary
    public KeyedArgName(Object argName, Object key)

    Method Detail

    toStringback to summary
    public String toString()

    Overrides java.lang.Object.toString.

    Doc from java.lang.Object.toString.

    Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

    Returns:String

    a string representation of the object

    Annotations
    @Override