Class ConstructorArg
java.lang.Object
org.apache.commons.configuration2.beanutils.ConstructorArg
A class representing an argument for a constructor invocation to be used by a BeanDeclaration
.
A BeanDeclaration
can provide a list of instances of this class to define the constructor to be invoked on
the bean class. Each constructor argument can either be a simple value or a nested BeanDeclaration
. In the
latter case, the bean is resolved recursively.
The constructor to be invoked on the bean class has to be determined based on the types of the constructor arguments. To avoid ambiguity, the type name can be explicitly provided.
- Since:
- 2.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic ConstructorArg
Creates a new instance ofConstructorArg
for the specifiedBeanDeclaration
.static ConstructorArg
forBeanDeclaration
(BeanDeclaration beanDeclaration, String typeName) Creates a new instance ofConstructorArg
for the specifiedBeanDeclaration
and sets the type name explicitly.static ConstructorArg
Creates a new instance ofConstructorArg
for the specified simple value.static ConstructorArg
Creates a new instance ofConstructorArg
for the specified simple value and sets the type name explicitly.Gets theBeanDeclaration
referenced by this constructor argument.Gets the optional data type name of this constructor argument.getValue()
Gets the value of this constructor argument.boolean
Tests whether this constructor argument represents aBeanDeclaration
.boolean
Checks whether this constructor argument is compatible with the given class.toString()
Gets a string representation of this object.
-
Method Details
-
forBeanDeclaration
Creates a new instance ofConstructorArg
for the specifiedBeanDeclaration
. The actual value of this argument is the resolvedBeanDeclaration
.- Parameters:
decl
- theBeanDeclaration
- Returns:
- the newly created instance of this class
- Throws:
NullPointerException
- if theBeanDeclaration
is null
-
forBeanDeclaration
Creates a new instance ofConstructorArg
for the specifiedBeanDeclaration
and sets the type name explicitly. The type name is used to match this argument against the parameter type of a constructor or the bean class.- Parameters:
beanDeclaration
- theBeanDeclaration
typeName
- the name of the data type of this argument- Returns:
- the newly created instance of this class
- Throws:
NullPointerException
- if theBeanDeclaration
is null
-
forValue
Creates a new instance ofConstructorArg
for the specified simple value. The value is passed to the constructor invocation.- Parameters:
value
- the value of this constructor argument (may be null)- Returns:
- the newly created instance of this class
-
forValue
Creates a new instance ofConstructorArg
for the specified simple value and sets the type name explicitly. The type name is used to match this argument against the parameter type of a constructor or the bean class.- Parameters:
value
- the value of this constructor argument (may be null)typeName
- the name of the data type of this argument- Returns:
- the newly created instance of this class
-
getBeanDeclaration
Gets theBeanDeclaration
referenced by this constructor argument. A return value of null means that this constructor argument does not have a bean declaration as value; in this case, the value can be queried using thegetValue()
method.- Returns:
- the referenced
BeanDeclaration
or null
-
getTypeName
Gets the optional data type name of this constructor argument. The type name can be specified as a hint to select a specific constructor if there are ambiguities. Note that it does not necessarily has to match the data type of this argument's value because a type conversion may be performed before invoking the constructor.- Returns:
- the data type name of this argument if defined or null otherwise
-
getValue
Gets the value of this constructor argument. This method can be queried ifisNestedBeanDeclaration()
returns false. Note that a return value of null is legal (to pass null to a constructor argument).- Returns:
- the simple value of this constructor argument
-
isNestedBeanDeclaration
Tests whether this constructor argument represents aBeanDeclaration
. If this method returns true, the actual value of this argument can be obtained by resolving the bean declaration returned bygetBeanDeclaration()
. Otherwise, this argument has a simple value which can be queried usinggetValue()
.- Returns:
- whether this constructor argument references a bean declaration
-
matches
Checks whether this constructor argument is compatible with the given class. This method is called to determine a matching constructor. It compares the argument's data type with the class name if it is defined. If no type name has been set, result is true as it is assumed that a type conversion can be performed when calling the constructor. This means that per default only the number of constructor arguments is checked to find a matching constructor. Only if there are multiple constructors with the same number of arguments, explicit type names have to be provided to select a specific constructor.- Parameters:
argCls
- the class of the constructor argument to compare with- Returns:
- true if this constructor argument is compatible with this class, false otherwise
-
toString
Gets a string representation of this object. This string contains the value of this constructor argument and the explicit type if provided.
-