JIDE 3.5.15

com.jidesoft.utils
Class ReflectionUtils

java.lang.Object
  extended by com.jidesoft.utils.ReflectionUtils

public class ReflectionUtils
extends Object

Utility class to use reflection to call methods.


Constructor Summary
ReflectionUtils()
           
 
Method Summary
static void call(Object thisObject, String methodName)
          Helper method to call a no argument, no return method.
static Object callAny(Object thisObject, String methodName, Class<?>[] argTypes, Object[] args)
          Helper method to call a multi-argument method having a return.
static Object callAny(Object thisObject, String methodName, Object[] args)
          Helper method to call a multi-argument method having a return.
static Object callAnyWithoutException(Object thisObject, Class<?> objectClass, String methodName, Class<?>[] argTypes, Object[] args)
          Helper method to call a multi-argument method having a return without throwing an exception.
static Object callConstructor(Class<?> clazz, Class<?>[] argTypes, Object[] args)
          Helper method to call a constructor.
static Object callGet(Object thisObject, String methodName)
          Helper method to call a get method with no argument.
static void callSet(Object thisObject, String methodName, Object value)
          Helper method to call a set boolean method.
static void callSetBoolean(Object thisObject, String methodName, boolean value)
          Helper method to call a set boolean method.
static void callSetInt(Object thisObject, String methodName, int value)
          Helper method to call a set boolean method.
static Object callStatic(Class<?> thisClass, String methodName, Class<?>[] argTypes, Object[] args)
          Helper method to call a multi-argument static class method having a return.
static Object createInstance(String className, Class<?>[] types, Object[] args)
          Instantiate an object based on the class name.
static boolean isSubClassOf(Object o, String className)
          Checks if the instance o is an instance of a subclass of the designated class name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionUtils

public ReflectionUtils()
Method Detail

callSetBoolean

public static void callSetBoolean(Object thisObject,
                                  String methodName,
                                  boolean value)
                           throws Exception
Helper method to call a set boolean method.

Parameters:
thisObject - the instance
methodName - the method name
value - true or false
Throws:
Exception - if the method is not found or invocation to the method fails.

callSetInt

public static void callSetInt(Object thisObject,
                              String methodName,
                              int value)
                       throws Exception
Helper method to call a set boolean method.

Parameters:
thisObject - the instance
methodName - the method name
value - the value
Throws:
Exception - if the method is not found or invocation to the method fails.

callSet

public static void callSet(Object thisObject,
                           String methodName,
                           Object value)
                    throws Exception
Helper method to call a set boolean method.

Parameters:
thisObject - the instance
methodName - the method name
value - the value
Throws:
Exception - if the method is not found or invocation to the method fails.

callGet

public static Object callGet(Object thisObject,
                             String methodName)
                      throws Exception
Helper method to call a get method with no argument.

Parameters:
thisObject - the instance
methodName - the method name
Returns:
the value the method returns.
Throws:
Exception - if the method is not found or invocation to the method fails.

call

public static void call(Object thisObject,
                        String methodName)
                 throws Exception
Helper method to call a no argument, no return method.

Parameters:
thisObject - the instance
methodName - the method name
Throws:
Exception - if the method is not found or invocation to the method fails.

callConstructor

public static Object callConstructor(Class<?> clazz,
                                     Class<?>[] argTypes,
                                     Object[] args)
                              throws Exception
Helper method to call a constructor.

Parameters:
clazz - the class
argTypes - argument Classes for constructor lookup. Must not be null.
args - the argument array
Returns:
the value the method returns.
Throws:
Exception - if the method is not found or invocation to the method fails.

callAny

public static Object callAny(Object thisObject,
                             String methodName,
                             Object[] args)
                      throws Exception
Helper method to call a multi-argument method having a return. The class types will be derived from the input values. This call is usually successful with primitive types or Strings as arguments, but care should be used with other kinds of values. The constructor lookup is not polymorphic.

Calls callAny(Object, methodName, argTypes, args).

Parameters:
thisObject - the instance
methodName - the method name
args - the argument array, must not contain null.
Returns:
the value the method returns.
Throws:
Exception - if the method is not found or invocation to the method fails.

callAny

public static Object callAny(Object thisObject,
                             String methodName,
                             Class<?>[] argTypes,
                             Object[] args)
                      throws Exception
Helper method to call a multi-argument method having a return.

Parameters:
thisObject - the instance
methodName - the method name
argTypes - argument Classes for constructor lookup. Must not be null.
args - the argument array
Returns:
the value the method returns.
Throws:
Exception - if the method is not found or invocation to the method fails.

callAnyWithoutException

public static Object callAnyWithoutException(Object thisObject,
                                             Class<?> objectClass,
                                             String methodName,
                                             Class<?>[] argTypes,
                                             Object[] args)
Helper method to call a multi-argument method having a return without throwing an exception.

Parameters:
thisObject - the instance
objectClass - the class which could find the method name
methodName - the method name
argTypes - argument Classes for constructor lookup. Must not be null.
args - the argument array
Returns:
the value the method returns.

callStatic

public static Object callStatic(Class<?> thisClass,
                                String methodName,
                                Class<?>[] argTypes,
                                Object[] args)
                         throws Exception
Helper method to call a multi-argument static class method having a return.

Parameters:
thisClass - the class
methodName - the method name
argTypes - argument Classes for constructor lookup. Must not be null.
args - the argument array
Returns:
the value the method returns.
Throws:
Exception - if the method is not found or invocation to the method fails.

createInstance

public static Object createInstance(String className,
                                    Class<?>[] types,
                                    Object[] args)
Instantiate an object based on the class name.

Parameters:
className - the class name
types - the class types for the constructor
args - the constructor values
Returns:
the object instance. null if any exception occurs.

isSubClassOf

public static boolean isSubClassOf(Object o,
                                   String className)
Checks if the instance o is an instance of a subclass of the designated class name.

Parameters:
o - the instance to check
className - the class name to check
Returns:
true if the instance o is an instance of a subclass of the class name. Otherwise false.
Since:
3.4.9

JIDE 3.5.15