qflib 0.98.0

de.qfs.lib.util
Class Reflector

java.lang.Object
  |
  +--de.qfs.lib.util.Reflector

public abstract class Reflector
extends java.lang.Object

This class holds a collection of static methods for convenient access to the reflection API.

Since:
0.98.0
Version:
$Revision: 1.1 $
Author:
Gregor Schmid

Constructor Summary
Reflector()
           
 
Method Summary
static java.lang.Object call(java.lang.Object instance, java.lang.String name)
          Call a no args method of an object.
static java.lang.Object call(java.lang.Object instance, java.lang.String name, boolean forceAccess)
          Call a no args method of an object.
static java.lang.Object call(java.lang.Object instance, java.lang.String name, java.lang.Class[] parameterTypes, java.lang.Object[] parameterValues)
          Call a method of an object.
static java.lang.Object call(java.lang.Object instance, java.lang.String name, java.lang.Class[] parameterTypes, java.lang.Object[] parameterValues, boolean forceAccess)
          Call a method of an object.
static java.lang.Object call(java.lang.Object instance, java.lang.String name, java.lang.Class parameterType, java.lang.Object parameterValue)
          Call a one arg method of an object.
static java.lang.Object call(java.lang.Object instance, java.lang.String name, java.lang.Class parameterType, java.lang.Object parameterValue, boolean forceAccess)
          Call a one arg method of an object.
static java.lang.Object get(java.lang.Object instance, java.lang.String name)
          Get a field value from an object.
static java.lang.Object get(java.lang.Object instance, java.lang.String name, boolean forceAccess)
          Get a field value from an object.
static java.lang.Object safeCall(java.lang.Object instance, java.lang.String name)
          Call a no args method of an object.
static java.lang.Object safeCall(java.lang.Object instance, java.lang.String name, boolean forceAccess)
          Call a no args method of an object.
static java.lang.Object safeCall(java.lang.Object instance, java.lang.String name, java.lang.Class[] parameterTypes, java.lang.Object[] parameterValues)
          Call a method of an object.
static java.lang.Object safeCall(java.lang.Object instance, java.lang.String name, java.lang.Class[] parameterTypes, java.lang.Object[] parameterValues, boolean forceAccess)
          Call a method of an object.
static java.lang.Object safeCall(java.lang.Object instance, java.lang.String name, java.lang.Class parameterType, java.lang.Object parameterValue)
          Call a one arg method of an object.
static java.lang.Object safeCall(java.lang.Object instance, java.lang.String name, java.lang.Class parameterType, java.lang.Object parameterValue, boolean forceAccess)
          Call a one arg method of an object.
static java.lang.Object safeGet(java.lang.Object instance, java.lang.String name)
          Get a field value from an object.
static java.lang.Object safeGet(java.lang.Object instance, java.lang.String name, boolean forceAccess)
          Get a field value from an object.
static void safeSet(java.lang.Object instance, java.lang.String name, java.lang.Object value)
          Set a field value in an object.
static void safeSet(java.lang.Object instance, java.lang.String name, java.lang.Object value, boolean forceAccess)
          Set a field value in an object.
static void set(java.lang.Object instance, java.lang.String name, java.lang.Object value)
          Set a field value in an object.
static void set(java.lang.Object instance, java.lang.String name, java.lang.Object value, boolean forceAccess)
          Set a field value in an object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Reflector

public Reflector()
Method Detail

call

public static java.lang.Object call(java.lang.Object instance,
                                    java.lang.String name,
                                    java.lang.Class[] parameterTypes,
                                    java.lang.Object[] parameterValues,
                                    boolean forceAccess)
                             throws java.lang.IllegalAccessException,
                                    java.lang.NoSuchMethodException,
                                    java.lang.reflect.InvocationTargetException
Call a method of an object.
Parameters:
instance - The object whose method to call.
name - The name of the method.
parameterTypes - The classes of the method parameters.
parameterValues - The parameter values.
forceAccess - Whether to force access to a normally inaccessible method via the Accessible interface (only works with JDK 1.2 and above).
Returns:
The result of the method call.
Throws:
java.lang.IllegalAccessException - If the method cannot be accessed.
java.lang.NoSuchMethodException - If no such method exists.
java.lang.reflect.InvocationTargetException - If execution of the method throws an exception.

call

public static java.lang.Object call(java.lang.Object instance,
                                    java.lang.String name,
                                    java.lang.Class[] parameterTypes,
                                    java.lang.Object[] parameterValues)
                             throws java.lang.IllegalAccessException,
                                    java.lang.NoSuchMethodException,
                                    java.lang.reflect.InvocationTargetException
Call a method of an object.
Parameters:
instance - The object whose method to call.
name - The name of the method.
parameterTypes - The classes of the method parameters.
parameterValues - The parameter values.
Returns:
The result of the method call.
Throws:
java.lang.IllegalAccessException - If the method cannot be accessed.
java.lang.NoSuchMethodException - If no such method exists.
java.lang.reflect.InvocationTargetException - If execution of the method throws an exception.

call

public static java.lang.Object call(java.lang.Object instance,
                                    java.lang.String name,
                                    boolean forceAccess)
                             throws java.lang.IllegalAccessException,
                                    java.lang.NoSuchMethodException,
                                    java.lang.reflect.InvocationTargetException
Call a no args method of an object.
Parameters:
instance - The object whose method to call.
name - The name of the method.
forceAccess - Whether to force access to a normally inaccessible method via the Accessible interface (only works with JDK 1.2 and above).
Returns:
The result of the method call.
Throws:
java.lang.IllegalAccessException - If the method cannot be accessed.
java.lang.NoSuchMethodException - If no such method exists.
java.lang.reflect.InvocationTargetException - If execution of the method throws an exception.

call

public static java.lang.Object call(java.lang.Object instance,
                                    java.lang.String name)
                             throws java.lang.IllegalAccessException,
                                    java.lang.NoSuchMethodException,
                                    java.lang.reflect.InvocationTargetException
Call a no args method of an object.
Parameters:
instance - The object whose method to call.
name - The name of the method.
Returns:
The result of the method call.
Throws:
java.lang.IllegalAccessException - If the method cannot be accessed.
java.lang.NoSuchMethodException - If no such method exists.
java.lang.reflect.InvocationTargetException - If execution of the method throws an exception.

call

public static java.lang.Object call(java.lang.Object instance,
                                    java.lang.String name,
                                    java.lang.Class parameterType,
                                    java.lang.Object parameterValue,
                                    boolean forceAccess)
                             throws java.lang.IllegalAccessException,
                                    java.lang.NoSuchMethodException,
                                    java.lang.reflect.InvocationTargetException
Call a one arg method of an object.
Parameters:
instance - The object whose method to call.
name - The name of the method.
parameterType - The class of the method parameter.
parameterValue - The parameter value.
forceAccess - Whether to force access to a normally inaccessible method via the Accessible interface (only works with JDK 1.2 and above).
Returns:
The result of the method call.
Throws:
java.lang.IllegalAccessException - If the method cannot be accessed.
java.lang.NoSuchMethodException - If no such method exists.
java.lang.reflect.InvocationTargetException - If execution of the method throws an exception.

call

public static java.lang.Object call(java.lang.Object instance,
                                    java.lang.String name,
                                    java.lang.Class parameterType,
                                    java.lang.Object parameterValue)
                             throws java.lang.IllegalAccessException,
                                    java.lang.NoSuchMethodException,
                                    java.lang.reflect.InvocationTargetException
Call a one arg method of an object.
Parameters:
instance - The object whose method to call.
name - The name of the method.
parameterType - The class of the method parameter.
parameterValue - The parameter value.
Returns:
The result of the method call.
Throws:
java.lang.IllegalAccessException - If the method cannot be accessed.
java.lang.NoSuchMethodException - If no such method exists.
java.lang.reflect.InvocationTargetException - If execution of the method throws an exception.

safeCall

public static java.lang.Object safeCall(java.lang.Object instance,
                                        java.lang.String name,
                                        java.lang.Class[] parameterTypes,
                                        java.lang.Object[] parameterValues,
                                        boolean forceAccess)
Call a method of an object. Exceptions are caught and logged at level Log.DBG.
Parameters:
instance - The object whose method to call.
name - The name of the method.
parameterTypes - The classes of the method parameters.
parameterValues - The parameter values.
forceAccess - Whether to force access to a normally inaccessible method via the Accessible interface (only works with JDK 1.2 and above).
Returns:
The result of the method call or null if an Exception is caught.

safeCall

public static java.lang.Object safeCall(java.lang.Object instance,
                                        java.lang.String name,
                                        java.lang.Class[] parameterTypes,
                                        java.lang.Object[] parameterValues)
Call a method of an object. Exceptions are caught and logged at level Log.DBG.
Parameters:
instance - The object whose method to call.
name - The name of the method.
parameterTypes - The classes of the method parameters.
parameterValues - The parameter values.
Returns:
The result of the method call or null if an Exception is caught.

safeCall

public static java.lang.Object safeCall(java.lang.Object instance,
                                        java.lang.String name,
                                        boolean forceAccess)
Call a no args method of an object. Exceptions are caught and logged at level Log.DBG.
Parameters:
instance - The object whose method to call.
name - The name of the method.
forceAccess - Whether to force access to a normally inaccessible method via the Accessible interface (only works with JDK 1.2 and above).
Returns:
The result of the method call or null if an Exception is caught.

safeCall

public static java.lang.Object safeCall(java.lang.Object instance,
                                        java.lang.String name)
Call a no args method of an object. Exceptions are caught and logged at level Log.DBG.
Parameters:
instance - The object whose method to call.
name - The name of the method.
Returns:
The result of the method call or null if an Exception is caught.

safeCall

public static java.lang.Object safeCall(java.lang.Object instance,
                                        java.lang.String name,
                                        java.lang.Class parameterType,
                                        java.lang.Object parameterValue,
                                        boolean forceAccess)
Call a one arg method of an object. Exceptions are caught and logged at level Log.DBG.
Parameters:
instance - The object whose method to call.
name - The name of the method.
parameterType - The class of the method parameter.
parameterValue - The parameter value.
forceAccess - Whether to force access to a normally inaccessible method via the Accessible interface (only works with JDK 1.2 and above).
Returns:
The result of the method call or null if an Exception is caught.

safeCall

public static java.lang.Object safeCall(java.lang.Object instance,
                                        java.lang.String name,
                                        java.lang.Class parameterType,
                                        java.lang.Object parameterValue)
Call a one arg method of an object. Exceptions are caught and logged at level Log.DBG.
Parameters:
instance - The object whose method to call.
name - The name of the method.
parameterType - The class of the method parameter.
parameterValue - The parameter value.
Returns:
The result of the method call or null if an Exception is caught.

get

public static java.lang.Object get(java.lang.Object instance,
                                   java.lang.String name,
                                   boolean forceAccess)
                            throws java.lang.IllegalAccessException,
                                   java.lang.NoSuchFieldException,
                                   java.lang.reflect.InvocationTargetException
Get a field value from an object.
Parameters:
instance - The object whose field to get.
name - The name of the field.
forceAccess - Whether to force access to a normally inaccessible field via the Accessible interface (only works with JDK 1.2 and above).
Returns:
The value of the field.
Throws:
java.lang.IllegalAccessException - If the method cannot be accessed.
java.lang.NoSuchFieldException - If no such field exists.
java.lang.reflect.InvocationTargetException - If execution of the method throws an exception.

get

public static java.lang.Object get(java.lang.Object instance,
                                   java.lang.String name)
                            throws java.lang.IllegalAccessException,
                                   java.lang.NoSuchFieldException,
                                   java.lang.reflect.InvocationTargetException
Get a field value from an object.
Parameters:
instance - The object whose field to get.
name - The name of the field.
Returns:
The value of the field.
Throws:
java.lang.IllegalAccessException - If the method cannot be accessed.
java.lang.NoSuchFieldException - If no such field exists.
java.lang.reflect.InvocationTargetException - If execution of the method throws an exception.

safeGet

public static java.lang.Object safeGet(java.lang.Object instance,
                                       java.lang.String name,
                                       boolean forceAccess)
Get a field value from an object. Exceptions are caught and logged at level Log.DBG.
Parameters:
instance - The object whose field to get.
name - The name of the field.
forceAccess - Whether to force access to a normally inaccessible field via the Accessible interface (only works with JDK 1.2 and above).
Returns:
The value of the field or null if an Exception is caught.

safeGet

public static java.lang.Object safeGet(java.lang.Object instance,
                                       java.lang.String name)
Get a field value from an object. Exceptions are caught and logged at level Log.DBG.
Parameters:
instance - The object whose field to get.
name - The name of the field.
Returns:
The value of the field or null if an Exception is caught.

set

public static void set(java.lang.Object instance,
                       java.lang.String name,
                       java.lang.Object value,
                       boolean forceAccess)
                throws java.lang.IllegalAccessException,
                       java.lang.NoSuchFieldException,
                       java.lang.reflect.InvocationTargetException
Set a field value in an object.
Parameters:
instance - The object whose field to get.
name - The name of the field.
value - The value to set.
forceAccess - Whether to force access to a normally inaccessible field via the Accessible interface (only works with JDK 1.2 and above).
Throws:
java.lang.IllegalAccessException - If the method cannot be accessed.
java.lang.NoSuchFieldException - If no such field exists.
java.lang.reflect.InvocationTargetException - If execution of the method throws an exception.

set

public static void set(java.lang.Object instance,
                       java.lang.String name,
                       java.lang.Object value)
                throws java.lang.IllegalAccessException,
                       java.lang.NoSuchFieldException,
                       java.lang.reflect.InvocationTargetException
Set a field value in an object.
Parameters:
instance - The object whose field to get.
name - The name of the field.
value - The value to set.
Throws:
java.lang.IllegalAccessException - If the method cannot be accessed.
java.lang.NoSuchFieldException - If no such field exists.
java.lang.reflect.InvocationTargetException - If execution of the method throws an exception.

safeSet

public static void safeSet(java.lang.Object instance,
                           java.lang.String name,
                           java.lang.Object value,
                           boolean forceAccess)
Set a field value in an object. Exceptions are caught and logged at level Log.DBG.
Parameters:
instance - The object whose field to get.
name - The name of the field.
value - The value to set.
forceAccess - Whether to force access to a normally inaccessible field via the Accessible interface (only works with JDK 1.2 and above).

safeSet

public static void safeSet(java.lang.Object instance,
                           java.lang.String name,
                           java.lang.Object value)
Set a field value in an object. Exceptions are caught and logged at level Log.DBG.
Parameters:
instance - The object whose field to get.
name - The name of the field.
value - The value to set.

qflib 0.98.0