|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectpt.moredata.tests.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 | |
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
java.lang.NoSuchFieldException
public 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
java.lang.NoSuchMethodException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetExceptioninvokeMethod(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
java.lang.NoSuchMethodException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetExceptioninvokeMethod(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
java.lang.NoSuchMethodException
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||