FileDocCategorySizeDatePackage
ReflectWrapper.javaAPI DocApache Ant 1.703411Wed Dec 13 06:16:24 GMT 2006org.apache.tools.ant.util

ReflectWrapper

public class ReflectWrapper extends Object
Utility class to handle reflection on java objects. The class is a holder class for an object and uses java reflection to call methods on the objects. If things go wrong, BuildExceptions are thrown.

Fields Summary
private Object
obj
Constructors Summary
public ReflectWrapper(ClassLoader loader, String name)
Construct a wrapped object using the no arg constructor.

param
loader the classloader to use to construct the class.
param
name the classname of the object to construct.

        try {
            Class clazz;
            clazz = Class.forName(name, true, loader);
            Constructor constructor;
            constructor = clazz.getConstructor((Class[]) null);
            obj = constructor.newInstance((Object[]) null);
        } catch (Exception t) {
            ReflectUtil.throwBuildException(t);
        }
    
public ReflectWrapper(Object obj)
Constructor using a passed in object.

param
obj the object to wrap.

        this.obj = obj;
    
Methods Summary
public java.lang.ObjectgetObject()

return
the wrapped object.

        return obj;
    
public java.lang.Objectinvoke(java.lang.String methodName)
Call a method on the object with no parameters.

param
methodName the name of the method to call
return
the object returned by the method

        return ReflectUtil.invoke(obj, methodName);
    
public java.lang.Objectinvoke(java.lang.String methodName, java.lang.Class argType, java.lang.Object arg)
Call a method on the object with one argument.

param
methodName the name of the method to call
param
argType the type of argument.
param
arg the value of the argument.
return
the object returned by the method

        return ReflectUtil.invoke(obj, methodName, argType, arg);
    
public java.lang.Objectinvoke(java.lang.String methodName, java.lang.Class argType1, java.lang.Object arg1, java.lang.Class argType2, java.lang.Object arg2)
Call a method on the object with one argument.

param
methodName the name of the method to call
param
argType1 the type of the first argument.
param
arg1 the value of the first argument.
param
argType2 the type of the second argument.
param
arg2 the value of the second argument.
return
the object returned by the method

        return ReflectUtil.invoke(
            obj, methodName, argType1, arg1, argType2, arg2);