org.apache.commons.beanutils
Class MethodUtils

java.lang.Object
  |
  +--org.apache.commons.beanutils.MethodUtils

public class MethodUtils
extends java.lang.Object

Utility reflection methods focussed on methods in general rather than properties in particular.

Author:
Craig R. McClanahan, Ralph Schaer, Chris Audley, Rey François, Gregor Raıman, Jan Sorensen, Robert Burrell Donkin

Constructor Summary
MethodUtils()
           
 
Method Summary
static java.lang.reflect.Method getAccessibleMethod(java.lang.Class clazz, java.lang.String methodName, java.lang.Class parameterType)
          Return an accessible method (that is, one that can be invoked via reflection) with given name and a single parameter.
static java.lang.reflect.Method getAccessibleMethod(java.lang.Class clazz, java.lang.String methodName, java.lang.Class[] parameterTypes)
          Return an accessible method (that is, one that can be invoked via reflection) with given name and parameters.
static java.lang.reflect.Method getAccessibleMethod(java.lang.reflect.Method method)
          Return an accessible method (that is, one that can be invoked via reflection) that implements the specified Method.
private static java.lang.reflect.Method getAccessibleMethodFromInterfaceNest(java.lang.Class clazz, java.lang.String methodName, java.lang.Class[] parameterTypes)
          Return an accessible method (that is, one that can be invoked via reflection) that implements the specified method, by scanning through all implemented interfaces and subinterfaces.
static java.lang.Object invokeExactMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object arg)
          Invoke a method whose parameter type matches exactly the object type.
static java.lang.Object invokeExactMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object[] args)
          Invoke a method whose parameter types match exactly the object types.
static java.lang.Object invokeExactMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object[] args, java.lang.Class[] parameterTypes)
          Invoke a method whose parameter types match exactly the parameter types given.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Constructor Detail

MethodUtils

public MethodUtils()
Method Detail

invokeExactMethod

public static java.lang.Object invokeExactMethod(java.lang.Object object,
                                                 java.lang.String methodName,
                                                 java.lang.Object arg)
                                          throws java.lang.NoSuchMethodException,
                                                 java.lang.IllegalAccessException,
                                                 java.lang.reflect.InvocationTargetException

Invoke a method whose parameter type matches exactly the object type.

This is a convenient wrapper for invokeExactMethod(Object object,String methodName,Object [] args).

Parameters:
object - invoke method on this object
methodName - get method with this name
arg - use this argument

invokeExactMethod

public static java.lang.Object invokeExactMethod(java.lang.Object object,
                                                 java.lang.String methodName,
                                                 java.lang.Object[] args)
                                          throws java.lang.NoSuchMethodException,
                                                 java.lang.IllegalAccessException,
                                                 java.lang.reflect.InvocationTargetException

Invoke a method whose parameter types match exactly the object types.

This uses reflection to invoke the method obtained from a call to getAccessibleMethod(java.lang.Class, java.lang.String, java.lang.Class).

Parameters:
object - invoke method on this object
methodName - get method with this name
args - use these arguments

invokeExactMethod

public static java.lang.Object invokeExactMethod(java.lang.Object object,
                                                 java.lang.String methodName,
                                                 java.lang.Object[] args,
                                                 java.lang.Class[] parameterTypes)
                                          throws java.lang.NoSuchMethodException,
                                                 java.lang.IllegalAccessException,
                                                 java.lang.reflect.InvocationTargetException

Invoke a method whose parameter types match exactly the parameter types given.

This uses reflection to invoke the method obtained from a call to getAccessibleMethod(java.lang.Class, java.lang.String, java.lang.Class).

Parameters:
object - invoke method on this object
methodName - get method with this name
args - use these arguments
parameterTypes - match these parameters

getAccessibleMethod

public static java.lang.reflect.Method getAccessibleMethod(java.lang.Class clazz,
                                                           java.lang.String methodName,
                                                           java.lang.Class parameterType)

Return an accessible method (that is, one that can be invoked via reflection) with given name and a single parameter. If no such method can be found, return null. Basically, a convenience wrapper that constructs a Class array for you.

Parameters:
clazz - get method from this class
methodName - get method with this name
parameterType - taking this type of parameter

getAccessibleMethod

public static java.lang.reflect.Method getAccessibleMethod(java.lang.Class clazz,
                                                           java.lang.String methodName,
                                                           java.lang.Class[] parameterTypes)

Return an accessible method (that is, one that can be invoked via reflection) with given name and parameters. If no such method can be found, return null. This is just a convenient wrapper for getAccessibleMethod(Method method).

Parameters:
clazz - get method from this class
methodName - get method with this name
parameterTypes - with these parameters types

getAccessibleMethod

public static java.lang.reflect.Method getAccessibleMethod(java.lang.reflect.Method method)

Return an accessible method (that is, one that can be invoked via reflection) that implements the specified Method. If no such method can be found, return null.

Parameters:
method - The method that we wish to call

getAccessibleMethodFromInterfaceNest

private static java.lang.reflect.Method getAccessibleMethodFromInterfaceNest(java.lang.Class clazz,
                                                                             java.lang.String methodName,
                                                                             java.lang.Class[] parameterTypes)

Return an accessible method (that is, one that can be invoked via reflection) that implements the specified method, by scanning through all implemented interfaces and subinterfaces. If no such method can be found, return null.

There isn't any good reason why this method must be private. It is because there doesn't seem any reason why other classes should call this rather than the higher level methods.

Parameters:
clazz - Parent class for the interfaces to be checked
methodName - Method name of the method we wish to call
parameterTypes - The parameter type signatures


Copyright (c) 2001 - Apache Software Foundation