public class MethodInvocation extends Invocation implements Invokable
A class that represents a method invocation.
This class stores all data, which is needed for invoking a method; i.e. the method name, the target class, optional information about the data types of the method parameters, and the current parameter values to be passed to the method.
Once initialized, an instance is immutable. So it can easily be shared
between multiple components and threads without having to care about
synchronization issues. The invoke()
method actually executes
the corresponding method.
Constructor and Description |
---|
MethodInvocation(ClassDescription targetClass,
Dependency targetDep,
String methodName,
boolean isStatic,
ClassDescription[] paramTypes,
Dependency... paramValues)
Creates a new instance of
MethodInvocation and fully initializes
it. |
MethodInvocation(ClassDescription targetClass,
String methodName,
boolean isStatic,
ClassDescription[] paramTypes,
Dependency... paramValues)
Creates a new instance of
MethodInvocation and initializes most
of the properties. |
MethodInvocation(ClassDescription targetClass,
String methodName,
ClassDescription[] paramTypes,
Dependency... paramValues)
Creates a new instance of
MethodInvocation and initializes
it with information about the method to invoke and the target class. |
MethodInvocation(String methodName,
ClassDescription[] paramTypes,
Dependency... paramValues)
Creates a new instance of
MethodInvocation for non-static
method invocations. |
Modifier and Type | Method and Description |
---|---|
String |
getMethodName()
Returns the name of the method to be invoked.
|
List<Dependency> |
getParameterDependencies()
Returns the
Dependency objects defining the current
parameter values. |
Dependency |
getTargetDependency()
Returns the target
Dependency of this MethodInvocation . |
protected void |
invocationInfoToString(StringBuilder buf)
Creates a string with additional information about this invocation.
|
Object |
invoke(DependencyProvider depProvider,
Object target)
Invokes the corresponding method on the specified target instance.
|
boolean |
isStaticInvocation()
Returns the static flag.
|
checkDependencyProvider, getParameterClasses, getParameterTypes, getResolvedParameters, getTargetClass, isTypeInfoComplete, parametersToString, toString
public MethodInvocation(String methodName, ClassDescription[] paramTypes, Dependency... paramValues)
MethodInvocation
for non-static
method invocations. This constructor sets the target class to null,
so that it can only be derived from the target instance (which prohibits
static method invocations).methodName
- the name of the method 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, or if the method name is
undefinedpublic MethodInvocation(ClassDescription targetClass, String methodName, ClassDescription[] paramTypes, Dependency... paramValues)
MethodInvocation
and initializes
it with information about the method to invoke and the target class.targetClass
- the class, on which the method is to be invokedmethodName
- the name of the method 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, or if the method name is
undefinedInvocation#Invocation(Class, Class[], Dependency...)
public MethodInvocation(ClassDescription targetClass, String methodName, boolean isStatic, ClassDescription[] paramTypes, Dependency... paramValues)
MethodInvocation
and initializes most
of the properties. This constructor is appropriate for static or
non-static invocations which are performed on the target object passed to
the invoke()
method.targetClass
- the class, on which the method is to be invokedmethodName
- the name of the method to be invoked (must not be
null)isStatic
- determines whether a static method is to be invokedparamTypes
- 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, or if the method name is
undefined, or if the static flag is true, but no target class is
definedInvocation#Invocation(Class, Class[], Dependency...)
public MethodInvocation(ClassDescription targetClass, Dependency targetDep, String methodName, boolean isStatic, ClassDescription[] paramTypes, Dependency... paramValues)
MethodInvocation
and fully initializes
it. This constructor takes all information required for arbitrary method
invocations. It is especially possible to define a dependency for the
target object. If set, this dependency is resolved during invocation; a
target object is then ignored. Refer to the base class for a detailed
explanation of the arguments.targetClass
- the class, on which the method is to be invokedtargetDep
- an optional Dependency
to the target bean on
which the method should be invokedmethodName
- the name of the method to be invoked (must not be
null)isStatic
- determines whether a static method is to be invokedparamTypes
- 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, or if the
method name is undefined, or if the static flag is true,
but no target class is definedInvocation#Invocation(Class, Class[], Dependency...)
public String getMethodName()
public boolean isStaticInvocation()
public Dependency getTargetDependency()
Dependency
of this MethodInvocation
.
This dependency defines the bean on which the method is to be invoked. If
there is no target dependency, result is null.Dependency
public List<Dependency> getParameterDependencies()
Dependency
objects defining the current
parameter values. This implementation adds the dependency to the invocation
target if it exists.getParameterDependencies
in interface Invokable
getParameterDependencies
in class Invocation
Dependency
objects for the
parameter valuespublic Object invoke(DependencyProvider depProvider, Object target)
isStaticInvocation()
flag. If it is set, a passed in target
object is ignored and a static method invocation on the target class is
performed. Otherwise, if a non null target object is passed in,
the target class is derived from this instance (an eventually set target
class is ignored).invoke
in interface Invokable
depProvider
- the dependency provider for resolving the parameters
(must not be null)target
- the target instance, on which to invoke the methodInjectionException
- in case of an errorIllegalArgumentException
- 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.