EchoPoint
1.0

echopoint.util.reflect
Class ReflectionKit

java.lang.Object
  extended byechopoint.util.reflect.ReflectionKit

public class ReflectionKit
extends java.lang.Object

ReflectionKit provides methods that help when using reflection on Java code.


Nested Class Summary
static class ReflectionKit.ClassComparator
          A Comparator that can be used when compraing and sorting Class objects.
static class ReflectionKit.MethodComparator
          A Comparator that can be used when compraing and sorting Method objects.
static interface ReflectionKit.MethodSearchCriteria
          MethodSearchCriteria is an interface used to determine if a method matches some search criteria.
 
Method Summary
static java.lang.String decapitalize(java.lang.String name)
          Takes a bean property method name and removes any 'get'/'is'/'set' at the front and then decapitalizes the rest of the name according to the Java Bean Spec.
static java.lang.reflect.Method[] getAllBeanGetterMethods(java.lang.Class targetClass, java.lang.Class stopClass)
          Returns an array containing getter Method objects reflecting all the member methods of the class or interface represented by the targetClass object, including those declared by the class or interface and and those inherited from superclasses and superinterfaces up until stopClass.
static java.lang.reflect.Method[] getAllBeanMethods(java.lang.Class targetClass, java.lang.Class stopClass)
          Returns an array containing getter and setter Method objects reflecting all the member methods of the class or interface represented by the targetClass object, including those declared by the class or interface and and those inherited from superclasses and superinterfaces up until stopClass.
static java.lang.reflect.Method[] getAllBeanSetterMethods(java.lang.Class targetClass, java.lang.Class stopClass)
          Returns an array containing setter Method objects reflecting all the member methods of the class or interface represented by the targetClass object, including those declared by the class or interface and and those inherited from superclasses and superinterfaces up until stopClass.
static java.lang.reflect.Method[] getAllDeclaredMethods(java.lang.Class targetClass)
          Shorthand method for ReflectionKit.getAllMethods(targetClass,Object.class);
static java.lang.reflect.Method[] getAllDeclaredMethods(java.lang.Class targetClass, java.lang.Class stopClass)
          Returns an array containing Method objects reflecting all the member methods of the class or interface represented by the targetClass object, including those declared by the class or interface and and those inherited from superclasses and superinterfaces up until stopClass.
static java.lang.reflect.Method[] getAllPublicMethods(java.lang.Class targetClass, java.lang.Class stopClass)
          Returns an array containing Method objects reflecting all the member methods of the class or interface represented by the targetClass object, including those declared by the class or interface and and those inherited from superclasses and superinterfaces up until stopClass.
static java.lang.reflect.Method[] getMethods(java.lang.Class targetClass, java.lang.Class stopClass, ReflectionKit.MethodSearchCriteria methodSearchCriteria)
          This method will returns member methods of the targetClass that meet a specified search criteria.
static boolean isGetter(java.lang.reflect.Method method)
          Returns true if the method is in fact a Java Bean getter method.
static boolean isSetter(java.lang.reflect.Method method)
          Returns true if the method is in fact a Java Bean setter method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isGetter

public static boolean isGetter(java.lang.reflect.Method method)
Returns true if the method is in fact a Java Bean getter method. ie is starts with 'get' or 'is' and takes no parameters and returns a value and is not static.

Note that it does check for public access because its valid to have a getter that isnt public.

Parameters:
method - - the method to examine
Returns:
true if the method is a Java Bean getter.

isSetter

public static boolean isSetter(java.lang.reflect.Method method)
Returns true if the method is in fact a Java Bean setter method. ie is starts with 'set', takes one parameter and has a return value of void and is not static.

Note that it does check for public access because its valid to have a setter that isnt public.

Parameters:
method - - the method to examine
Returns:
true if the method is a Java Bean setter.

decapitalize

public static java.lang.String decapitalize(java.lang.String name)
Takes a bean property method name and removes any 'get'/'is'/'set' at the front and then decapitalizes the rest of the name according to the Java Bean Spec.

Parameters:
name - - the name of the method or field name to change
Returns:
- the decapitalized name

getMethods

public static java.lang.reflect.Method[] getMethods(java.lang.Class targetClass,
                                                    java.lang.Class stopClass,
                                                    ReflectionKit.MethodSearchCriteria methodSearchCriteria)
This method will returns member methods of the targetClass that meet a specified search criteria. The targetClass will be search up to and including the stopClass.

The results are sorted by method name within class.

If stopClass is not a superclass or superinterface of targetClass, then Object.class is used.

Parameters:
targetClass - - the class to check for methods
stopClass - - the supertype to stop at.
methodSearchCriteria - - the MethodSearchCirteria to use
Returns:
and array of Methods or Method[0] if there are none that match the criteria
See Also:
ReflectionKit.MethodSearchCriteria

getAllDeclaredMethods

public static java.lang.reflect.Method[] getAllDeclaredMethods(java.lang.Class targetClass,
                                                               java.lang.Class stopClass)
Returns an array containing Method objects reflecting all the member methods of the class or interface represented by the targetClass object, including those declared by the class or interface and and those inherited from superclasses and superinterfaces up until stopClass.

All public, protected, default (package) access, and private methods are returned.

If stopClass is not a superclass or superinterface of targetClass, then Object.class is used.

Parameters:
targetClass - - the class to check for methods
stopClass - - the supertype to stop at.
Returns:
and array of Methods or Method[0] if there are none

getAllDeclaredMethods

public static java.lang.reflect.Method[] getAllDeclaredMethods(java.lang.Class targetClass)
Shorthand method for ReflectionKit.getAllMethods(targetClass,Object.class);

See Also:
getAllDeclaredMethods(Class, Class)

getAllPublicMethods

public static java.lang.reflect.Method[] getAllPublicMethods(java.lang.Class targetClass,
                                                             java.lang.Class stopClass)
Returns an array containing Method objects reflecting all the member methods of the class or interface represented by the targetClass object, including those declared by the class or interface and and those inherited from superclasses and superinterfaces up until stopClass.

Only public methods are returned.

If stopClass is not a superclass or superinterface of targetClass, then Object.class is used.

Parameters:
targetClass - - the class to check for methods
stopClass - - the supertype to stop at.
Returns:
and array of Methods or Method[0] if there are none

getAllBeanGetterMethods

public static java.lang.reflect.Method[] getAllBeanGetterMethods(java.lang.Class targetClass,
                                                                 java.lang.Class stopClass)
Returns an array containing getter Method objects reflecting all the member methods of the class or interface represented by the targetClass object, including those declared by the class or interface and and those inherited from superclasses and superinterfaces up until stopClass.

Only methods matching the Java Bean specifiction for a getter method are returned.

If stopClass is not a superclass or superinterface of targetClass, then Object.class is used.

Parameters:
targetClass - - the class to check for methods
stopClass - - the supertype to stop at.
Returns:
and array of Methods or Method[0] if there are none

getAllBeanSetterMethods

public static java.lang.reflect.Method[] getAllBeanSetterMethods(java.lang.Class targetClass,
                                                                 java.lang.Class stopClass)
Returns an array containing setter Method objects reflecting all the member methods of the class or interface represented by the targetClass object, including those declared by the class or interface and and those inherited from superclasses and superinterfaces up until stopClass.

Only methods matching the Java Bean specifiction for a setter method are returned.

If stopClass is not a superclass or superinterface of targetClass, then Object.class is used.

Parameters:
targetClass - - the class to check for methods
stopClass - - the supertype to stop at.
Returns:
and array of Methods or Method[0] if there are none

getAllBeanMethods

public static java.lang.reflect.Method[] getAllBeanMethods(java.lang.Class targetClass,
                                                           java.lang.Class stopClass)
Returns an array containing getter and setter Method objects reflecting all the member methods of the class or interface represented by the targetClass object, including those declared by the class or interface and and those inherited from superclasses and superinterfaces up until stopClass.

Only methods matching the Java Bean specifiction for a getter or setter method are returned.

If stopClass is not a superclass or superinterface of targetClass, then Object.class is used.

Parameters:
targetClass - - the class to check for methods
stopClass - - the supertype to stop at.
Returns:
and array of Methods or Method[0] if there are none

EchoPoint
1.0