public final class ConstructorArg extends Object
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.
Modifier and Type | Method and Description |
---|---|
static ConstructorArg |
forBeanDeclaration(BeanDeclaration decl)
Creates a new instance of
ConstructorArg for the specified
BeanDeclaration . |
static ConstructorArg |
forBeanDeclaration(BeanDeclaration beanDeclaration,
String typeName)
Creates a new instance of
ConstructorArg for the specified
BeanDeclaration and sets the type name explicitly. |
static ConstructorArg |
forValue(Object value)
Creates a new instance of
ConstructorArg for the specified simple
value. |
static ConstructorArg |
forValue(Object value,
String typeName)
Creates a new instance of
ConstructorArg for the specified simple
value and sets the type name explicitly. |
BeanDeclaration |
getBeanDeclaration()
Returns the
BeanDeclaration referenced by this constructor
argument. |
String |
getTypeName()
Returns the optional data type name of this constructor argument.
|
Object |
getValue()
Returns the value of this constructor argument.
|
boolean |
isNestedBeanDeclaration()
Returns a flag whether this constructor argument represents a
BeanDeclaration . |
boolean |
matches(Class<?> argCls)
Checks whether this constructor argument is compatible with the given
class.
|
String |
toString()
Returns a string representation of this object.
|
public static ConstructorArg forBeanDeclaration(BeanDeclaration decl)
ConstructorArg
for the specified
BeanDeclaration
. The actual value of this argument is the
resolved BeanDeclaration
.decl
- the BeanDeclaration
NullPointerException
- if the BeanDeclaration
is
nullpublic static ConstructorArg forBeanDeclaration(BeanDeclaration beanDeclaration, String typeName)
ConstructorArg
for the specified
BeanDeclaration
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.beanDeclaration
- the BeanDeclaration
typeName
- the name of the data type of this argumentNullPointerException
- if the BeanDeclaration
is
nullpublic static ConstructorArg forValue(Object value)
ConstructorArg
for the specified simple
value. The value is passed to the constructor invocation.value
- the value of this constructor argument (may be null)public static ConstructorArg forValue(Object value, String typeName)
ConstructorArg
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.value
- the value of this constructor argument (may be null)typeName
- the name of the data type of this argumentpublic BeanDeclaration getBeanDeclaration()
BeanDeclaration
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 the getValue()
method.BeanDeclaration
or nullpublic boolean isNestedBeanDeclaration()
BeanDeclaration
. If this method returns true, the actual
value of this argument can be obtained by resolving the bean declaration
returned by getBeanDeclaration()
. Otherwise, this argument has a
simple value which can be queried using getValue()
.public Object getValue()
isNestedBeanDeclaration()
returns false. Note
that a return value of null is legal (to pass null to a
constructor argument).public String getTypeName()
public boolean matches(Class<?> argCls)
argCls
- the class of the constructor argument to compare withCopyright © 2001–2020 The Apache Software Foundation. All rights reserved.