类 ReflectHelper
- java.lang.Object
-
- org.hibernate.internal.util.ReflectHelper
-
public final class ReflectHelper extends Object
Utility class for various reflection operations.- 作者:
- Gavin King, Steve Ebersole, Chris Cranford
-
-
字段概要
字段 修饰符和类型 字段 说明 static Class[]NO_PARAM_SIGNATUREstatic Object[]NO_PARAMSstatic Class[]SINGLE_OBJECT_PARAM_SIGNATURE
-
方法概要
所有方法 静态方法 具体方法 已过时的方法 修饰符和类型 方法 说明 static ClassclassForName(String name)已过时。Depending on context, eitherClassLoaderServiceorClassLoaderAccessshould be preferredstatic ClassclassForName(String name, Class caller)Perform resolution of a class name.static voidensureAccessibility(AccessibleObject accessibleObject)static MethodextractEqualsMethod(Class clazz)Encapsulation of getting hold of a class'sequalsmethod.static MethodextractHashCodeMethod(Class clazz)Encapsulation of getting hold of a class'shashCodemethod.static FieldfindField(Class containerClass, String propertyName)static MethodfindGetterMethod(Class containerClass, String propertyName)static MethodfindGetterMethodForFieldAccess(Field field, String propertyName)Similar togetterMethodOrNull(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 MethodfindSetterMethod(Class containerClass, String propertyName, Class propertyType)static ObjectgetConstantValue(String name, SessionFactoryImplementor factory)static ConstructorgetConstructor(Class clazz, Type[] types)Retrieve a constructor for the given class, with arguments matching the specified Hibernate mappingtypes.static <T> Constructor<T>getDefaultConstructor(Class<T> clazz)Retrieve the default (no arg) constructor from the given class.static MethodgetMethod(Class clazz, Method method)static MethodgetterMethodOrNull(Class containerJavaType, String propertyName)static booleanimplementsInterface(Class clazz, Class intf)Determine if the given class implements the given interface.static booleanisAbstractClass(Class clazz)Determine if the given class is declared abstract.static booleanisFinalClass(Class clazz)Determine is the given class is declared final.static booleanisPublic(Class clazz, Member member)Is this member publicly accessible.static booleanoverridesEquals(Class clazz)Determine if the given class defines anObject.equals(java.lang.Object)override.static booleanoverridesHashCode(Class clazz)Determine if the given class defines aObject.hashCode()override.static ClassreflectedPropertyClass(Class clazz, String name)Attempt to resolve the specified property type through reflection.static ClassreflectedPropertyClass(String className, String name, ClassLoaderService classLoaderService)Attempt to resolve the specified property type through reflection.static MethodsetterMethodOrNull(Class containerClass, String propertyName, Class propertyType)
-
-
-
方法详细资料
-
extractEqualsMethod
public static Method extractEqualsMethod(Class clazz) throws NoSuchMethodException
Encapsulation of getting hold of a class'sequalsmethod.- 参数:
clazz- The class from which to extract the equals method.- 返回:
- The equals method reference
- 抛出:
NoSuchMethodException- Should indicate an attempt to extract equals method from interface.
-
extractHashCodeMethod
public static Method extractHashCodeMethod(Class clazz) throws NoSuchMethodException
Encapsulation of getting hold of a class'shashCodemethod.- 参数:
clazz- The class from which to extract the hashCode method.- 返回:
- The hashCode method reference
- 抛出:
NoSuchMethodException- Should indicate an attempt to extract hashCode method from interface.
-
overridesEquals
public static boolean overridesEquals(Class clazz)
Determine if the given class defines anObject.equals(java.lang.Object)override.- 参数:
clazz- The class to check- 返回:
- True if clazz defines an equals override.
-
overridesHashCode
public static boolean overridesHashCode(Class clazz)
Determine if the given class defines aObject.hashCode()override.- 参数:
clazz- The class to check- 返回:
- True if clazz defines an hashCode override.
-
implementsInterface
public static boolean implementsInterface(Class clazz, Class intf)
Determine if the given class implements the given interface.- 参数:
clazz- The class to checkintf- The interface to check it against.- 返回:
- True if the class does implement the interface, false otherwise.
-
classForName
public static Class classForName(String name, Class caller) throws ClassNotFoundException
Perform resolution of a class name. Here we first check the context classloader, if one, before delegating toClass.forName(String, boolean, ClassLoader)using the caller's classloader- 参数:
name- The class namecaller- The class from which this call originated (in order to access that class's loader).- 返回:
- The class reference.
- 抛出:
ClassNotFoundException- FromClass.forName(String, boolean, ClassLoader).
-
classForName
@Deprecated public static Class classForName(String name) throws ClassNotFoundException
已过时。Depending on context, eitherClassLoaderServiceorClassLoaderAccessshould be preferredPerform resolution of a class name. Same asclassForName(String, Class)except that here we delegate toClass.forName(String)if the context classloader lookup is unsuccessful.- 参数:
name- The class name- 返回:
- The class reference.
- 抛出:
ClassNotFoundException- FromClass.forName(String).
-
isPublic
public static boolean isPublic(Class clazz, Member member)
Is this member publicly accessible.- 参数:
clazz- The class which defines the membermember- The member.- 返回:
- True if the member is publicly accessible, false otherwise.
-
reflectedPropertyClass
public static Class reflectedPropertyClass(String className, String name, ClassLoaderService classLoaderService) throws MappingException
Attempt to resolve the specified property type through reflection.- 参数:
className- The name of the class owning the property.name- The name of the property.classLoaderService- ClassLoader services- 返回:
- The type of the property.
- 抛出:
MappingException- Indicates we were unable to locate the property.
-
reflectedPropertyClass
public static Class reflectedPropertyClass(Class clazz, String name) throws MappingException
Attempt to resolve the specified property type through reflection.- 参数:
clazz- The class owning the property.name- The name of the property.- 返回:
- The type of the property.
- 抛出:
MappingException- Indicates we were unable to locate the property.
-
getConstantValue
public static Object getConstantValue(String name, SessionFactoryImplementor factory)
-
getDefaultConstructor
public static <T> Constructor<T> getDefaultConstructor(Class<T> clazz) throws PropertyNotFoundException
Retrieve the default (no arg) constructor from the given class.- 参数:
clazz- The class for which to retrieve the default ctor.- 返回:
- The default constructor.
- 抛出:
PropertyNotFoundException- Indicates there was not publicly accessible, no-arg constructor (todo : why PropertyNotFoundException???)
-
isAbstractClass
public static boolean isAbstractClass(Class clazz)
Determine if the given class is declared abstract.- 参数:
clazz- The class to check.- 返回:
- True if the class is abstract, false otherwise.
-
isFinalClass
public static boolean isFinalClass(Class clazz)
Determine is the given class is declared final.- 参数:
clazz- The class to check.- 返回:
- True if the class is final, false otherwise.
-
getConstructor
public static Constructor getConstructor(Class clazz, Type[] types) throws PropertyNotFoundException
Retrieve a constructor for the given class, with arguments matching the specified Hibernate mappingtypes.- 参数:
clazz- The class needing instantiationtypes- The types representing the required ctor param signature- 返回:
- The matching constructor.
- 抛出:
PropertyNotFoundException- Indicates we could not locate an appropriate constructor (todo : again with PropertyNotFoundException???)
-
ensureAccessibility
public static void ensureAccessibility(AccessibleObject accessibleObject)
-
getterMethodOrNull
public static Method getterMethodOrNull(Class containerJavaType, String propertyName)
-
setterMethodOrNull
public static Method setterMethodOrNull(Class containerClass, String propertyName, Class propertyType)
-
findSetterMethod
public static Method findSetterMethod(Class containerClass, String propertyName, Class propertyType)
-
findGetterMethodForFieldAccess
public static Method findGetterMethodForFieldAccess(Field field, String propertyName)
Similar togetterMethodOrNull(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...
-
-