de.bea.domingo.map
Class MethodFinder

java.lang.Object
  extended by de.bea.domingo.map.MethodFinder

public final class MethodFinder
extends java.lang.Object

Finds methods and constructors that can be invoked by reflection. Attempts to address some of the limitations of the JDK's Class.getMethod() and Class.getConstructor(), and other JDK reflective facilities.


Constructor Summary
MethodFinder(java.lang.Class clazz)
           
 
Method Summary
 boolean equals(java.lang.Object o)
          
 java.lang.reflect.Constructor findConstructor(java.lang.Class[] parameterTypes)
          Returns the most specific public constructor in my target class that accepts the number and type of parameters in the given Class array in a reflective invocation.
 java.lang.reflect.Method findMethod(java.lang.String methodName, java.lang.Class[] parameterTypes)
          Returns the most specific public method in my target class that has the given name and accepts the number and type of parameters in the given Class array in a reflective invocation.
static java.lang.Class[] getParameterTypesFrom(java.lang.Object[] args)
           
static java.lang.Class[] getParameterTypesFrom(java.lang.String[] classNames)
           
static java.lang.Class[] getParameterTypesFrom(java.lang.String[] classNames, java.lang.ClassLoader loader)
           
 int hashCode()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MethodFinder

public MethodFinder(java.lang.Class clazz)
Parameters:
clazz - Class in which I will look for methods and constructors throws IllegalArgumentException if clazz is null, or represents a primitive, or represents an array type
Method Detail

equals

public boolean equals(java.lang.Object o)

Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

findConstructor

public java.lang.reflect.Constructor findConstructor(java.lang.Class[] parameterTypes)
                                              throws java.lang.NoSuchMethodException
Returns the most specific public constructor in my target class that accepts the number and type of parameters in the given Class array in a reflective invocation.

A null value or Void.TYPE in parameterTypes matches a corresponding Object or array reference in a constructor's formal parameter list, but not a primitive formal parameter.

Parameters:
parameterTypes - array representing the number and types of parameters to look for in the constructor's signature. A null array is treated as a zero-length array.
Returns:
Constructor object satisfying the conditions
Throws:
java.lang.NoSuchMethodException - if no constructors match the criteria, or if the reflective call is ambiguous based on the parameter types

findMethod

public java.lang.reflect.Method findMethod(java.lang.String methodName,
                                           java.lang.Class[] parameterTypes)
                                    throws java.lang.NoSuchMethodException
Returns the most specific public method in my target class that has the given name and accepts the number and type of parameters in the given Class array in a reflective invocation.

A null value or Void.TYPE in parameterTypes will match a corresponding Object or array reference in a method's formal parameter list, but not a primitive formal parameter.

Parameters:
methodName - name of the method to search for
parameterTypes - array representing the number and types of parameters to look for in the method's signature. A null array is treated as a zero-length array.
Returns:
Method object satisfying the conditions
Throws:
java.lang.NoSuchMethodException - if no methods match the criteria, or if the reflective call is ambiguous based on the parameter types, or if methodName is null

getParameterTypesFrom

public static java.lang.Class[] getParameterTypesFrom(java.lang.Object[] args)
Parameters:
args - an Object array
Returns:
an array of Class objects representing the classes of the objects in the given Object array. If args is null, a zero-length Class array is returned. If an element in args is null, then Void.TYPE is the corresponding Class in the return array.

getParameterTypesFrom

public static java.lang.Class[] getParameterTypesFrom(java.lang.String[] classNames)
                                               throws java.lang.ClassNotFoundException
Parameters:
classNames - String array of fully qualified names (FQNs) of classes or primitives. Represent an array type by using its JVM type descriptor, with dots instead of slashes (e.g. represent the type int[] with "[I", and Object[][] with "[[Ljava.lang.Object;").
Returns:
an array of Class objects representing the classes or primitives named by the FQNs in the given String array. If the String array is null, a zero-length Class array is returned. If an element in classNames is null, the empty string, "void", or "null", then Void.TYPE is the corresponding Class in the return array. If any classes require loading because of this operation, the loading is done by the ClassLoader that loaded this class. Such classes are not initialized, however.
Throws:
java.lang.ClassNotFoundException - if any of the FQNs name an unknown class

getParameterTypesFrom

public static java.lang.Class[] getParameterTypesFrom(java.lang.String[] classNames,
                                                      java.lang.ClassLoader loader)
                                               throws java.lang.ClassNotFoundException
Parameters:
classNames - String array of fully qualified names (FQNs) of classes or primitives. Represent an array type by using its JVM type descriptor, with dots instead of slashes (e.g. represent the type int[] with "[I", and Object[][] with "[[Ljava.lang.Object;").
loader - a ClassLoader
Returns:
an array of Class objects representing the classes or primitives named by the FQNs in the given String array. If the String array is null, a zero-length Class array is returned. If an element in classNames is null, the empty string, "void", or "null", then Void.TYPE is the corresponding Class in the return array. If any classes require loading because of this operation, the loading is done by the given ClassLoader. Such classes are not initialized, however.
Throws:
java.lang.ClassNotFoundException - if any of the FQNs name an unknown class

hashCode

public int hashCode()

Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()


Domingo Java-API