Methods Summary |
---|
private static java.lang.reflect.Field | findDeclaredField(java.lang.Class javaClass, java.lang.String fieldName)Finding a field within a class potentially has to navigate through it's superclasses to eventually
find the field. This method is called by the public getDeclaredField() method and does a recursive
search for the named field in the given classes or it's superclasses.
try {
return javaClass.getDeclaredField(fieldName);
} catch (NoSuchFieldException ex) {
Class superclass = javaClass.getSuperclass();
if (superclass == null) {
throw ex;
} else {
return findDeclaredField(superclass, fieldName);
}
}
|
private static java.lang.reflect.Method | findMethod(java.lang.Class javaClass, java.lang.String methodName, java.lang.Class[] methodParameterTypes)Finding a method within a class potentially has to navigate through it's superclasses to eventually
find the method. This method is called by the public getDeclaredMethod() method and does a recursive
search for the named method in the given classes or it's superclasses.
try {
return javaClass.getDeclaredMethod(methodName, methodParameterTypes);
} catch (NoSuchMethodException ex) {
Class superclass = javaClass.getSuperclass();
if (superclass == null) {
throw ex;
} else {
try{
return findMethod(superclass, methodName, methodParameterTypes);
}catch (NoSuchMethodException lastEx){
throw ex;
}
}
}
|
public static java.lang.Class | getClassForName(java.lang.String className)Execute a java Class.forName(). Wrap the call in a doPrivileged block if necessary.
return Class.forName(className);
|
public 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.
return Class.forName(className, initialize, loader);
|
public static java.lang.ClassLoader | getClassLoaderForClass(java.lang.Class clazz)Gets the class loader for a given class. Wraps the call in a privileged block if necessary
return clazz.getClassLoader();
|
public 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. The shouldSetAccessible parameter allows the the setAccessible API to be called as well.
This option was added to avoid making multiple doPrivileged calls within InstantiationPolicy.
Constructor result = javaClass.getConstructor(args);
if (shouldSetAccessible) {
result.setAccessible(true);
}
return result;
|
public static java.lang.ClassLoader | getContextClassLoader(java.lang.Thread thread)Get the context ClassLoader for a thread. Wrap the call in a doPrivileged block if necessary.
return thread.getContextClassLoader();
|
public 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. The shouldSetAccessible parameter allows
the the setAccessible API to be called as well. This option was added to avoid making multiple
doPrivileged calls within InstantiationPolicy.
Constructor result = javaClass.getDeclaredConstructor(args);
if (shouldSetAccessible) {
result.setAccessible(true);
}
return result;
|
public 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.
The shouldSetAccessible parameter allows the the setAccessible API to be called as well.
This option was added to avoid making multiple doPrivileged calls within InstanceVariableAttributeAccessor.
Field field = javaClass.getDeclaredField(fieldName);
if (shouldSetAccessible) {
field.setAccessible(true);
}
return field;
|
public static java.lang.reflect.Field[] | getDeclaredFields(java.lang.Class clazz)Get the list of fields in a class. Wrap the call in doPrivileged if necessary
Excludes inherited fields.
return clazz.getDeclaredFields();
|
public 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. This call will NOT traverse the superclasses. Wrap the call in
doPrivileged if necessary.
return clazz.getDeclaredMethod(methodName, methodParameterTypes);
|
public static java.lang.reflect.Method[] | getDeclaredMethods(java.lang.Class clazz)Get the list of methods in a class. Wrap the call in doPrivileged if
necessary. Excludes inherited methods.
return clazz.getDeclaredMethods();
|
public 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.
The shouldSetAccessible parameter allows the the setAccessible API to be called as well.
This option was added to avoid making multiple doPrivileged calls within InstanceVariableAttributeAccessor.
Field field = (Field)findDeclaredField(javaClass, fieldName);
if (shouldSetAccessible) {
field.setAccessible(true);
}
return field;
|
public static java.lang.Class | getFieldType(java.lang.reflect.Field field)Get the return type for a given method. Wrap the call in doPrivileged if necessary.
return field.getType();
|
public static java.lang.String | getLineSeparator()Get the line separator character.
Previous versions of TopLink always did this in a privileged block so we will continue to do so.
if (shouldUsePrivilegedAccess()) {
return (String)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty("file.separator");
}
});
} else {
return oracle.toplink.essentials.internal.helper.Helper.cr();
}
|
public 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. Wrap the call in doPrivileged
if necessary. This call will traver the superclasses. The
shouldSetAccessible parameter allows the the setAccessible API to be
called as well. This option was added to avoid making multiple
doPrivileged calls within MethodBasedAttributeAccessor.
Method method = findMethod(javaClass, methodName, methodParameterTypes);
if (shouldSetAccessible) {
method.setAccessible(true);
}
return method;
|
public static java.lang.Class[] | getMethodParameterTypes(java.lang.reflect.Method method)Get the list of parameter types for a given method. Wrap the call in doPrivileged if necessary.
return method.getParameterTypes();
|
public static java.lang.Class | getMethodReturnType(java.lang.reflect.Method method)Get the return type for a given method. Wrap the call in doPrivileged if necessary.
return method.getReturnType();
|
public static java.lang.reflect.Method[] | getMethods(java.lang.Class clazz)Get the list of methods in a class. Wrap the call in doPrivileged if
necessary. This call will traver the superclasses.
return clazz.getMethods();
|
public 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.
return field.get(object);
|
public 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. Wrap the call in a
doPrivileged block if necessary.
return constructor.newInstance(args);
|
public 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. Wrap in a doPrivileged block
if necessary.
// Ensure the method is accessible.
if (!method.isAccessible()) {
method.setAccessible(true);
}
return method.invoke(object, parameters);
|
public static java.lang.Object | newInstanceFromClass(java.lang.Class clazz)Get a new instance of a class using the default constructor. Wrap the call in a privileged block
if necessary.
return clazz.newInstance();
|
public 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. Wrap the call in a privileged block
if necessary.
field.set(object, value);
|
public static boolean | shouldUsePrivilegedAccess()This method checks to see if calls should be made to doPrivileged.
In general, if a security manager is enabled, it will return true and if one
is not enabled, it will return false.
It will, however, always return false if either of the following two java properties is
set.
oracle.j2ee.toplink.security.usedoprivileged=false
oracle.j2ee.security.usedoprivileged=false
Note: it is not possible to run TopLink using doPrivileged blocks when there is no SecurityManager
enabled.
// We will only detect whether to use doPrivileged once.
if (shouldSecurityManagerBeChecked) {
shouldSecurityManagerBeChecked = false;
Boolean privilegedPropertySet = (Boolean)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
boolean propertySet;
// check TopLink and OC4j doPrivileged flag.
String usePrivileged = System.getProperty("oracle.j2ee.toplink.security.usedoprivileged");
String oc4jUsePrivileged = System.getProperty("oracle.j2ee.security.usedoprivileged");
propertySet = (((usePrivileged != null) && usePrivileged.equalsIgnoreCase("false")) || ((oc4jUsePrivileged != null) && oc4jUsePrivileged.equalsIgnoreCase("false")));
return new Boolean(propertySet);
}
});
if (privilegedPropertySet.booleanValue()) {
shouldUsePrivilegedAccess = false;
} else {
shouldUsePrivilegedAccess = (System.getSecurityManager() != null);
}
}
return shouldUsePrivilegedAccess;
|