Class SetPropertyInvocation
- java.lang.Object
-
- net.sf.jguiraffe.di.impl.Invocation
-
- net.sf.jguiraffe.di.impl.SetPropertyInvocation
-
- All Implemented Interfaces:
Invokable
public class SetPropertyInvocation extends Invocation implements Invokable
A special
Invocation
implementation for setting properties.This
Invocation
implementation is initialized with a property name and value (the latter one is provided as aDependency
object. In itsinvoke()
method it will set this property on the target object.This is more or less a convenience class because similar results could be achieved by using
MethodInvocation
and specifying the name of the set method corresponding to the property and the property value as parameter dependency. Setting the property is done using theInvocationHelper
class. This ensures that required type conversions are done automatically.Once initialized, an instance is immutable. So it can easily be shared between multiple components and threads without having to care about synchronization issues.
- Version:
- $Id: SetPropertyInvocation.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Constructor Summary
Constructors Constructor Description SetPropertyInvocation(String propName, Dependency propValue)
Creates a new instance ofSetPropertyInvocation
and initializes it.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getPropertyName()
Returns the name of the property that will be set.protected void
invocationInfoToString(StringBuilder buf)
Outputs further information about this invocation to the specified buffer.Object
invoke(DependencyProvider depProvider, Object target)
Performs the invocation and sets the property on the specified target object.-
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
-
SetPropertyInvocation
public SetPropertyInvocation(String propName, Dependency propValue)
Creates a new instance ofSetPropertyInvocation
and initializes it.- Parameters:
propName
- the name of the property to set (must not be null)propValue
- a dependency that defines the property's value (must not be null)- Throws:
IllegalArgumentException
- if the property name or its value is undefined
-
-
Method Detail
-
getPropertyName
public String getPropertyName()
Returns the name of the property that will be set.- Returns:
- the name of the property
-
invoke
public Object invoke(DependencyProvider depProvider, Object target)
Performs the invocation and sets the property on the specified target object.- Specified by:
invoke
in interfaceInvokable
- Parameters:
depProvider
- the dependency provider (must not be null)target
- the target instance (must not be null)- Returns:
- the result of the invocation, which is always null in this case
- Throws:
InjectionException
- if an error occursIllegalArgumentException
- if one of the parameters is null
-
invocationInfoToString
protected void invocationInfoToString(StringBuilder buf)
Outputs further information about this invocation to the specified buffer. This implementation will print the name of the affected property.- Overrides:
invocationInfoToString
in classInvocation
- Parameters:
buf
- the target buffer
-
-