fr.lip6.sma.simulacion.test
Class PrivateAccessor

java.lang.Object
  extended by fr.lip6.sma.simulacion.test.PrivateAccessor

public final class PrivateAccessor
extends Object

Class to access private/protected fields and methods for testing purposes.

Version:
$Revision: 3 $
Author:
Paul Guyot

Constructor Summary
private PrivateAccessor()
          Default constructor.
 
Method Summary
private static Object doGetField(Class inClass, Object inObject, String inName)
          Access a given static field of a class.
private static Object doInvokeMethod(Class inClass, Object inObject, String inName, Object[] inArgs)
          Invoke a given instance method.
private static void doSetField(Class inClass, Object inObject, String inName, Object inValue)
          Modify a given field of an object or a class.
private static Field findField(Class inClass, String inName)
          Find a given field of a class.
private static Method findMethod(Class inClass, String inName)
          Find a given method of a class.
static Object getField(Class inClass, String inName)
          Access a given static field of a class.
static Object getField(Object inObject, String inName)
          Access a given field of an object.
static Object invokeMethod(Class inClass, String inName, Object[] inArgs)
          Invoke a given class method.
static Object invokeMethod(Object inObject, String inName, Object[] inArgs)
          Invoke a given instance method.
static void setField(Class inClass, String inName, Object inValue)
          Modify a given field of an object.
static void setField(Object inObject, String inName, Object inValue)
          Modify a given field of an object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PrivateAccessor

private PrivateAccessor()
Default constructor.

Method Detail

getField

public static Object getField(Class inClass,
                              String inName)
Access a given static field of a class.

Parameters:
inClass - class we want the field of.
inName - name of the field we want to access.
Returns:
the value of the field.
Throws:
IllegalArgumentException - if a problem occurs.

getField

public static Object getField(Object inObject,
                              String inName)
Access a given field of an object.

Parameters:
inObject - object we want the field of.
inName - name of the field we want to access.
Returns:
the value of the field.
Throws:
IllegalArgumentException - if a problem occurs.

doGetField

private static Object doGetField(Class inClass,
                                 Object inObject,
                                 String inName)
Access a given static field of a class.

Parameters:
inClass - class (of the object) we want the field of.
inObject - object we want the field of or null if the field is static.
inName - name of the field we want to access.
Returns:
the value of the field.
Throws:
IllegalArgumentException - if a problem occurs.

setField

public static void setField(Class inClass,
                            String inName,
                            Object inValue)
Modify a given field of an object.

Parameters:
inClass - class we want to modify the field of.
inName - name of the field we want to access.
inValue - new value for the field.
Throws:
IllegalArgumentException - if a problem occurs.

setField

public static void setField(Object inObject,
                            String inName,
                            Object inValue)
Modify a given field of an object.

Parameters:
inObject - object we want to modify the field of.
inName - name of the field we want to access.
inValue - new value for the field.
Throws:
IllegalArgumentException - if a problem occurs.

doSetField

private static void doSetField(Class inClass,
                               Object inObject,
                               String inName,
                               Object inValue)
Modify a given field of an object or a class.

Parameters:
inClass - class (of the object) we want to modify the field of.
inObject - object we want to modify the field of or null if the field is static.
inName - name of the field we want to access.
inValue - new value for the field.
Throws:
IllegalArgumentException - if a problem occurs.

invokeMethod

public static Object invokeMethod(Class inClass,
                                  String inName,
                                  Object[] inArgs)
Invoke a given class method.

Parameters:
inClass - class we want to invoke a method of.
inName - name of the method we want to invoke.
inArgs - arguments for the invocation.
Returns:
the result of the method call.
Throws:
IllegalArgumentException - if a problem occurs.

invokeMethod

public static Object invokeMethod(Object inObject,
                                  String inName,
                                  Object[] inArgs)
Invoke a given instance method.

Parameters:
inObject - object we want to invoke the method of.
inName - name of the method we want to invoke.
inArgs - arguments for the invocation.
Returns:
the result of the method call.
Throws:
IllegalArgumentException - if a problem occurs.

doInvokeMethod

private static Object doInvokeMethod(Class inClass,
                                     Object inObject,
                                     String inName,
                                     Object[] inArgs)
Invoke a given instance method.

Parameters:
inClass - class we want to invoke the method of.
inObject - this for the method call, or null if the method is static.
inName - name of the method we want to invoke.
inArgs - arguments for the invocation.
Returns:
the result of the method call.
Throws:
IllegalArgumentException - if a problem occurs.

findField

private static Field findField(Class inClass,
                               String inName)
Find a given field of a class.

Parameters:
inClass - class we want the field of.
inName - name of the field we want to access.
Returns:
the field (reflect) object or null if it couldn't be found.

findMethod

private static Method findMethod(Class inClass,
                                 String inName)
Find a given method of a class.

Parameters:
inClass - class we want the method of.
inName - name of the method we want to access.
Returns:
the method (reflect) object or null if it couldn't be found.