|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectsilk.performer.ReflectionUtil
The ReflectionUtil class provides methods for reading and writing non-public fields of objects, for reading non-public static fields of classes and for reconstructing objects from a serialized representation stored in a file. These methods are recorded as needed by SilkPerformer's Java Recorder.
| Constructor Summary | |
ReflectionUtil()
Default constructor. |
|
ReflectionUtil(SilkPerformer silkPerformer)
Constructor for use within SilkPerformers JavaFramework. |
|
| Method Summary | |
java.lang.Object |
deserialize(java.lang.String identifier)
Reconstructs an object from a serialized version stored in a file. |
void |
ensureSecurityManager()
Ensures that a security manager is installed. |
static boolean |
getNpBoolean(java.lang.Object obj,
java.lang.String fieldName)
Retrieves the boolean value of the specified field of the specified object.
|
static byte |
getNpByte(java.lang.Object obj,
java.lang.String fieldName)
Retrieves the byte value of the specified field of the specified object.
|
static char |
getNpChar(java.lang.Object obj,
java.lang.String fieldName)
Retrieves the char value of the specified field of the specified object.
|
static double |
getNpDouble(java.lang.Object obj,
java.lang.String fieldName)
Retrieves the double value of the specified field of the specified object.
|
static float |
getNpFloat(java.lang.Object obj,
java.lang.String fieldName)
Retrieves the float value of the specified field of the specified object.
|
static int |
getNpInt(java.lang.Object obj,
java.lang.String fieldName)
Retrieves the int value of the specified field of the specified object.
|
static long |
getNpLong(java.lang.Object obj,
java.lang.String fieldName)
Retrieves the long value of the specified field of the specified object.
|
static java.lang.Object |
getNpObject(java.lang.Object obj,
java.lang.String fieldName)
Retrieves the Object value of the specified field of the specified object.
|
static short |
getNpShort(java.lang.Object obj,
java.lang.String fieldName)
Retrieves the short value of the specified field of the specified object.
|
static boolean |
getNpStaticBoolean(java.lang.Class clazz,
java.lang.String fieldName)
Retrieves the boolean value of the specified static field of the specified class.
|
static byte |
getNpStaticByte(java.lang.Class clazz,
java.lang.String fieldName)
Retrieves the byte value of the specified static field of the specified class.
|
static char |
getNpStaticChar(java.lang.Class clazz,
java.lang.String fieldName)
Retrieves the char value of the specified static field of the specified class.
|
static double |
getNpStaticDouble(java.lang.Class clazz,
java.lang.String fieldName)
Retrieves the double value of the specified static field of the specified class.
|
static float |
getNpStaticFloat(java.lang.Class clazz,
java.lang.String fieldName)
Retrieves the float value of the specified static field of the specified class.
|
static int |
getNpStaticInt(java.lang.Class clazz,
java.lang.String fieldName)
Retrieves the int value of the specified static field of the specified class.
|
static long |
getNpStaticLong(java.lang.Class clazz,
java.lang.String fieldName)
Retrieves the long value of the specified static field of the specified class.
|
static java.lang.Object |
getNpStaticObject(java.lang.Class clazz,
java.lang.String fieldName)
Retrieves the Object value of the specified static field of the specified class.
|
static short |
getNpStaticShort(java.lang.Class clazz,
java.lang.String fieldName)
Retrieves the short value of the specified static field of the specified class.
|
static void |
setPrivateField(java.lang.Object obj,
java.lang.String fieldName,
boolean value)
Assigns a boolean value to the specified field of the specified object.
|
static void |
setPrivateField(java.lang.Object obj,
java.lang.String fieldName,
byte value)
Assigns a byte value to the specified field of the specified object.
|
static void |
setPrivateField(java.lang.Object obj,
java.lang.String fieldName,
char value)
Assigns a char value to the specified field of the specified object.
|
static void |
setPrivateField(java.lang.Object obj,
java.lang.String fieldName,
double value)
Assigns a double value to the specified field of the specified object.
|
static void |
setPrivateField(java.lang.Object obj,
java.lang.String fieldName,
float value)
Assigns a float value to the specified field of the specified object.
|
static void |
setPrivateField(java.lang.Object obj,
java.lang.String fieldName,
int value)
Assigns an int value to the specified field of the specified object.
|
static void |
setPrivateField(java.lang.Object obj,
java.lang.String fieldName,
long value)
Assigns a long value to the specified field of the specified object.
|
static void |
setPrivateField(java.lang.Object obj,
java.lang.String fieldName,
java.lang.Object value)
Assigns an Object value to the specified field of the specified object.
|
static void |
setPrivateField(java.lang.Object obj,
java.lang.String fieldName,
short value)
Assigns a short value to the specified field of the specified object.
|
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public ReflectionUtil()
For use when scripts recorded with SilkPerformer's Java Recorder are executed outside of SilkPerformer, e.g. JUnit.
The method deserialize will use the context classloader to find the file which contains a serialized object.
public ReflectionUtil(SilkPerformer silkPerformer)
The method deserialize will use the specified SilkPerformer object to find the file which contains a
serialized object. This includes searching in datafiles attached to a SilkPerformer project.
silkPerformer - The SilkPerformer object which links to SilkPerformer's replaying engine.| Method Detail |
public void ensureSecurityManager()
If no security manager is installed, a new RMISecurityManager will be installed, otherwise no action is performed.
This is useful for RMI applications, which require that a security manager is installed.
public java.lang.Object deserialize(java.lang.String identifier)
throws SilkPerformerException
When constructed with the default constructor, the specified file must
be available within the classpath of the context classloader.
When used within SilkPerformer's replay engine and constructed
with ReflectionUtil(SilkPerformer), the specified file
will be search in the datafiles attached to the current SilkPerformer project.
identifier - Specifies the filename without extension. The extension ".ser" is added automatically.
SilkPerformerException
public static void setPrivateField(java.lang.Object obj,
java.lang.String fieldName,
java.lang.Object value)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException
Object value to the specified field of the specified object.
obj - The object.fieldName - The name of the field. This field needs not to be public.value - Value to assign to the field.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
public static void setPrivateField(java.lang.Object obj,
java.lang.String fieldName,
boolean value)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException
boolean value to the specified field of the specified object.
obj - The object.fieldName - The name of the field. This field needs not to be public.value - Value to assign to the field.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
public static void setPrivateField(java.lang.Object obj,
java.lang.String fieldName,
byte value)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException
byte value to the specified field of the specified object.
obj - The object.fieldName - The name of the field. This field needs not to be public.value - Value to assign to the field.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
public static void setPrivateField(java.lang.Object obj,
java.lang.String fieldName,
short value)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException
short value to the specified field of the specified object.
obj - The object.fieldName - The name of the field. This field needs not to be public.value - Value to assign to the field.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
public static void setPrivateField(java.lang.Object obj,
java.lang.String fieldName,
int value)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException
int value to the specified field of the specified object.
obj - The object.fieldName - The name of the field. This field needs not to be public.value - Value to assign to the field.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
public static void setPrivateField(java.lang.Object obj,
java.lang.String fieldName,
long value)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException
long value to the specified field of the specified object.
obj - The object.fieldName - The name of the field. This field needs not to be public.value - Value to assign to the field.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
public static void setPrivateField(java.lang.Object obj,
java.lang.String fieldName,
char value)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException
char value to the specified field of the specified object.
obj - The object.fieldName - The name of the field. This field needs not to be public.value - Value to assign to the field.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
public static void setPrivateField(java.lang.Object obj,
java.lang.String fieldName,
float value)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException
float value to the specified field of the specified object.
obj - The object.fieldName - The name of the field. This field needs not to be public.value - Value to assign to the field.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
public static void setPrivateField(java.lang.Object obj,
java.lang.String fieldName,
double value)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException
double value to the specified field of the specified object.
obj - The object.fieldName - The name of the field. This field needs not to be public.value - Value to assign to the field.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
public static java.lang.Object getNpObject(java.lang.Object obj,
java.lang.String fieldName)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException
Object value of the specified field of the specified object.
obj - The object.fieldName - The name of the field. This field needs not to be public.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
public static boolean getNpBoolean(java.lang.Object obj,
java.lang.String fieldName)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException
boolean value of the specified field of the specified object.
obj - The object.fieldName - The name of the field. This field needs not to be public.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
public static byte getNpByte(java.lang.Object obj,
java.lang.String fieldName)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException
byte value of the specified field of the specified object.
obj - The object.fieldName - The name of the field. This field needs not to be public.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
public static short getNpShort(java.lang.Object obj,
java.lang.String fieldName)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException
short value of the specified field of the specified object.
obj - The object.fieldName - The name of the field. This field needs not to be public.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
public static int getNpInt(java.lang.Object obj,
java.lang.String fieldName)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException
int value of the specified field of the specified object.
obj - The object.fieldName - The name of the field. This field needs not to be public.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
public static long getNpLong(java.lang.Object obj,
java.lang.String fieldName)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException
long value of the specified field of the specified object.
obj - The object.fieldName - The name of the field. This field needs not to be public.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
public static char getNpChar(java.lang.Object obj,
java.lang.String fieldName)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException
char value of the specified field of the specified object.
obj - The object.fieldName - The name of the field. This field needs not to be public.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
public static float getNpFloat(java.lang.Object obj,
java.lang.String fieldName)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException
float value of the specified field of the specified object.
obj - The object.fieldName - The name of the field. This field needs not to be public.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
public static double getNpDouble(java.lang.Object obj,
java.lang.String fieldName)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException
double value of the specified field of the specified object.
obj - The object.fieldName - The name of the field. This field needs not to be public.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
public static java.lang.Object getNpStaticObject(java.lang.Class clazz,
java.lang.String fieldName)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException,
SilkPerformerException
Object value of the specified static field of the specified class.
clazz - The class.fieldName - The name of the field. This field needs not to be public.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
SilkPerformerException
public static boolean getNpStaticBoolean(java.lang.Class clazz,
java.lang.String fieldName)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException,
SilkPerformerException
boolean value of the specified static field of the specified class.
clazz - The class.fieldName - The name of the field. This field needs not to be public.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
SilkPerformerException
public static byte getNpStaticByte(java.lang.Class clazz,
java.lang.String fieldName)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException,
SilkPerformerException
byte value of the specified static field of the specified class.
clazz - The class.fieldName - The name of the field. This field needs not to be public.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
SilkPerformerException
public static short getNpStaticShort(java.lang.Class clazz,
java.lang.String fieldName)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException,
SilkPerformerException
short value of the specified static field of the specified class.
clazz - The class.fieldName - The name of the field. This field needs not to be public.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
SilkPerformerException
public static int getNpStaticInt(java.lang.Class clazz,
java.lang.String fieldName)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException,
SilkPerformerException
int value of the specified static field of the specified class.
clazz - The class.fieldName - The name of the field. This field needs not to be public.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
SilkPerformerException
public static long getNpStaticLong(java.lang.Class clazz,
java.lang.String fieldName)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException,
SilkPerformerException
long value of the specified static field of the specified class.
clazz - The class.fieldName - The name of the field. This field needs not to be public.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
SilkPerformerException
public static char getNpStaticChar(java.lang.Class clazz,
java.lang.String fieldName)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException,
SilkPerformerException
char value of the specified static field of the specified class.
clazz - The class.fieldName - The name of the field. This field needs not to be public.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
SilkPerformerException
public static float getNpStaticFloat(java.lang.Class clazz,
java.lang.String fieldName)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException,
SilkPerformerException
float value of the specified static field of the specified class.
clazz - The class.fieldName - The name of the field. This field needs not to be public.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
SilkPerformerException
public static double getNpStaticDouble(java.lang.Class clazz,
java.lang.String fieldName)
throws java.lang.NoSuchFieldException,
java.lang.IllegalAccessException,
SilkPerformerException
double value of the specified static field of the specified class.
clazz - The class.fieldName - The name of the field. This field needs not to be public.
java.lang.NoSuchFieldException
java.lang.IllegalAccessException
SilkPerformerException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||