|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.objectweb.cjdbc.test.util.PrivilegedAccessor
a.k.a. The "ObjectMolester"
This class is used to access a method or field of an object no matter what the access modifier of the method or field. The syntax for accessing fields and methods is out of the ordinary because this class uses reflection to peel away protection.
Here is an example of using this to access a private member.
resolveName
is a private method of Class
.
Class c = Class.class; System.out.println( PrivilegedAccessor.invokeMethod(c, "resolveName", "/net/iss/common/PrivilegeAccessor"));
Constructor Summary | |
PrivilegedAccessor()
|
Method Summary | |
private static java.lang.reflect.Field |
getField(java.lang.Class thisClass,
java.lang.String fieldName)
Returns the named field from the given class. |
private static java.lang.reflect.Method |
getMethod(java.lang.Class thisClass,
java.lang.String methodName,
java.lang.Class[] classTypes)
Returns the named method with a method signature matching classTypes from the given class. |
static java.lang.reflect.Method |
getMethod(java.lang.Object instance,
java.lang.String methodName,
java.lang.Class[] classTypes)
|
static java.lang.Object |
getValue(java.lang.Object instance,
java.lang.String fieldName)
Gets the value of the named field and returns it as an object. |
static java.lang.Object |
invokeMethod(java.lang.Object instance,
java.lang.String methodName,
java.lang.Object arg)
Calls a method on the given object instance with the given argument. |
static java.lang.Object |
invokeMethod(java.lang.Object instance,
java.lang.String methodName,
java.lang.Object[] args)
Calls a method on the given object instance with the given arguments. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public PrivilegedAccessor()
Method Detail |
public static java.lang.Object getValue(java.lang.Object instance, java.lang.String fieldName) throws java.lang.IllegalAccessException, java.lang.NoSuchFieldException
instance
- the object instancefieldName
- the name of the field
java.lang.IllegalAccessException
- if the access to the class is refused
java.lang.NoSuchFieldException
- if the field name does not existpublic static java.lang.Object invokeMethod(java.lang.Object instance, java.lang.String methodName, java.lang.Object arg) throws java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
instance
- the object instancemethodName
- the name of the method to invokearg
- the argument to pass to the method
Object
instance
java.lang.NoSuchMethodException
- when no such method exists
java.lang.IllegalAccessException
- if the access to the class is refused
java.lang.reflect.InvocationTargetException
- if the invocation failedinvokeMethod(Object,String,Object[])
public static java.lang.Object invokeMethod(java.lang.Object instance, java.lang.String methodName, java.lang.Object[] args) throws java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
instance
- the object instancemethodName
- the name of the method to invokeargs
- an array of objects to pass as arguments
Object
instance
java.lang.NoSuchMethodException
- when no such method exists
java.lang.IllegalAccessException
- if the access to the class is refused
java.lang.reflect.InvocationTargetException
- if the invocation failedinvokeMethod(Object,String,Object)
public static java.lang.reflect.Method getMethod(java.lang.Object instance, java.lang.String methodName, java.lang.Class[] classTypes) throws java.lang.NoSuchMethodException
instance
- the object instancemethodName
- the method nameclassTypes
- class types
Method
instance
java.lang.NoSuchMethodException
- when no such method existsprivate static java.lang.reflect.Field getField(java.lang.Class thisClass, java.lang.String fieldName) throws java.lang.NoSuchFieldException
thisClass
- classfieldName
- field name
Field
instance
java.lang.NoSuchFieldException
- when no such field existsprivate static java.lang.reflect.Method getMethod(java.lang.Class thisClass, java.lang.String methodName, java.lang.Class[] classTypes) throws java.lang.NoSuchMethodException
thisClass
- classmethodName
- method nameclassTypes
- class types
Method
instance
java.lang.NoSuchMethodException
- when no such method exists
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |