public class PrivilegedAccessHelper
extends java.lang.Object
| Constructor and Description |
|---|
PrivilegedAccessHelper() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.Class |
getClassForName(java.lang.String className)
Execute a java Class.forName().
|
static java.lang.Class |
getClassForName(java.lang.String className,
boolean initialize,
java.lang.ClassLoader loader)
Execute a java Class.forName() wrap the call in a doPrivileged block if necessary.
|
static java.lang.ClassLoader |
getClassLoaderForClass(java.lang.Class clazz)
Gets the class loader for a given class.
|
static java.lang.reflect.Constructor |
getConstructorFor(java.lang.Class javaClass,
java.lang.Class[] args,
boolean shouldSetAccessible)
Get the public constructor for the given class and given arguments and wrap it in doPrivileged if
necessary.
|
static java.lang.ClassLoader |
getContextClassLoader(java.lang.Thread thread)
Get the context ClassLoader for a thread.
|
static java.lang.reflect.Constructor |
getDeclaredConstructorFor(java.lang.Class javaClass,
java.lang.Class[] args,
boolean shouldSetAccessible)
Get the constructor for the given class and given arguments (regardless of whether it is public
or private))and wrap it in doPrivileged if necessary.
|
static java.lang.reflect.Field |
getDeclaredField(java.lang.Class javaClass,
java.lang.String fieldName,
boolean shouldSetAccessible)
Get a field actually declared in a class and wrap the call in doPrivileged if necessary.
|
static java.lang.reflect.Field[] |
getDeclaredFields(java.lang.Class clazz)
Get the list of fields in a class.
|
static java.lang.reflect.Method |
getDeclaredMethod(java.lang.Class clazz,
java.lang.String methodName,
java.lang.Class[] methodParameterTypes)
Return a method on a given class with the given method name and parameter
types.
|
static java.lang.reflect.Method[] |
getDeclaredMethods(java.lang.Class clazz)
Get the list of methods in a class.
|
static java.lang.reflect.Field |
getField(java.lang.Class javaClass,
java.lang.String fieldName,
boolean shouldSetAccessible)
Get a field in a class or its superclasses and wrap the call in doPrivileged if necessary.
|
static java.lang.Class |
getFieldType(java.lang.reflect.Field field)
Get the return type for a given method.
|
static java.lang.String |
getLineSeparator()
Get the line separator character.
|
static java.lang.reflect.Method |
getMethod(java.lang.Class javaClass,
java.lang.String methodName,
java.lang.Class[] methodParameterTypes,
boolean shouldSetAccessible)
Get a method declared in the given class.
|
static java.lang.Class[] |
getMethodParameterTypes(java.lang.reflect.Method method)
Get the list of parameter types for a given method.
|
static java.lang.Class |
getMethodReturnType(java.lang.reflect.Method method)
Get the return type for a given method.
|
static java.lang.reflect.Method[] |
getMethods(java.lang.Class clazz)
Get the list of methods in a class.
|
static java.lang.Object |
getValueFromField(java.lang.reflect.Field field,
java.lang.Object object)
Get the value of the given field in the given object.
|
static java.lang.Object |
invokeConstructor(java.lang.reflect.Constructor constructor,
java.lang.Object[] args)
Construct an object with the given Constructor and the given array of arguments.
|
static java.lang.Object |
invokeMethod(java.lang.reflect.Method method,
java.lang.Object object,
java.lang.Object[] parameters)
Invoke the givenMethod on a givenObject using the array of parameters given.
|
static java.lang.Object |
newInstanceFromClass(java.lang.Class clazz)
Get a new instance of a class using the default constructor.
|
static void |
setValueInField(java.lang.reflect.Field field,
java.lang.Object object,
java.lang.Object value)
Set the value of a given field in the given object with the value given.
|
static boolean |
shouldUsePrivilegedAccess()
This method checks to see if calls should be made to doPrivileged.
|
public static java.lang.Class getClassForName(java.lang.String className)
throws java.lang.ClassNotFoundException
className - java.lang.ClassNotFoundExceptionpublic static java.lang.Class getClassForName(java.lang.String className,
boolean initialize,
java.lang.ClassLoader loader)
throws java.lang.ClassNotFoundException
className - initialize - loader - java.lang.ClassNotFoundExceptionpublic static java.lang.ClassLoader getClassLoaderForClass(java.lang.Class clazz)
public static java.lang.reflect.Constructor getConstructorFor(java.lang.Class javaClass,
java.lang.Class[] args,
boolean shouldSetAccessible)
throws java.lang.NoSuchMethodException
javaClass - The class to get the Constructor forargs - An array of classes representing the argument types of the constructorshouldSetAccessible - whether or not to call the setAccessible APIjava.lang.NoSuchMethodExceptionpublic static java.lang.ClassLoader getContextClassLoader(java.lang.Thread thread)
public static java.lang.reflect.Constructor getDeclaredConstructorFor(java.lang.Class javaClass,
java.lang.Class[] args,
boolean shouldSetAccessible)
throws java.lang.NoSuchMethodException
javaClass - The class to get the Constructor forargs - An array of classes representing the argument types of the constructorshouldSetAccessible - whether or not to call the setAccessible APIjava.lang.NoSuchMethodExceptionpublic static java.lang.reflect.Field getField(java.lang.Class javaClass,
java.lang.String fieldName,
boolean shouldSetAccessible)
throws java.lang.NoSuchFieldException
javaClass - The class to get the field fromfieldName - The name of the fieldshouldSetAccessible - whether or not to call the setAccessible APIjava.lang.NoSuchFieldExceptionpublic static java.lang.reflect.Field getDeclaredField(java.lang.Class javaClass,
java.lang.String fieldName,
boolean shouldSetAccessible)
throws java.lang.NoSuchFieldException
javaClass - The class to get the field fromfieldName - The name of the fieldshouldSetAccessible - whether or not to call the setAccessible APIjava.lang.NoSuchFieldExceptionpublic static java.lang.reflect.Field[] getDeclaredFields(java.lang.Class clazz)
clazz - the class to get the fields from.public static java.lang.reflect.Method getDeclaredMethod(java.lang.Class clazz,
java.lang.String methodName,
java.lang.Class[] methodParameterTypes)
throws java.lang.NoSuchMethodException
method - the class to get the method frommethodName - the name of the method to getmethodParameters - a list of classes representing the classes of the
parameters of the method.java.lang.NoSuchMethodExceptionpublic static java.lang.reflect.Method getMethod(java.lang.Class javaClass,
java.lang.String methodName,
java.lang.Class[] methodParameterTypes,
boolean shouldSetAccessible)
throws java.lang.NoSuchMethodException
javaClass - The class to get the method frommethodName - The name of the method to getmethodParameterTypes - A list of classes representing the classes of the parameters of the mthodshouldSetAccessible - whether or not to call the setAccessible APIjava.lang.NoSuchMethodExceptionpublic static java.lang.reflect.Method[] getDeclaredMethods(java.lang.Class clazz)
clazz - the class to get the methods from.public static java.lang.Class getFieldType(java.lang.reflect.Field field)
field - public static java.lang.String getLineSeparator()
public static java.lang.Class[] getMethodParameterTypes(java.lang.reflect.Method method)
method - The method to get the parameter types ofpublic static java.lang.Class getMethodReturnType(java.lang.reflect.Method method)
method - public static java.lang.reflect.Method[] getMethods(java.lang.Class clazz)
clazz - the class to get the methods from.public static java.lang.Object getValueFromField(java.lang.reflect.Field field,
java.lang.Object object)
throws java.lang.IllegalAccessException
java.lang.IllegalAccessExceptionpublic static java.lang.Object invokeConstructor(java.lang.reflect.Constructor constructor,
java.lang.Object[] args)
throws java.lang.IllegalAccessException,
java.lang.reflect.InvocationTargetException,
java.lang.InstantiationException
java.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetExceptionjava.lang.InstantiationExceptionpublic static java.lang.Object invokeMethod(java.lang.reflect.Method method,
java.lang.Object object,
java.lang.Object[] parameters)
throws java.lang.IllegalAccessException,
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetExceptionpublic static java.lang.Object newInstanceFromClass(java.lang.Class clazz)
throws java.lang.IllegalAccessException,
java.lang.InstantiationException
java.lang.IllegalAccessExceptionjava.lang.InstantiationExceptionpublic static void setValueInField(java.lang.reflect.Field field,
java.lang.Object object,
java.lang.Object value)
throws java.lang.IllegalAccessException
java.lang.IllegalAccessExceptionpublic static boolean shouldUsePrivilegedAccess()