|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.util.MethodInvoker
public class MethodInvoker
Helper class that allows for specifying a method to invoke in a declarative fashion, be it static or non-static.
Usage: Specify "targetClass"/"targetMethod" or "targetObject"/"targetMethod", optionally specify arguments, prepare the invoker. Afterwards, you may invoke the method any number of times, obtaining the invocation result.
Typically not used directly but via its subclasses
MethodInvokingFactoryBean
and
MethodInvokingJobDetailFactoryBean
.
prepare()
,
invoke()
,
MethodInvokingFactoryBean
,
MethodInvokingJobDetailFactoryBean
Constructor Summary | |
---|---|
MethodInvoker()
|
Method Summary | |
---|---|
protected Method |
findMatchingMethod()
Find a matching method with the specified name for the specified arguments. |
Object[] |
getArguments()
Retrun the arguments for the method invocation. |
Method |
getPreparedMethod()
Return the prepared Method object that will be invoked. |
Class |
getTargetClass()
Return the target class on which to call the target method. |
String |
getTargetMethod()
Return the name of the method to be invoked. |
Object |
getTargetObject()
Return the target object on which to call the target method. |
Object |
invoke()
Invoke the specified method. |
void |
prepare()
Prepare the specified method. |
protected Class |
resolveClassName(String className)
Resolve the given class name into a Class. |
void |
setArguments(Object[] arguments)
Set arguments for the method invocation. |
void |
setStaticMethod(String staticMethod)
Set a fully qualified static method name to invoke, e.g. |
void |
setTargetClass(Class targetClass)
Set the target class on which to call the target method. |
void |
setTargetMethod(String targetMethod)
Set the name of the method to be invoked. |
void |
setTargetObject(Object targetObject)
Set the target object on which to call the target method. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MethodInvoker()
Method Detail |
---|
public void setTargetClass(Class targetClass)
setTargetObject(java.lang.Object)
,
setTargetMethod(java.lang.String)
public Class getTargetClass()
public void setTargetObject(Object targetObject)
setTargetClass(java.lang.Class)
,
setTargetMethod(java.lang.String)
public Object getTargetObject()
public void setTargetMethod(String targetMethod)
setTargetClass(java.lang.Class)
,
setTargetObject(java.lang.Object)
public String getTargetMethod()
public void setStaticMethod(String staticMethod)
setTargetClass(java.lang.Class)
,
setTargetMethod(java.lang.String)
public void setArguments(Object[] arguments)
public Object[] getArguments()
public void prepare() throws ClassNotFoundException, NoSuchMethodException
ClassNotFoundException
NoSuchMethodException
getPreparedMethod()
,
invoke()
protected Class resolveClassName(String className) throws ClassNotFoundException
The default implementations uses ClassUtils.forName
,
using the thread context class loader.
className
- the class name to resolve
ClassNotFoundException
- if the class name was invalidprotected Method findMatchingMethod()
null
if nonegetTargetClass()
,
getTargetMethod()
,
getArguments()
public Method getPreparedMethod() throws IllegalStateException
Can for example be used to determine the return type.
null
)
IllegalStateException
- if the invoker hasn't been prepared yetprepare()
,
invoke()
public Object invoke() throws InvocationTargetException, IllegalAccessException
The invoker needs to have been prepared before.
null
if the method has a void return type
InvocationTargetException
- if the target method threw an exception
IllegalAccessException
- if the target method couldn't be accessedprepare()
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |