|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.hibernate.validator.util.ReflectionHelper
public final class ReflectionHelper
Some reflection utility methods. Where necessary calls will be performed as PrivilegedAction which is necessary
for situations where a security manager is in place.
| Method Summary | ||
|---|---|---|
static java.lang.Class<?> |
boxedType(java.lang.reflect.Type primitiveType)
Returns the autoboxed type of a primitive type. |
|
static java.util.Set<java.lang.Class<?>> |
computeAllImplementedInterfaces(java.lang.Class<?> clazz)
Get all interfaces a class directly implements. |
|
static java.util.List<java.lang.Class<?>> |
computeClassHierarchy(java.lang.Class<?> clazz,
boolean includeInterfaces)
Get all superclasses and optionally interfaces recursively. |
|
static boolean |
containsDeclaredField(java.lang.Class<?> clazz,
java.lang.String fieldName)
Checks whether the specified class contains a declared field with the given name. |
|
static boolean |
containsMethodWithPropertyName(java.lang.Class<?> clazz,
java.lang.String property)
Checks whether the specified class contains a method for the specified property. |
|
static
|
getAnnotationParameter(java.lang.annotation.Annotation annotation,
java.lang.String parameterName,
java.lang.Class<T> type)
|
|
static java.lang.ClassLoader |
getClassLoaderFromClass(java.lang.Class<?> clazz)
|
|
static java.lang.ClassLoader |
getClassLoaderFromContext()
|
|
static
|
getConstructor(java.lang.Class<T> clazz,
java.lang.Class<?>... params)
|
|
static java.lang.reflect.Field |
getDeclaredField(java.lang.Class<?> clazz,
java.lang.String fieldName)
Returns the declared field with the specified name or null if it does not exist. |
|
static java.lang.reflect.Field[] |
getDeclaredFields(java.lang.Class<?> clazz)
Returns the fields of the specified class. |
|
static java.lang.reflect.Method |
getDeclaredMethod(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Class<?>... parameterTypes)
Returns the declared method with the specified name and parameter types or null if
it does not exist. |
|
static java.lang.reflect.Method[] |
getDeclaredMethods(java.lang.Class<?> clazz)
Returns the declared methods of the specified class. |
|
static java.lang.reflect.Type |
getIndexedType(java.lang.reflect.Type type)
Determines the type of elements of an Iterable, array or the value of a Map. |
|
static java.lang.Object |
getIndexedValue(java.lang.Object value,
java.lang.Integer index)
Tries to retrieve the indexed value from the specified object. |
|
static java.lang.Object |
getMappedValue(java.lang.Object value,
java.lang.Object key)
Tries to retrieve the mapped value from the specified object. |
|
static java.lang.reflect.Member |
getMember(java.lang.Class<?> clazz,
java.lang.String property,
java.lang.annotation.ElementType elementType)
Returns the member with the given name and type. |
|
static java.lang.reflect.Method |
getMethod(java.lang.Class<?> clazz,
java.lang.String methodName)
Returns the method with the specified name or null if it does not exist. |
|
static java.lang.reflect.Method |
getMethodFromPropertyName(java.lang.Class<?> clazz,
java.lang.String methodName)
Returns the method with the specified property name or null if it does not exist. |
|
static java.lang.reflect.Method[] |
getMethods(java.lang.Class<?> clazz)
Returns the methods of the specified class (include inherited methods). |
|
static java.lang.String |
getPropertyName(java.lang.reflect.Member member)
Process bean properties getter by applying the JavaBean naming conventions. |
|
static java.lang.Class<?> |
getType(java.lang.reflect.Member member)
Returns the type of the field of return type of a method. |
|
static java.lang.Object |
getValue(java.lang.reflect.Member member,
java.lang.Object object)
|
|
static boolean |
haveSameSignature(java.lang.reflect.Method method1,
java.lang.reflect.Method method2)
Checks, whether the given methods have the same signature, which is the case if they have the same name, parameter count and types. |
|
static boolean |
isGetterMethod(java.lang.reflect.Method member)
Checks whether the given method's name is a valid JavaBeans getter name, meaning it starts with "is" or "has". |
|
static boolean |
isIterable(java.lang.reflect.Type type)
|
|
static boolean |
isList(java.lang.reflect.Type type)
|
|
static boolean |
isMap(java.lang.reflect.Type type)
|
|
static java.lang.Class<?> |
loadClass(java.lang.String className,
java.lang.Class<?> caller)
|
|
static
|
newConstructorInstance(java.lang.reflect.Constructor<T> constructor,
java.lang.Object... initArgs)
|
|
static
|
newInstance(java.lang.Class<T> clazz,
java.lang.String message)
|
|
static boolean |
propertyExists(java.lang.Class<?> clazz,
java.lang.String property,
java.lang.annotation.ElementType elementType)
Checks whether the property with the specified name and type exists on the given class. |
|
static void |
setAccessibility(java.lang.reflect.Member member)
|
|
static java.lang.reflect.Type |
typeOf(java.lang.reflect.Member member)
|
|
static java.lang.reflect.Type |
typeOf(java.lang.reflect.Method method,
int parameterIndex)
Returns the type of the parameter of the given method with the given parameter index. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static java.lang.ClassLoader getClassLoaderFromContext()
public static java.lang.ClassLoader getClassLoaderFromClass(java.lang.Class<?> clazz)
public static java.lang.Class<?> loadClass(java.lang.String className,
java.lang.Class<?> caller)
public static <T> java.lang.reflect.Constructor<T> getConstructor(java.lang.Class<T> clazz,
java.lang.Class<?>... params)
public static <T> T newInstance(java.lang.Class<T> clazz,
java.lang.String message)
public static <T> T newConstructorInstance(java.lang.reflect.Constructor<T> constructor,
java.lang.Object... initArgs)
public static <T> T getAnnotationParameter(java.lang.annotation.Annotation annotation,
java.lang.String parameterName,
java.lang.Class<T> type)
public static java.lang.String getPropertyName(java.lang.reflect.Member member)
member - the member for which to get the property name.
null
the method name id not according to the JavaBeans standard.public static boolean isGetterMethod(java.lang.reflect.Method member)
member - The method of interest.
public static boolean propertyExists(java.lang.Class<?> clazz,
java.lang.String property,
java.lang.annotation.ElementType elementType)
clazz - The class to check for the property. Cannot be null.property - The property name without 'is', 'get' or 'has'. Cannot be null or empty.elementType - The element type. Either ElementType.FIELD or ElementType METHOD.
true is the property and can be access via the specified type, false otherwise.
public static java.lang.reflect.Member getMember(java.lang.Class<?> clazz,
java.lang.String property,
java.lang.annotation.ElementType elementType)
clazz - The class from which to retrieve the member. Cannot be null.property - The property name without 'is', 'get' or 'has'. Cannot be null or empty.elementType - The element type. Either ElementType.FIELD or ElementType METHOD.
null if no such member exists.public static java.lang.Class<?> getType(java.lang.reflect.Member member)
member - the member for which to get the type.
public static java.lang.reflect.Type typeOf(java.lang.reflect.Member member)
member - The Member instance for which to retrieve the type.
Type of the given Field or Method.
java.lang.IllegalArgumentException - in case member is not a Field or Method.
public static java.lang.reflect.Type typeOf(java.lang.reflect.Method method,
int parameterIndex)
method - The method of interest.parameterIndex - The index of the parameter for which the type should be returned.
public static java.lang.Object getValue(java.lang.reflect.Member member,
java.lang.Object object)
public static void setAccessibility(java.lang.reflect.Member member)
public static java.lang.reflect.Type getIndexedType(java.lang.reflect.Type type)
Iterable, array or the value of a Map.
type - the type to inspect
Iterable, array or the value of a Map.
null is returned in case the type is not indexable (in the context of JSR 303).public static boolean isIterable(java.lang.reflect.Type type)
type - the type to check.
true if type is a iterable type, false otherwise.public static boolean isMap(java.lang.reflect.Type type)
type - the type to check.
true if type is implementing Map, false otherwise.public static boolean isList(java.lang.reflect.Type type)
type - the type to check.
true if type is implementing List, false otherwise.
public static java.lang.Object getIndexedValue(java.lang.Object value,
java.lang.Integer index)
value - The object from which to retrieve the indexed value. The object has to be non null and
either a collection or array.index - The index. The index does not have to be numerical. value could also be a map in which
case the index could also be a string key.
- Returns:
- The indexed value or
null if value is null or not a collection or array.
null is also returned in case the index does not exist.
public static java.lang.Object getMappedValue(java.lang.Object value,
java.lang.Object key)
value - The object from which to retrieve the mapped value. The object has to be non null and
must implement the @{code Map} interface.key - The map key. index.
null if value is null or not implementing @{code Map}.
public static java.lang.reflect.Field getDeclaredField(java.lang.Class<?> clazz,
java.lang.String fieldName)
null if it does not exist.
clazz - The class to check.fieldName - The field name.
null if it does not exist.
public static boolean containsDeclaredField(java.lang.Class<?> clazz,
java.lang.String fieldName)
clazz - The class to check.fieldName - The field name.
true if the field exists, false otherwise.public static java.lang.reflect.Field[] getDeclaredFields(java.lang.Class<?> clazz)
clazz - The class for which to retrieve the fields.
public static java.lang.reflect.Method getMethodFromPropertyName(java.lang.Class<?> clazz,
java.lang.String methodName)
null if it does not exist. This method will
prepend 'is' and 'get' to the property name and capitalize the first letter.
clazz - The class to check.methodName - The property name.
null if it does not exist.
public static boolean containsMethodWithPropertyName(java.lang.Class<?> clazz,
java.lang.String property)
clazz - The class to check.property - The property name.
true if the method exists, false otherwise.
public static java.lang.reflect.Method getMethod(java.lang.Class<?> clazz,
java.lang.String methodName)
null if it does not exist.
clazz - The class to check.methodName - The method name.
null if it does not exist.
public static java.lang.reflect.Method getDeclaredMethod(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Class<?>... parameterTypes)
null if
it does not exist.
clazz - The class to check.methodName - The method name.parameterTypes - The method parameter types.
null if it does not exist.public static java.lang.reflect.Method[] getDeclaredMethods(java.lang.Class<?> clazz)
clazz - The class for which to retrieve the methods.
public static java.lang.reflect.Method[] getMethods(java.lang.Class<?> clazz)
clazz - The class for which to retrieve the methods.
public static boolean haveSameSignature(java.lang.reflect.Method method1,
java.lang.reflect.Method method2)
method1 - A first method.method2 - A second method.
public static java.lang.Class<?> boxedType(java.lang.reflect.Type primitiveType)
primitiveType - the primitive type
java.lang.IllegalArgumentException - in case the parameter primitiveType does not represent a primitive type.
public static java.util.List<java.lang.Class<?>> computeClassHierarchy(java.lang.Class<?> clazz,
boolean includeInterfaces)
clazz - The class to start the search with.includeInterfaces - whether or not to include interfaces
clazz. The list contains the class itself! The empty
list is returned if clazz is null.public static java.util.Set<java.lang.Class<?>> computeAllImplementedInterfaces(java.lang.Class<?> clazz)
clazz - The class for which to find the interfaces
clazz implements. The empty list is returned if clazz does not
implement any interfaces or clazz is null
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||