public class ReflectionHelper
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
ReflectionHelper.ClassTypePair
A tuple consisting of a class and type of the class.
|
static class |
ReflectionHelper.DeclaringClassInterfacePair
A tuple consisting of a concrete class, declaring class that declares a
generic interface type.
|
static class |
ReflectionHelper.TypeClassPair |
Constructor and Description |
---|
ReflectionHelper() |
Modifier and Type | Method and Description |
---|---|
static java.security.PrivilegedAction<java.lang.Class<?>> |
classForNamePA(java.lang.String name)
Get privileged action to obtain Class from given class name.
|
static java.security.PrivilegedAction<java.lang.Class<?>> |
classForNamePA(java.lang.String name,
java.lang.ClassLoader cl)
Get privileged action to obtain Class from given class name.
|
static <T> java.security.PrivilegedExceptionAction<java.lang.Class<T>> |
classForNameWithExceptionPEA(java.lang.String name)
Get privileged exception action to obtain Class from given class name.
|
static <T> java.security.PrivilegedExceptionAction<java.lang.Class<T>> |
classForNameWithExceptionPEA(java.lang.String name,
java.lang.ClassLoader cl)
Get privileged exception action to obtain Class from given class name.
|
static java.security.PrivilegedAction<java.lang.reflect.Method> |
findMethodOnClassPA(java.lang.Class<?> c,
java.lang.reflect.Method m)
Get privileged action to find a method on a class given an existing method.
|
static java.lang.Class |
getArrayClass(java.lang.Class c)
Get Array class of component class.
|
static ReflectionHelper.DeclaringClassInterfacePair |
getClass(java.lang.Class concrete,
java.lang.Class iface)
Find the declaring class that implements or extends an interface.
|
static java.security.PrivilegedAction<java.lang.ClassLoader> |
getContextClassLoaderPA()
Get privileged action to obtain context class loader.
|
static java.lang.Class |
getDeclaringClass(java.lang.reflect.AccessibleObject ao) |
static java.security.PrivilegedAction<java.lang.reflect.Method> |
getFromStringStringMethodPA(java.lang.Class<?> c)
Get privileged action to get the static fromString(String ) method.
|
static java.lang.Class |
getGenericClass(java.lang.reflect.Type parameterizedType)
Get the class that is the type argument of a parameterized type.
|
static OsgiRegistry |
getOsgiRegistryInstance()
Returns an
OsgiRegistry instance. |
static java.lang.Class[] |
getParameterizedClassArguments(ReflectionHelper.DeclaringClassInterfacePair p)
Get the parameterized class arguments for a declaring class that
declares a generic interface type.
|
static java.lang.reflect.Type[] |
getParameterizedTypeArguments(ReflectionHelper.DeclaringClassInterfacePair p)
Get the parameterized type arguments for a declaring class that
declares a generic interface type.
|
static java.security.PrivilegedAction<java.lang.reflect.Constructor> |
getStringConstructorPA(java.lang.Class<?> c)
Get privileged action to obtain constructor that has a single parameter of String.
|
static ReflectionHelper.TypeClassPair |
getTypeArgumentAndClass(java.lang.reflect.Type parameterizedType) |
static java.security.PrivilegedAction<java.lang.reflect.Method> |
getValueOfStringMethodPA(java.lang.Class<?> c)
Get privileged action to obtain the static valueOf(String ) method.
|
static java.lang.String |
methodInstanceToString(java.lang.Object o,
java.lang.reflect.Method m)
Create a string representation of a method and an instance whose
class implements the method.
|
static java.lang.String |
objectToString(java.lang.Object o)
Create a string representation of an object.
|
static ReflectionHelper.ClassTypePair |
resolveTypeVariable(java.lang.Class c,
java.lang.Class dc,
java.lang.reflect.TypeVariable tv)
Given a type variable resolve the Java class of that variable.
|
static java.security.PrivilegedAction |
setAccessibleMethodPA(java.lang.reflect.Method m)
Get privileged action to set a method to be accessible.
|
public static java.lang.Class getDeclaringClass(java.lang.reflect.AccessibleObject ao)
public static java.lang.String objectToString(java.lang.Object o)
Returns a string consisting of the name of the class of which the
object is an instance, the at-sign character '@
', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
o.getClass().getName() + '@' + Integer.toHexString(o.hashCode())
o
- the object.public static java.lang.String methodInstanceToString(java.lang.Object o, java.lang.reflect.Method m)
Returns a string consisting of the name of the class of which the object
is an instance, the at-sign character '@
',
the unsigned hexadecimal representation of the hash code of the
object, the character '.
', the name of the method,
the character '(
', the list of method parameters, and
the character ')
'. In other words, thos method returns a
string equal to the value of:
o.getClass().getName() + '@' + Integer.toHexString(o.hashCode()) + '.' + m.getName() + '(' + <parameters> + ')'.
o
- the object whose class implements m
.m
- the method.public static java.security.PrivilegedAction<java.lang.Class<?>> classForNamePA(java.lang.String name)
name
- class name.null
if the class cannot be found.AccessController.doPrivileged(java.security.PrivilegedAction)
public static java.security.PrivilegedAction<java.lang.Class<?>> classForNamePA(java.lang.String name, java.lang.ClassLoader cl)
name
- class name.cl
- class loader to use, if null then the defining class loader
of this class will be utilized.null
if the class cannot be found.AccessController.doPrivileged(java.security.PrivilegedAction)
public static <T> java.security.PrivilegedExceptionAction<java.lang.Class<T>> classForNameWithExceptionPEA(java.lang.String name) throws java.lang.ClassNotFoundException
T
- class type.name
- class name.ClassNotFoundException
or return null
if the class cannot be found.java.lang.ClassNotFoundException
AccessController.doPrivileged(java.security.PrivilegedExceptionAction)
public static <T> java.security.PrivilegedExceptionAction<java.lang.Class<T>> classForNameWithExceptionPEA(java.lang.String name, java.lang.ClassLoader cl) throws java.lang.ClassNotFoundException
T
- class type.name
- class name.cl
- class loader to use, if null
then the defining class loader
of the calling class will be utilized.ClassNotFoundException
or returns null
if the class cannot be found.java.lang.ClassNotFoundException
AccessController.doPrivileged(java.security.PrivilegedExceptionAction)
public static java.security.PrivilegedAction<java.lang.ClassLoader> getContextClassLoaderPA()
null
if context class loader has not been set.AccessController.doPrivileged(java.security.PrivilegedAction)
public static java.security.PrivilegedAction setAccessibleMethodPA(java.lang.reflect.Method m)
m
- method to be set as accessible.AccessController.doPrivileged(java.security.PrivilegedAction)
public static java.lang.Class getGenericClass(java.lang.reflect.Type parameterizedType) throws java.lang.IllegalArgumentException
parameterizedType
- must be an instance of ParameterizedType
and have exactly one type argument.java.lang.IllegalArgumentException
- if the single type argument is not of
a class, or a generic array type, or the generic component type
of the generic array type is not class, or not a parameterized
type with a raw type that is not a class.public static ReflectionHelper.TypeClassPair getTypeArgumentAndClass(java.lang.reflect.Type parameterizedType) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public static java.lang.Class getArrayClass(java.lang.Class c)
c
- the component class of the arraypublic static java.security.PrivilegedAction<java.lang.reflect.Method> getValueOfStringMethodPA(java.lang.Class<?> c)
c
- The class to obtain the method.null
if the method is not present.AccessController.doPrivileged(java.security.PrivilegedAction)
public static java.security.PrivilegedAction<java.lang.reflect.Method> getFromStringStringMethodPA(java.lang.Class<?> c)
c
- class for which to get the method.null
if the method is not present.AccessController.doPrivileged(java.security.PrivilegedAction)
public static java.security.PrivilegedAction<java.lang.reflect.Constructor> getStringConstructorPA(java.lang.Class<?> c)
c
- The class for which to obtain the constructor.null
if the constructor is not present.AccessController.doPrivileged(java.security.PrivilegedAction)
public static java.lang.Class[] getParameterizedClassArguments(ReflectionHelper.DeclaringClassInterfacePair p)
p
- the declaring classpublic static java.lang.reflect.Type[] getParameterizedTypeArguments(ReflectionHelper.DeclaringClassInterfacePair p)
p
- the declaring classpublic static ReflectionHelper.DeclaringClassInterfacePair getClass(java.lang.Class concrete, java.lang.Class iface)
concrete
- the concrete class than directly or indirectly
implements or extends an interface class.iface
- the interface class.public static ReflectionHelper.ClassTypePair resolveTypeVariable(java.lang.Class c, java.lang.Class dc, java.lang.reflect.TypeVariable tv)
c
- the concrete class from which all type variables are resolveddc
- the declaring class where the type variable was definedtv
- the type variablepublic static java.security.PrivilegedAction<java.lang.reflect.Method> findMethodOnClassPA(java.lang.Class<?> c, java.lang.reflect.Method m)
TypeVariable
then that public method is
returned from the action.c
- the class to search for a public methodm
- the method to findAccessController.doPrivileged(java.security.PrivilegedAction)
public static OsgiRegistry getOsgiRegistryInstance()
OsgiRegistry
instance.OsgiRegistry
instance or null
if the class cannot be instantiated (not in OSGi environment).Copyright © 2016 Oracle Corporation. All Rights Reserved.