public final class ReflectHelper
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.Class[] |
NO_PARAM_SIGNATURE |
static java.lang.Object[] |
NO_PARAMS |
static java.lang.Class[] |
SINGLE_OBJECT_PARAM_SIGNATURE |
Modifier and Type | Method and Description |
---|---|
static java.lang.Class |
classForName(java.lang.String name)
Deprecated.
Depending on context, either
ClassLoaderService
or ClassLoaderAccess should be preferred |
static java.lang.Class |
classForName(java.lang.String name,
java.lang.Class caller)
Perform resolution of a class name.
|
static java.lang.reflect.Method |
extractEqualsMethod(java.lang.Class clazz)
Encapsulation of getting hold of a class's
equals method. |
static java.lang.reflect.Method |
extractHashCodeMethod(java.lang.Class clazz)
Encapsulation of getting hold of a class's
hashCode method. |
static java.lang.reflect.Field |
findField(java.lang.Class containerClass,
java.lang.String propertyName) |
static java.lang.reflect.Method |
findGetterMethod(java.lang.Class containerClass,
java.lang.String propertyName) |
static java.lang.reflect.Method |
findGetterMethodForFieldAccess(java.lang.reflect.Field field,
java.lang.String propertyName)
Similar to
getterMethodOrNull(java.lang.Class, java.lang.String) , except that here we are just looking for the
corresponding getter for a field (defined as field access) if one exists. |
static java.lang.reflect.Method |
findSetterMethod(java.lang.Class containerClass,
java.lang.String propertyName,
java.lang.Class propertyType) |
static java.lang.Object |
getConstantValue(java.lang.String name,
SessionFactoryImplementor factory) |
static java.lang.reflect.Constructor |
getConstructor(java.lang.Class clazz,
Type[] types)
Retrieve a constructor for the given class, with arguments matching the specified Hibernate mapping
types . |
static <T> java.lang.reflect.Constructor<T> |
getDefaultConstructor(java.lang.Class<T> clazz)
Retrieve the default (no arg) constructor from the given class.
|
static java.lang.reflect.Method |
getMethod(java.lang.Class clazz,
java.lang.reflect.Method method) |
static java.lang.reflect.Method |
getterMethodOrNull(java.lang.Class containerJavaType,
java.lang.String propertyName) |
static boolean |
implementsInterface(java.lang.Class clazz,
java.lang.Class intf)
Determine if the given class implements the given interface.
|
static boolean |
isAbstractClass(java.lang.Class clazz)
Determine if the given class is declared abstract.
|
static boolean |
isFinalClass(java.lang.Class clazz)
Determine is the given class is declared final.
|
static boolean |
isPublic(java.lang.Class clazz,
java.lang.reflect.Member member)
Is this member publicly accessible.
|
static boolean |
overridesEquals(java.lang.Class clazz)
Determine if the given class defines an
Object.equals(java.lang.Object) override. |
static boolean |
overridesHashCode(java.lang.Class clazz)
Determine if the given class defines a
Object.hashCode() override. |
static java.lang.Class |
reflectedPropertyClass(java.lang.Class clazz,
java.lang.String name)
Attempt to resolve the specified property type through reflection.
|
static java.lang.Class |
reflectedPropertyClass(java.lang.String className,
java.lang.String name,
ClassLoaderService classLoaderService)
Attempt to resolve the specified property type through reflection.
|
static java.lang.reflect.Method |
setterMethodOrNull(java.lang.Class containerJavaType,
java.lang.String propertyName,
java.lang.Class propertyJavaType) |
public static final java.lang.Class[] NO_PARAM_SIGNATURE
public static final java.lang.Object[] NO_PARAMS
public static final java.lang.Class[] SINGLE_OBJECT_PARAM_SIGNATURE
public static java.lang.reflect.Method extractEqualsMethod(java.lang.Class clazz) throws java.lang.NoSuchMethodException
equals
method.clazz
- The class from which to extract the equals method.java.lang.NoSuchMethodException
- Should indicate an attempt to extract equals method from interface.public static java.lang.reflect.Method extractHashCodeMethod(java.lang.Class clazz) throws java.lang.NoSuchMethodException
hashCode
method.clazz
- The class from which to extract the hashCode method.java.lang.NoSuchMethodException
- Should indicate an attempt to extract hashCode method from interface.public static boolean overridesEquals(java.lang.Class clazz)
Object.equals(java.lang.Object)
override.clazz
- The class to checkpublic static boolean overridesHashCode(java.lang.Class clazz)
Object.hashCode()
override.clazz
- The class to checkpublic static boolean implementsInterface(java.lang.Class clazz, java.lang.Class intf)
clazz
- The class to checkintf
- The interface to check it against.public static java.lang.Class classForName(java.lang.String name, java.lang.Class caller) throws java.lang.ClassNotFoundException
Class.forName(String, boolean, ClassLoader)
using the caller's classloadername
- The class namecaller
- The class from which this call originated (in order to access that class's loader).java.lang.ClassNotFoundException
- From Class.forName(String, boolean, ClassLoader)
.@Deprecated public static java.lang.Class classForName(java.lang.String name) throws java.lang.ClassNotFoundException
ClassLoaderService
or ClassLoaderAccess
should be preferredclassForName(String, Class)
except that here we delegate to
Class.forName(String)
if the context classloader lookup is unsuccessful.name
- The class namejava.lang.ClassNotFoundException
- From Class.forName(String)
.public static boolean isPublic(java.lang.Class clazz, java.lang.reflect.Member member)
clazz
- The class which defines the membermember
- The memeber.public static java.lang.Class reflectedPropertyClass(java.lang.String className, java.lang.String name, ClassLoaderService classLoaderService) throws MappingException
className
- The name of the class owning the property.name
- The name of the property.classLoaderService
- ClassLoader servicesMappingException
- Indicates we were unable to locate the property.public static java.lang.Class reflectedPropertyClass(java.lang.Class clazz, java.lang.String name) throws MappingException
clazz
- The class owning the property.name
- The name of the property.MappingException
- Indicates we were unable to locate the property.public static java.lang.Object getConstantValue(java.lang.String name, SessionFactoryImplementor factory)
public static <T> java.lang.reflect.Constructor<T> getDefaultConstructor(java.lang.Class<T> clazz) throws PropertyNotFoundException
clazz
- The class for which to retrieve the default ctor.PropertyNotFoundException
- Indicates there was not publicly accessible, no-arg constructor (todo : why PropertyNotFoundException???)public static boolean isAbstractClass(java.lang.Class clazz)
clazz
- The class to check.public static boolean isFinalClass(java.lang.Class clazz)
clazz
- The class to check.public static java.lang.reflect.Constructor getConstructor(java.lang.Class clazz, Type[] types) throws PropertyNotFoundException
types
.clazz
- The class needing instantiationtypes
- The types representing the required ctor param signaturePropertyNotFoundException
- Indicates we could not locate an appropriate constructor (todo : again with PropertyNotFoundException???)public static java.lang.reflect.Method getMethod(java.lang.Class clazz, java.lang.reflect.Method method)
public static java.lang.reflect.Field findField(java.lang.Class containerClass, java.lang.String propertyName)
public static java.lang.reflect.Method findGetterMethod(java.lang.Class containerClass, java.lang.String propertyName)
public static java.lang.reflect.Method getterMethodOrNull(java.lang.Class containerJavaType, java.lang.String propertyName)
public static java.lang.reflect.Method setterMethodOrNull(java.lang.Class containerJavaType, java.lang.String propertyName, java.lang.Class propertyJavaType)
public static java.lang.reflect.Method findSetterMethod(java.lang.Class containerClass, java.lang.String propertyName, java.lang.Class propertyType)
public static java.lang.reflect.Method findGetterMethodForFieldAccess(java.lang.reflect.Field field, java.lang.String propertyName)
getterMethodOrNull(java.lang.Class, java.lang.String)
, except that here we are just looking for the
corresponding getter for a field (defined as field access) if one exists.
We do not look at supers, although conceivably the super could declare the method
as an abstract - but again, that is such an edge case...Copyright © 2001-2018 Red Hat, Inc. All Rights Reserved.