org.apache.tools.ant.util
Class ReflectUtil
java.lang.Objectorg.apache.tools.ant.util.ReflectUtil
public class ReflectUtil
extends java.lang.Object
Utility class to handle reflection on java objects.
The class contains static methods to call reflection
methods, catch any exceptions, converting them
to BuildExceptions.
static Object | getField(Object obj, String fieldName)- Get the value of a field in an object.
|
static Object | invoke(Object obj, String methodName)- Call a method on the object with no parameters.
|
static Object | invoke(Object obj, String methodName, Class argType, Object arg)- Call a method on the object with one argument.
|
static Object | invoke(Object obj, String methodName, Class argType1, Object arg1, Class argType2, Object arg2)- Call a method on the object with two argument.
|
static Object | invokeStatic(Object obj, String methodName)- Call a method on the object with no parameters.
|
static boolean | respondsTo(Object o, String methodName)- A method to test if an object responds to a given
message (method call)
|
static void | throwBuildException(Exception t)- A method to convert an invocationTargetException to
a buildexception and throw it.
|
static BuildException | toBuildException(Exception t)- A method to convert an invocationTargetException to
a buildexception.
|
getField
public static Object getField(Object obj,
String fieldName)
throws BuildException Get the value of a field in an object.
obj - the object to look at.fieldName - the name of the field in the object.
invoke
public static Object invoke(Object obj,
String methodName) Call a method on the object with no parameters.
obj - the object to invoke the method on.methodName - the name of the method to call
- the object returned by the method
invoke
public static Object invoke(Object obj,
String methodName,
Class argType,
Object arg) Call a method on the object with one argument.
obj - the object to invoke the method on.methodName - the name of the method to callargType - the type of argument.arg - the value of the argument.
- the object returned by the method
invoke
public static Object invoke(Object obj,
String methodName,
Class argType1,
Object arg1,
Class argType2,
Object arg2) Call a method on the object with two argument.
obj - the object to invoke the method on.methodName - the name of the method to callargType1 - the type of the first argument.arg1 - the value of the first argument.argType2 - the type of the second argument.arg2 - the value of the second argument.
- the object returned by the method
invokeStatic
public static Object invokeStatic(Object obj,
String methodName) Call a method on the object with no parameters.
Note: Unlike the invoke method above, this
calls class or static methods, not instance methods.
obj - the object to invoke the method on.methodName - the name of the method to call
- the object returned by the method
respondsTo
public static boolean respondsTo(Object o,
String methodName)
throws BuildException A method to test if an object responds to a given
message (method call)
o - the objectmethodName - the method to check for
- true if the object has the method.
throwBuildException
public static void throwBuildException(Exception t)
throws BuildException A method to convert an invocationTargetException to
a buildexception and throw it.
t - the invocation target exception.
toBuildException
public static BuildException toBuildException(Exception t)
A method to convert an invocationTargetException to
a buildexception.
t - the invocation target exception.