|
||||||||||
| 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 Class<?> |
boxedType(Type primitiveType)
Returns the autoboxed type of a primitive type. |
|
static List<Class<?>> |
computeClassHierarchy(Class<?> clazz)
Get all superclasses and interfaces recursively. |
|
static boolean |
containsField(Class<?> clazz,
String fieldName)
Checks whether the specified class contains a field with the given name. |
|
static boolean |
containsMethod(Class<?> clazz,
String methodName)
Checks whether the specified class contains a method with the given name. |
|
static boolean |
containsMethodWithPropertyName(Class<?> clazz,
String property)
Checks whether the specified class contains a method for the specified property. |
|
static
|
getAnnotationParameter(Annotation annotation,
String parameterName,
Class<T> type)
|
|
static ClassLoader |
getClassLoaderFromClass(Class<?> clazz)
|
|
static ClassLoader |
getClassLoaderFromContext()
|
|
static
|
getConstructor(Class<T> clazz,
Class<?>... params)
|
|
static Field |
getField(Class<?> clazz,
String fieldName)
Returns the field with the specified name or null if it does not exist. |
|
static Field[] |
getFields(Class<?> clazz)
Returns the fields of the specified class. |
|
static Type |
getIndexedType(Type type)
Determines the type of elements of an Iterable, array or the value of a Map. |
|
static Object |
getIndexedValue(Object value,
Integer index)
Tries to retrieve the indexed value from the specified object. |
|
static Object |
getMappedValue(Object value,
Object key)
Tries to retrieve the mapped value from the specified object. |
|
static Member |
getMember(Class<?> clazz,
String property,
ElementType elementType)
Returns the member with the given name and type. |
|
static Method |
getMethod(Class<?> clazz,
String methodName)
Returns the method with the specified name or null if it does not exist. |
|
static Method |
getMethodFromPropertyName(Class<?> clazz,
String methodName)
Returns the method with the specified property name or null if it does not exist. |
|
static Method[] |
getMethods(Class<?> clazz)
Returns the methods of the specified class. |
|
static String |
getPropertyName(Member member)
Process bean properties getter by applying the JavaBean naming conventions. |
|
static Class<?> |
getType(Member member)
Returns the type of the field of return type of a method. |
|
static Object |
getValue(Member member,
Object object)
|
|
static boolean |
isIterable(Type type)
|
|
static boolean |
isList(Type type)
|
|
static boolean |
isMap(Type type)
|
|
static Class<?> |
loadClass(String className,
Class<?> caller)
|
|
static
|
newConstructorInstance(Constructor<T> constructor,
Object... initArgs)
|
|
static
|
newInstance(Class<T> clazz,
String message)
|
|
static boolean |
propertyExists(Class<?> clazz,
String property,
ElementType elementType)
Checks whether the property with the specified name and type exists on the given class. |
|
static void |
setAccessibility(Member member)
|
|
static Type |
typeOf(Member member)
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static ClassLoader getClassLoaderFromContext()
public static ClassLoader getClassLoaderFromClass(Class<?> clazz)
public static Class<?> loadClass(String className,
Class<?> caller)
public static <T> Constructor<T> getConstructor(Class<T> clazz,
Class<?>... params)
public static <T> T newInstance(Class<T> clazz,
String message)
public static <T> T newConstructorInstance(Constructor<T> constructor,
Object... initArgs)
public static <T> T getAnnotationParameter(Annotation annotation,
String parameterName,
Class<T> type)
public static String getPropertyName(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 propertyExists(Class<?> clazz,
String property,
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 Member getMember(Class<?> clazz,
String property,
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 Class<?> getType(Member member)
member - the member for which to get the type.
public static Type typeOf(Member member)
member - The Member instance for which to retrieve the type.
Type of the given Field or Method.
IllegalArgumentException - in case member is not a Field or Method.
public static Object getValue(Member member,
Object object)
public static void setAccessibility(Member member)
public static Type getIndexedType(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(Type type)
type - the type to check.
true if type is a iterable type, false otherwise.public static boolean isMap(Type type)
type - the type to check.
true if type is implementing Map, false otherwise.public static boolean isList(Type type)
type - the type to check.
true if type is implementing List, false otherwise.
public static Object getIndexedValue(Object value,
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 Object getMappedValue(Object value,
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 Field getField(Class<?> clazz,
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 containsField(Class<?> clazz,
String fieldName)
clazz - The class to check.fieldName - The field name.
true if the field exists, false otherwise.public static Field[] getFields(Class<?> clazz)
clazz - The class for which to retrieve the fields.
public static Method getMethodFromPropertyName(Class<?> clazz,
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(Class<?> clazz,
String property)
clazz - The class to check.property - The property name.
true if the method exists, false otherwise.
public static Method getMethod(Class<?> clazz,
String methodName)
null if it does not exist.
clazz - The class to check.methodName - The property name.
nullif it does not exist.public static Method[] getMethods(Class<?> clazz)
clazz - The class for which to retrieve the methods.
public static boolean containsMethod(Class<?> clazz,
String methodName)
clazz - The class to check.methodName - The method name.
true if the method exists, false otherwise.public static Class<?> boxedType(Type primitiveType)
primitiveType - the primitive type
IllegalArgumentException - in case the parameter primitiveType does not represent a primitive type.public static List<Class<?>> computeClassHierarchy(Class<?> clazz)
clazz - The class to start the search with.
clazz. The list contains the class itself! The empty
list is returned if clazz is null.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||