Class ConstructorInvocation
- java.lang.Object
-
- net.sf.jguiraffe.di.impl.Invocation
-
- net.sf.jguiraffe.di.impl.ConstructorInvocation
-
- All Implemented Interfaces:
Invokable
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. TheInvocationHelper
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.
- Version:
- $Id: ConstructorInvocation.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Constructor Summary
Constructors Constructor Description ConstructorInvocation(ClassDescription targetClass, ClassDescription[] paramTypes, Dependency... paramValues)
Creates a new instance ofConstructorInvocation
and initializes it.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.-
Methods inherited from class net.sf.jguiraffe.di.impl.Invocation
checkDependencyProvider, getParameterClasses, getParameterDependencies, getParameterTypes, getResolvedParameters, getTargetClass, isTypeInfoComplete, parametersToString, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.jguiraffe.di.impl.Invokable
getParameterDependencies
-
-
-
-
Constructor Detail
-
ConstructorInvocation
public ConstructorInvocation(ClassDescription targetClass, ClassDescription[] paramTypes, Dependency... paramValues)
Creates a new instance ofConstructorInvocation
and initializes it. Refer to the base class for a detailed explanation of the arguments.- Parameters:
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 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, of if the target class is null- See Also:
Invocation#Invocation(Class, Class[], Dependency...)
-
-
Method Detail
-
invoke
public Object invoke(DependencyProvider depProvider)
Invokes the corresponding constructor on the specified target class and returns the newly created instance. The required dependencies are resolved using the givenDependencyProvider
.- Parameters:
depProvider
- the dependency provider (must not be null)- Returns:
- the newly created instance of the target class
- Throws:
InjectionException
- if an error occursIllegalArgumentException
- if the dependency provider is null
-
invoke
public Object invoke(DependencyProvider depProvider, Object target)
Performs the invocation. This method is required by theInvokable
interface. It delegates to the method with the same name, ignoring thetarget
parameter (which is not needed for a constructor invocation).- Specified by:
invoke
in interfaceInvokable
- Parameters:
depProvider
- the dependency provider (must not be null)target
- the target of the invocation- Returns:
- the result of the invocation
- Throws:
InjectionException
- if an error occursIllegalArgumentException
- if the dependency provider is null
-
invocationInfoToString
protected void invocationInfoToString(StringBuilder buf)
Adds additional information about this invocation to the string buffer. This implementation adds a name for the constructor.- Overrides:
invocationInfoToString
in classInvocation
- Parameters:
buf
- the target buffer
-
-