Class Invocation
- java.lang.Object
-
- net.sf.jguiraffe.di.impl.Invocation
-
- Direct Known Subclasses:
ConstructorInvocation
,MethodInvocation
,SetPropertyInvocation
public class Invocation extends Object
A base class for (method or constructor) invocations.
This class allows the definition of important data that is required for invoking a method using reflection. Especially the parameter types and the parameter values can be specified. The parameter values are provided as
Dependency
objects, so they can refer to other beans defined in aBeanStore
.The main use case for
Invocation
objects is the creation and initialization of beans performed by the dependency injection framework: At first a bean has to be created by invoking one of its constructors. After that some initialization methods may be called. In both cases the parameters for the calls have to be specified (which can be either constant values or references to other beans).This base provides common functionality related to the management of the invocation parameters. There will be concrete sub classes implementing specific invocations of methods or constructors.
- Version:
- $Id: Invocation.java 207 2012-02-09 07:30:13Z oheger $
- Author:
- Oliver Heger
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Invocation(ClassDescription targetClass, ClassDescription[] paramTypes, Dependency... paramValues)
Creates a new instance ofInvocation
and initializes it with information about the call parameters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static void
checkDependencyProvider(DependencyProvider depProvider)
Checks whether a validDependencyProvider
has been specified.Class<?>[]
getParameterClasses(DependencyProvider depProvider)
Returns an array with the concrete parameter classes.List<Dependency>
getParameterDependencies()
Returns theDependency
objects defining the current parameter values.ClassDescription[]
getParameterTypes()
Returns an array with the types of the parameters of the invocation.Object[]
getResolvedParameters(DependencyProvider depProvider)
Returns an array with the resolved parameters.ClassDescription
getTargetClass()
Returns the target class of this invocation.protected void
invocationInfoToString(StringBuilder buf)
Creates a string with additional information about this invocation.boolean
isTypeInfoComplete()
Returns a flag whether the data types of all method parameters are known.protected void
parametersToString(StringBuilder buf)
Creates a string representation of the current parameter values.String
toString()
Returns a string representation of this object.
-
-
-
Constructor Detail
-
Invocation
protected Invocation(ClassDescription targetClass, ClassDescription[] paramTypes, Dependency... paramValues)
Creates a new instance ofInvocation
and initializes it with information about the call parameters. To perform an invocation the class has to know the current parameter values and (at least partly) the data types of these values. From this information the signature of the method to call is derived. The array with the parameter types can have null elements if the corresponding parameter types are unknown; it can even be null at all if no information about data types is available. If it is not null, its length must be the same as the length of the array with the parameter values.- Parameters:
targetClass
- description of the class, on which the method is to be invokedparamTypes
- an array with the parameter type descriptionsparamValues
- the current parameter values (defined asDependency
objects); this array must not contain null elements- Throws:
IllegalArgumentException
- 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
-
-
Method Detail
-
getTargetClass
public ClassDescription getTargetClass()
Returns the target class of this invocation. This is the class, on which the method or constructor is to be invoked. A target class may not be required for all cases, e.g. for non-static method invocations it can be determined from the target instance.- Returns:
- the target class of the invocation
-
getParameterTypes
public ClassDescription[] getParameterTypes()
Returns an array with the types of the parameters of the invocation. Note that the array returned here is never null, even if null was passed to the constructor. The returned array may contain null elements for parameters where the type information is lacking.- Returns:
- an array with the parameter types
-
getParameterDependencies
public List<Dependency> getParameterDependencies()
Returns theDependency
objects defining the current parameter values.- Returns:
- a list with the
Dependency
objects for the parameter values
-
isTypeInfoComplete
public boolean isTypeInfoComplete()
Returns a flag whether the data types of all method parameters are known. If this is the case, the signature of the method to be called can be exactly specified. Otherwise the signature has to be derived from the data types of the current parameters.- Returns:
- a flag whether information about the parameter types is complete
-
getResolvedParameters
public Object[] getResolvedParameters(DependencyProvider depProvider)
Returns an array with the resolved parameters. This method iterates over the parameter dependencies and tries to resolve them using the specifiedDependencyProvider
. An array with the resulting beans is returned. If no parameters are specified (i.e. for invocations of methods that do not have arguments), the return value is null.- Parameters:
depProvider
- the dependency provider (must not be null)- Returns:
- an array with the resolved parameter values (can be null)
- Throws:
InjectionException
- if a dependency cannot be resolvedIllegalArgumentException
- if the passed in dependency provider is null
-
getParameterClasses
public Class<?>[] getParameterClasses(DependencyProvider depProvider)
Returns an array with the concrete parameter classes. This method converts the internally storedClassDescription
objects intoClass
objects.- Parameters:
depProvider
- the dependency provider for resolving the classes- Returns:
- an array with the parameter classes
- Throws:
InjectionException
- if a class cannot be resolved
-
toString
public String toString()
Returns a string representation of this object. The returned string will contain information about this invocation (including the class name, the target class name, the parameters, and further information provided by sub classes). This implementation will print the concrete class name, followed by an opening square bracket. TheninvocationInfoToString()
, andparametersToString()
are called. Finally a closing square bracket is output.
-
invocationInfoToString
protected void invocationInfoToString(StringBuilder buf)
Creates a string with additional information about this invocation. This method is called by the defaulttoString()
implementation. It adds the target class to the buffer if it is defined.- Parameters:
buf
- the target buffer
-
parametersToString
protected void parametersToString(StringBuilder buf)
Creates a string representation of the current parameter values. This implementation iterates over all parameter dependencies and invokes theirtoString()
method. It is called by thetoString()
method.- Parameters:
buf
- the target buffer
-
checkDependencyProvider
protected static void checkDependencyProvider(DependencyProvider depProvider)
Checks whether a validDependencyProvider
has been specified.- Parameters:
depProvider
- the provider to be checked- Throws:
IllegalArgumentException
- if theDependencyProvider
is undefined- Since:
- 1.1
-
-