public class ConstructorInvocation extends Invocation implements Invokable
A class that represents a constructor invocation.
Instances of this class can be used for creating objects by invoking
constructors on their classes. For this purpose the parameters to be passed
to the constructor must be specified, which is done in form of an array of
Dependency
objects. These dependencies can either refer to other
beans (they will then be resolved by the dependency injection framework), or
can contain constant values that will be directly passed to the constructor.
If the constructor's signature is known, the types of its arguments can be
defined. If this is not the case, the parameter types will be derived from
the current parameter values. The
InvocationHelper
class is used
to find the correct constructor to be invoked.
Objects of this class cannot be changed after they have been created. So they can be shared between multiple clients.
Constructor and Description |
---|
ConstructorInvocation(ClassDescription targetClass,
ClassDescription[] paramTypes,
Dependency... paramValues)
Creates a new instance of
ConstructorInvocation and
initializes it. |
Modifier and Type | Method and Description |
---|---|
protected void |
invocationInfoToString(StringBuilder buf)
Adds additional information about this invocation to the string buffer.
|
Object |
invoke(DependencyProvider depProvider)
Invokes the corresponding constructor on the specified target class and
returns the newly created instance.
|
Object |
invoke(DependencyProvider depProvider,
Object target)
Performs the invocation.
|
checkDependencyProvider, getParameterClasses, getParameterDependencies, getParameterTypes, getResolvedParameters, getTargetClass, isTypeInfoComplete, parametersToString, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getParameterDependencies
public ConstructorInvocation(ClassDescription targetClass, ClassDescription[] paramTypes, Dependency... paramValues)
ConstructorInvocation
and
initializes it. Refer to the base class for a detailed explanation of the
arguments.targetClass
- the class, on which the method is to be invoked (must
not be null)paramTypes
- an array with the parameter typesparamValues
- the current parameter values (defined as
Dependency
objects); this array must not contain null
elementsIllegalArgumentException
- if the length of the parameter types
array does not match the length of the parameter values array, or if the
values array contains null elements, of if the target class is
nullInvocation#Invocation(Class, Class[], Dependency...)
public Object invoke(DependencyProvider depProvider)
DependencyProvider
.depProvider
- the dependency provider (must not be null)InjectionException
- if an error occursIllegalArgumentException
- if the dependency provider is nullpublic Object invoke(DependencyProvider depProvider, Object target)
Invokable
interface. It delegates to the method with the same name, ignoring the
target
parameter (which is not needed for a constructor
invocation).invoke
in interface Invokable
depProvider
- the dependency provider (must not be null)target
- the target of the invocationInjectionException
- if an error occursIllegalArgumentException
- if the dependency provider is
nullprotected void invocationInfoToString(StringBuilder buf)
invocationInfoToString
in class Invocation
buf
- the target bufferCopyright © 2016 The JGUIraffe Team. All rights reserved.