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

public Class ConstructorArgumentValues

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Collections, .Iterator, .LinkedHashMap, .List, .Map, .Set, org.springframework.beans.BeanMetadataElement, .Mergeable, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .ObjectUtils

Holder for constructor argument values, typically as part of a bean definition.

Supports values for a specific index in the constructor argument list as well as for generic argument matches by type.

Author
Juergen Hoeller
Since
09.11.2003
See Also
BeanDefinition#getConstructorArgumentValues

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ConstructorArgumentValues.ValueHolder

Holder for a constructor argument value, with an optional type attribute indicating the target type of the actual constructor argument.

Field Summary

Modifier and TypeField and Description
private final List<ConstructorArgumentValues.ValueHolder>
private final Map<Integer, ConstructorArgumentValues.ValueHolder>

Constructor Summary

AccessConstructor and Description
public
ConstructorArgumentValues()

Create a new empty ConstructorArgumentValues object.

public
ConstructorArgumentValues(ConstructorArgumentValues
the ConstructorArgumentValues to copy
original
)

Deep copy constructor.

Method Summary

Modifier and TypeMethod and Description
public void
addArgumentValues(ConstructorArgumentValues other)

Copy all given argument values into this object, using separate holder instances to keep the values independent of the original object.

public void
addGenericArgumentValue(Object
the argument value
value
)

Add a generic argument value to be matched by type.

public void
addGenericArgumentValue(Object
the argument value
value
,
String
the type of the constructor argument
type
)

Add a generic argument value to be matched by type.

public void
addGenericArgumentValue(ConstructorArgumentValues.ValueHolder
the argument value in the form of a ValueHolder

Note

Identical ValueHolder instances will only be registered once, to allow for merging and re-merging of argument value definitions. Distinct ValueHolder instances carrying the same content are of course allowed.

newValue
)

Add a generic argument value to be matched by type or name (if available).

public void
addIndexedArgumentValue(int
the index in the constructor argument list
index
,
Object
the argument value
value
)

Add an argument value for the given index in the constructor argument list.

public void
addIndexedArgumentValue(int
the index in the constructor argument list
index
,
Object
the argument value
value
,
String
the type of the constructor argument
type
)

Add an argument value for the given index in the constructor argument list.

public void
addIndexedArgumentValue(int
the index in the constructor argument list
index
,
ConstructorArgumentValues.ValueHolder
the argument value in the form of a ValueHolder
newValue
)

Add an argument value for the given index in the constructor argument list.

private void
addOrMergeGenericArgumentValue(ConstructorArgumentValues.ValueHolder
the argument value in the form of a ValueHolder
newValue
)

Add a generic argument value, merging the new value (typically a collection) with the current value if demanded: see org.springframework.beans.Mergeable.

private void
addOrMergeIndexedArgumentValue(Integer
the index in the constructor argument list
key
,
ConstructorArgumentValues.ValueHolder
the argument value in the form of a ValueHolder
newValue
)

Add an argument value for the given index in the constructor argument list, merging the new value (typically a collection) with the current value if demanded: see org.springframework.beans.Mergeable.

public void
clear()

Clear this holder, removing all argument values.

public boolean
containsNamedArgument()

Determine whether at least one argument value refers to a name.

public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public int
getArgumentCount()

Return the number of argument values held in this instance, counting both indexed and generic argument values.

public ConstructorArgumentValues.ValueHolder

Returns:

the ValueHolder for the argument, or null if none set
getArgumentValue
(int
the index in the constructor argument list
index
,
Class<?>
the parameter type to match
requiredType
)

Look for an argument value that either corresponds to the given index in the constructor argument list or generically matches by type.

public ConstructorArgumentValues.ValueHolder

Returns:

the ValueHolder for the argument, or null if none set
getArgumentValue
(int
the index in the constructor argument list
index
,
Class<?>
the parameter type to match
requiredType
,
String
the parameter name to match
requiredName
)

Look for an argument value that either corresponds to the given index in the constructor argument list or generically matches by type.

public ConstructorArgumentValues.ValueHolder

Returns:

the ValueHolder for the argument, or null if none set
getArgumentValue
(int
the index in the constructor argument list
index
,
Class<?>
the parameter type to match (can be null to find an untyped argument value)
requiredType
,
String
the parameter name to match (can be null to find an unnamed argument value, or empty String to match any name)
requiredName
,
Set<ConstructorArgumentValues.ValueHolder>
a Set of ValueHolder objects that have already been used in the current resolution process and should therefore not be returned again (allowing to return the next generic argument match in case of multiple generic argument values of the same type)
usedValueHolders
)

Look for an argument value that either corresponds to the given index in the constructor argument list or generically matches by type.

public ConstructorArgumentValues.ValueHolder

Returns:

the ValueHolder for the argument, or null if none set
getGenericArgumentValue
(Class<?>
the type to match
requiredType
)

Look for a generic argument value that matches the given type.

public ConstructorArgumentValues.ValueHolder

Returns:

the ValueHolder for the argument, or null if none set
getGenericArgumentValue
(Class<?>
the type to match
requiredType
,
String
the name to match
requiredName
)

Look for a generic argument value that matches the given type.

public ConstructorArgumentValues.ValueHolder

Returns:

the ValueHolder for the argument, or null if none found
getGenericArgumentValue
(Class<?>
the type to match (can be null to find an arbitrary next generic argument value)
requiredType
,
String
the name to match (can be null to not match argument values by name, or empty String to match any name)
requiredName
,
Set<ConstructorArgumentValues.ValueHolder>
a Set of ValueHolder objects that have already been used in the current resolution process and should therefore not be returned again
usedValueHolders
)

Look for the next generic argument value that matches the given type, ignoring argument values that have already been used in the current resolution process.

public List<ConstructorArgumentValues.ValueHolder>

Returns:

unmodifiable List of ValueHolders
getGenericArgumentValues
()

Return the list of generic argument values.

public ConstructorArgumentValues.ValueHolder

Returns:

the ValueHolder for the argument, or null if none set
getIndexedArgumentValue
(int
the index in the constructor argument list
index
,
Class<?>
the type to match (can be null to match untyped values only)
requiredType
)

Get argument value for the given index in the constructor argument list.

public ConstructorArgumentValues.ValueHolder

Returns:

the ValueHolder for the argument, or null if none set
getIndexedArgumentValue
(int
the index in the constructor argument list
index
,
Class<?>
the type to match (can be null to match untyped values only)
requiredType
,
String
the type to match (can be null to match unnamed values only, or empty String to match any name)
requiredName
)

Get argument value for the given index in the constructor argument list.

public Map<Integer, ConstructorArgumentValues.ValueHolder>

Returns:

unmodifiable Map with Integer index as key and ValueHolder as value
getIndexedArgumentValues
()

Return the map of indexed argument values.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public boolean
hasIndexedArgumentValue(int
the index in the constructor argument list
index
)

Check whether an argument value has been registered for the given index.

public boolean
isEmpty()

Return if this holder does not contain any argument values, neither indexed ones nor generic ones.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

genericArgumentValuesback to summary
private final List<ConstructorArgumentValues.ValueHolder> genericArgumentValues
indexedArgumentValuesback to summary
private final Map<Integer, ConstructorArgumentValues.ValueHolder> indexedArgumentValues

Constructor Detail

ConstructorArgumentValuesback to summary
public ConstructorArgumentValues()

Create a new empty ConstructorArgumentValues object.

ConstructorArgumentValuesback to summary
public ConstructorArgumentValues(ConstructorArgumentValues original)

Deep copy constructor.

Parameters
original:ConstructorArgumentValues

the ConstructorArgumentValues to copy

Method Detail

addArgumentValuesback to summary
public void addArgumentValues(ConstructorArgumentValues other)

Copy all given argument values into this object, using separate holder instances to keep the values independent of the original object.

Note

Identical ValueHolder instances will only be registered once, to allow for merging and re-merging of argument value definitions. Distinct ValueHolder instances carrying the same content are of course allowed.

addGenericArgumentValueback to summary
public void addGenericArgumentValue(Object value)

Add a generic argument value to be matched by type.

Note

A single generic argument value will just be used once, rather than matched multiple times.

Parameters
value:Object

the argument value

addGenericArgumentValueback to summary
public void addGenericArgumentValue(Object value, String type)

Add a generic argument value to be matched by type.

Note

A single generic argument value will just be used once, rather than matched multiple times.

Parameters
value:Object

the argument value

type:String

the type of the constructor argument

addGenericArgumentValueback to summary
public void addGenericArgumentValue(ConstructorArgumentValues.ValueHolder newValue)

Add a generic argument value to be matched by type or name (if available).

Note

A single generic argument value will just be used once, rather than matched multiple times.

Parameters
newValue:ConstructorArgumentValues.ValueHolder

the argument value in the form of a ValueHolder

Note

Identical ValueHolder instances will only be registered once, to allow for merging and re-merging of argument value definitions. Distinct ValueHolder instances carrying the same content are of course allowed.

addIndexedArgumentValueback to summary
public void addIndexedArgumentValue(int index, Object value)

Add an argument value for the given index in the constructor argument list.

Parameters
index:int

the index in the constructor argument list

value:Object

the argument value

addIndexedArgumentValueback to summary
public void addIndexedArgumentValue(int index, Object value, String type)

Add an argument value for the given index in the constructor argument list.

Parameters
index:int

the index in the constructor argument list

value:Object

the argument value

type:String

the type of the constructor argument

addIndexedArgumentValueback to summary
public void addIndexedArgumentValue(int index, ConstructorArgumentValues.ValueHolder newValue)

Add an argument value for the given index in the constructor argument list.

Parameters
index:int

the index in the constructor argument list

newValue:ConstructorArgumentValues.ValueHolder

the argument value in the form of a ValueHolder

addOrMergeGenericArgumentValueback to summary
private void addOrMergeGenericArgumentValue(ConstructorArgumentValues.ValueHolder newValue)

Add a generic argument value, merging the new value (typically a collection) with the current value if demanded: see org.springframework.beans.Mergeable.

Parameters
newValue:ConstructorArgumentValues.ValueHolder

the argument value in the form of a ValueHolder

addOrMergeIndexedArgumentValueback to summary
private void addOrMergeIndexedArgumentValue(Integer key, ConstructorArgumentValues.ValueHolder newValue)

Add an argument value for the given index in the constructor argument list, merging the new value (typically a collection) with the current value if demanded: see org.springframework.beans.Mergeable.

Parameters
key:Integer

the index in the constructor argument list

newValue:ConstructorArgumentValues.ValueHolder

the argument value in the form of a ValueHolder

clearback to summary
public void clear()

Clear this holder, removing all argument values.

containsNamedArgumentback to summary
public boolean containsNamedArgument()

Determine whether at least one argument value refers to a name.

Since
6.0.3
See Also
ValueHolder#getName()
equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getArgumentCountback to summary
public int getArgumentCount()

Return the number of argument values held in this instance, counting both indexed and generic argument values.

getArgumentValueback to summary
public ConstructorArgumentValues.ValueHolder getArgumentValue(int index, Class<?> requiredType)

Look for an argument value that either corresponds to the given index in the constructor argument list or generically matches by type.

Parameters
index:int

the index in the constructor argument list

requiredType:Class<?>

the parameter type to match

Returns:ConstructorArgumentValues.ValueHolder

the ValueHolder for the argument, or null if none set

Annotations
@Nullable
getArgumentValueback to summary
public ConstructorArgumentValues.ValueHolder getArgumentValue(int index, Class<?> requiredType, String requiredName)

Look for an argument value that either corresponds to the given index in the constructor argument list or generically matches by type.

Parameters
index:int

the index in the constructor argument list

requiredType:Class<?>

the parameter type to match

requiredName:String

the parameter name to match

Returns:ConstructorArgumentValues.ValueHolder

the ValueHolder for the argument, or null if none set

Annotations
@Nullable
getArgumentValueback to summary
public ConstructorArgumentValues.ValueHolder getArgumentValue(int index, Class<?> requiredType, String requiredName, Set<ConstructorArgumentValues.ValueHolder> usedValueHolders)

Look for an argument value that either corresponds to the given index in the constructor argument list or generically matches by type.

Parameters
index:int

the index in the constructor argument list

requiredType:Class<?>

the parameter type to match (can be null to find an untyped argument value)

requiredName:String

the parameter name to match (can be null to find an unnamed argument value, or empty String to match any name)

usedValueHolders:Set<ConstructorArgumentValues.ValueHolder>

a Set of ValueHolder objects that have already been used in the current resolution process and should therefore not be returned again (allowing to return the next generic argument match in case of multiple generic argument values of the same type)

Returns:ConstructorArgumentValues.ValueHolder

the ValueHolder for the argument, or null if none set

Annotations
@Nullable
getGenericArgumentValueback to summary
public ConstructorArgumentValues.ValueHolder getGenericArgumentValue(Class<?> requiredType)

Look for a generic argument value that matches the given type.

Parameters
requiredType:Class<?>

the type to match

Returns:ConstructorArgumentValues.ValueHolder

the ValueHolder for the argument, or null if none set

Annotations
@Nullable
getGenericArgumentValueback to summary
public ConstructorArgumentValues.ValueHolder getGenericArgumentValue(Class<?> requiredType, String requiredName)

Look for a generic argument value that matches the given type.

Parameters
requiredType:Class<?>

the type to match

requiredName:String

the name to match

Returns:ConstructorArgumentValues.ValueHolder

the ValueHolder for the argument, or null if none set

Annotations
@Nullable
getGenericArgumentValueback to summary
public ConstructorArgumentValues.ValueHolder getGenericArgumentValue(Class<?> requiredType, String requiredName, Set<ConstructorArgumentValues.ValueHolder> usedValueHolders)

Look for the next generic argument value that matches the given type, ignoring argument values that have already been used in the current resolution process.

Parameters
requiredType:Class<?>

the type to match (can be null to find an arbitrary next generic argument value)

requiredName:String

the name to match (can be null to not match argument values by name, or empty String to match any name)

usedValueHolders:Set<ConstructorArgumentValues.ValueHolder>

a Set of ValueHolder objects that have already been used in the current resolution process and should therefore not be returned again

Returns:ConstructorArgumentValues.ValueHolder

the ValueHolder for the argument, or null if none found

Annotations
@Nullable
getGenericArgumentValuesback to summary
public List<ConstructorArgumentValues.ValueHolder> getGenericArgumentValues()

Return the list of generic argument values.

Returns:List<ConstructorArgumentValues.ValueHolder>

unmodifiable List of ValueHolders

See Also
ValueHolder
getIndexedArgumentValueback to summary
public ConstructorArgumentValues.ValueHolder getIndexedArgumentValue(int index, Class<?> requiredType)

Get argument value for the given index in the constructor argument list.

Parameters
index:int

the index in the constructor argument list

requiredType:Class<?>

the type to match (can be null to match untyped values only)

Returns:ConstructorArgumentValues.ValueHolder

the ValueHolder for the argument, or null if none set

Annotations
@Nullable
getIndexedArgumentValueback to summary
public ConstructorArgumentValues.ValueHolder getIndexedArgumentValue(int index, Class<?> requiredType, String requiredName)

Get argument value for the given index in the constructor argument list.

Parameters
index:int

the index in the constructor argument list

requiredType:Class<?>

the type to match (can be null to match untyped values only)

requiredName:String

the type to match (can be null to match unnamed values only, or empty String to match any name)

Returns:ConstructorArgumentValues.ValueHolder

the ValueHolder for the argument, or null if none set

Annotations
@Nullable
getIndexedArgumentValuesback to summary
public Map<Integer, ConstructorArgumentValues.ValueHolder> getIndexedArgumentValues()

Return the map of indexed argument values.

Returns:Map<Integer, ConstructorArgumentValues.ValueHolder>

unmodifiable Map with Integer index as key and ValueHolder as value

See Also
ValueHolder
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
hasIndexedArgumentValueback to summary
public boolean hasIndexedArgumentValue(int index)

Check whether an argument value has been registered for the given index.

Parameters
index:int

the index in the constructor argument list

isEmptyback to summary
public boolean isEmpty()

Return if this holder does not contain any argument values, neither indexed ones nor generic ones.

org.springframework.beans.factory.config back to summary

public Class ConstructorArgumentValues.ValueHolder

extends Object
implements BeanMetadataElement
Class Inheritance
  • java.lang.Object
  • org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder
All Implemented Interfaces
org.springframework.beans.BeanMetadataElement

Holder for a constructor argument value, with an optional type attribute indicating the target type of the actual constructor argument.

Field Summary

Modifier and TypeField and Description
private boolean
private Object
private String
private Object
private String
private Object

Constructor Summary

AccessConstructor and Description
public
ValueHolder(Object
the argument value
value
)

Create a new ValueHolder for the given value.

public
ValueHolder(Object
the argument value
value
,
String
the type of the constructor argument
type
)

Create a new ValueHolder for the given value and type.

public
ValueHolder(Object
the argument value
value
,
String
the type of the constructor argument
type
,
String
the name of the constructor argument
name
)

Create a new ValueHolder for the given value, type and name.

Method Summary

Modifier and TypeMethod and Description
private boolean
contentEquals(ConstructorArgumentValues.ValueHolder other)

Determine whether the content of this ValueHolder is equal to the content of the given other ValueHolder.

private int
contentHashCode()

Determine whether the hash code of the content of this ValueHolder.

public ConstructorArgumentValues.ValueHolder
copy()

Create a copy of this ValueHolder: that is, an independent ValueHolder instance with the same contents.

public synchronized Object
getConvertedValue()

Return the converted value of the constructor argument, after processed type conversion.

public String
getName()

Return the name of the constructor argument.

public Object
getSource()

Overrides default org.springframework.beans.BeanMetadataElement.getSource.

Return the configuration source Object for this metadata element (may be null).
public String
getType()

Return the type of the constructor argument.

public Object
getValue()

Return the value for the constructor argument.

public synchronized boolean
isConverted()

Return whether this holder contains a converted value already (true), or whether the value still needs to be converted (false).

public synchronized void
setConvertedValue(Object value)

Set the converted value of the constructor argument, after processed type conversion.

public void
setName(String name)

Set the name of the constructor argument.

public void
setSource(Object source)

Set the configuration source Object for this metadata element.

public void
setType(String type)

Set the type of the constructor argument.

public void
setValue(Object value)

Set the value for the constructor argument.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

convertedback to summary
private boolean converted
convertedValueback to summary
private Object convertedValue
Annotations
@Nullable
nameback to summary
private String name
Annotations
@Nullable
sourceback to summary
private Object source
Annotations
@Nullable
typeback to summary
private String type
Annotations
@Nullable
valueback to summary
private Object value
Annotations
@Nullable

Constructor Detail

ValueHolderback to summary
public ValueHolder(Object value)

Create a new ValueHolder for the given value.

Parameters
value:Object

the argument value

ValueHolderback to summary
public ValueHolder(Object value, String type)

Create a new ValueHolder for the given value and type.

Parameters
value:Object

the argument value

type:String

the type of the constructor argument

ValueHolderback to summary
public ValueHolder(Object value, String type, String name)

Create a new ValueHolder for the given value, type and name.

Parameters
value:Object

the argument value

type:String

the type of the constructor argument

name:String

the name of the constructor argument

Method Detail

contentEqualsback to summary
private boolean contentEquals(ConstructorArgumentValues.ValueHolder other)

Determine whether the content of this ValueHolder is equal to the content of the given other ValueHolder.

Note that ValueHolder does not implement equals directly, to allow for multiple ValueHolder instances with the same content to reside in the same Set.

contentHashCodeback to summary
private int contentHashCode()

Determine whether the hash code of the content of this ValueHolder.

Note that ValueHolder does not implement hashCode directly, to allow for multiple ValueHolder instances with the same content to reside in the same Set.

copyback to summary
public ConstructorArgumentValues.ValueHolder copy()

Create a copy of this ValueHolder: that is, an independent ValueHolder instance with the same contents.

getConvertedValueback to summary
public synchronized Object getConvertedValue()

Return the converted value of the constructor argument, after processed type conversion.

Annotations
@Nullable
getNameback to summary
public String getName()

Return the name of the constructor argument.

Annotations
@Nullable
getSourceback to summary
public Object getSource()

Overrides default org.springframework.beans.BeanMetadataElement.getSource.

Doc from org.springframework.beans.BeanMetadataElement.getSource.

Return the configuration source Object for this metadata element (may be null).

Annotations
@Override
@Nullable
getTypeback to summary
public String getType()

Return the type of the constructor argument.

Annotations
@Nullable
getValueback to summary
public Object getValue()

Return the value for the constructor argument.

Annotations
@Nullable
isConvertedback to summary
public synchronized boolean isConverted()

Return whether this holder contains a converted value already (true), or whether the value still needs to be converted (false).

setConvertedValueback to summary
public synchronized void setConvertedValue(Object value)

Set the converted value of the constructor argument, after processed type conversion.

setNameback to summary
public void setName(String name)

Set the name of the constructor argument.

setSourceback to summary
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.

setTypeback to summary
public void setType(String type)

Set the type of the constructor argument.

setValueback to summary
public void setValue(Object value)

Set the value for the constructor argument.