public class PrivilegedAccessHelper extends Object
Constructor and Description |
---|
PrivilegedAccessHelper() |
Modifier and Type | Method and Description |
---|---|
static Class |
getClassForName(String className)
Execute a java Class.forName().
|
static Class |
getClassForName(String className,
boolean initialize,
ClassLoader loader)
Execute a java Class.forName() wrap the call in a doPrivileged block if necessary.
|
static ClassLoader |
getClassLoaderForClass(Class clazz)
Gets the class loader for a given class.
|
static Constructor |
getConstructorFor(Class javaClass,
Class[] args,
boolean shouldSetAccessible)
Get the public constructor for the given class and given arguments and wrap it in doPrivileged if
necessary.
|
static ClassLoader |
getContextClassLoader(Thread thread)
Get the context ClassLoader for a thread.
|
static Constructor |
getDeclaredConstructorFor(Class javaClass,
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 Field |
getDeclaredField(Class javaClass,
String fieldName,
boolean shouldSetAccessible)
Get a field actually declared in a class and wrap the call in doPrivileged if necessary.
|
static Field[] |
getDeclaredFields(Class clazz)
Get the list of fields in a class.
|
static Method |
getDeclaredMethod(Class clazz,
String methodName,
Class[] methodParameterTypes)
Return a method on a given class with the given method name and parameter
types.
|
static Method[] |
getDeclaredMethods(Class clazz)
Get the list of methods in a class.
|
static Field |
getField(Class javaClass,
String fieldName,
boolean shouldSetAccessible)
Get a field in a class or its superclasses and wrap the call in doPrivileged if necessary.
|
static Field[] |
getFields(Class clazz)
Get the list of public fields in a class.
|
static Class |
getFieldType(Field field)
Get the return type for a given method.
|
static String |
getLineSeparator()
Get the line separator character.
|
static Method |
getMethod(Class javaClass,
String methodName,
Class[] methodParameterTypes,
boolean shouldSetAccessible)
Get a method declared in the given class.
|
static Class[] |
getMethodParameterTypes(Method method)
Get the list of parameter types for a given method.
|
static Class |
getMethodReturnType(Method method)
Get the return type for a given method.
|
static Method[] |
getMethods(Class clazz)
Get the list of methods in a class.
|
static Method |
getPublicMethod(Class javaClass,
String methodName,
Class[] methodParameterTypes,
boolean shouldSetAccessible)
Get a public method declared in the given class.
|
static String |
getSystemProperty(String key)
INTERNAL:
Get the
System property indicated by the specified key . |
static String |
getSystemProperty(String key,
String def)
INTERNAL:
Get the
System property indicated by the specified key . |
static boolean |
getSystemPropertyBoolean(String key,
boolean def)
INTERNAL:
Get boolean value of the
System property indicated by the specified key . |
static Object |
getValueFromField(Field field,
Object object)
Get the value of the given field in the given object.
|
static Object |
invokeConstructor(Constructor constructor,
Object[] args)
Construct an object with the given Constructor and the given array of arguments.
|
static Object |
invokeMethod(Method method,
Object object)
Invoke the givenMethod on a givenObject.
|
static Object |
invokeMethod(Method method,
Object object,
Object[] parameters)
Invoke the givenMethod on a givenObject using the array of parameters given.
|
static Object |
newInstanceFromClass(Class clazz)
Get a new instance of a class using the default constructor.
|
static ClassLoader |
privilegedGetClassLoaderForClass(Class clazz)
Gets the class loader for a given class.
|
static void |
setDefaultUseDoPrivilegedValue(boolean def)
INTERNAL
It will be used to set default value of property "eclipselink.security.usedoprivileged"
if not passed as system property.
|
static void |
setValueInField(Field field,
Object object,
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 void setDefaultUseDoPrivilegedValue(boolean def)
public static Class getClassForName(String className) throws ClassNotFoundException
className
- ClassNotFoundException
public static Class getClassForName(String className, boolean initialize, ClassLoader loader) throws ClassNotFoundException
ClassNotFoundException
public static ClassLoader getClassLoaderForClass(Class clazz)
public static ClassLoader privilegedGetClassLoaderForClass(Class clazz)
public static Constructor getConstructorFor(Class javaClass, Class[] args, boolean shouldSetAccessible) throws 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 APINoSuchMethodException
public static ClassLoader getContextClassLoader(Thread thread)
public static Constructor getDeclaredConstructorFor(Class javaClass, Class[] args, boolean shouldSetAccessible) throws 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 APINoSuchMethodException
public static Field getField(Class javaClass, String fieldName, boolean shouldSetAccessible) throws NoSuchFieldException
javaClass
- The class to get the field fromfieldName
- The name of the fieldshouldSetAccessible
- whether or not to call the setAccessible APINoSuchFieldException
public static Field getDeclaredField(Class javaClass, String fieldName, boolean shouldSetAccessible) throws NoSuchFieldException
javaClass
- The class to get the field fromfieldName
- The name of the fieldshouldSetAccessible
- whether or not to call the setAccessible APINoSuchFieldException
public static Field[] getDeclaredFields(Class clazz)
clazz
- the class to get the fields from.public static Field[] getFields(Class clazz)
clazz
- the class to get the fields from.public static Method getDeclaredMethod(Class clazz, String methodName, Class[] methodParameterTypes) throws 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.NoSuchMethodException
public static Method getMethod(Class javaClass, String methodName, Class[] methodParameterTypes, boolean shouldSetAccessible) throws 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 APINoSuchMethodException
public static Method getPublicMethod(Class javaClass, String methodName, Class[] methodParameterTypes, boolean shouldSetAccessible) throws 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 methodshouldSetAccessible
- whether or not to call the setAccessible APINoSuchMethodException
public static Method[] getDeclaredMethods(Class clazz)
clazz
- the class to get the methods from.public static Class getFieldType(Field field)
field
- public static final String getSystemProperty(String key)
System
property indicated by the specified key
.public static final String getSystemProperty(String key, String def)
System
property indicated by the specified key
.public static final boolean getSystemPropertyBoolean(String key, boolean def)
System
property indicated by the specified key
.key
- The name of the System
property.def
- The default value.true
if the property value is "true"
(case insensitive)
or the property is not defined and def
is true
;
false
otherwise.public static String getLineSeparator()
public static Class[] getMethodParameterTypes(Method method)
method
- The method to get the parameter types ofpublic static Class getMethodReturnType(Method method)
method
- public static Method[] getMethods(Class clazz)
clazz
- the class to get the methods from.public static Object getValueFromField(Field field, Object object) throws IllegalAccessException
IllegalAccessException
public static Object invokeConstructor(Constructor constructor, Object[] args) throws IllegalAccessException, InvocationTargetException, InstantiationException
public static Object invokeMethod(Method method, Object object) throws IllegalAccessException, InvocationTargetException
public static Object invokeMethod(Method method, Object object, Object[] parameters) throws IllegalAccessException, InvocationTargetException
public static Object newInstanceFromClass(Class clazz) throws IllegalAccessException, InstantiationException
public static void setValueInField(Field field, Object object, Object value) throws IllegalAccessException
IllegalAccessException
public static boolean shouldUsePrivilegedAccess()
Note: it is not possible to run EclipseLink using doPrivileged blocks when there is no SecurityManager enabled.
EclipseLink 2.6.3, "build v20160428-59c81c5" API Reference