Package org.hibernate.util
Class ReflectHelper
java.lang.Object
org.hibernate.util.ReflectHelper
Utility class for various reflection operations.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic ClassclassForName(String name) Perform resolution of a class name.static ClassclassForName(String name, Class caller) Perform resolution of a class name.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 ObjectgetConstantValue(String name) Resolve a constant to its actual value.static ConstructorgetConstructor(Class clazz, Type[] types) Retrieve a constructor for the given class, with arguments matching the specified Hibernate mappingtypes.static ConstructorgetDefaultConstructor(Class clazz) Retrieve the default (no arg) constructor from the given class.static GetterDirectly retrieve theGetterreference via theBasicPropertyAccessor.static Methodstatic 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 booleanIs this member publicly accessible.static booleanIs 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(String className, String name) Attempt to resolve the specified property type through reflection.
-
Field Details
-
NO_PARAM_SIGNATURE
-
NO_PARAMS
-
SINGLE_OBJECT_PARAM_SIGNATURE
-
-
Method Details
-
extractEqualsMethod
Encapsulation of getting hold of a class'sequalsmethod.- Parameters:
clazz- The class from which to extract the equals method.- Returns:
- The equals method reference
- Throws:
NoSuchMethodException- Should indicate an attempt to extract equals method from interface.
-
extractHashCodeMethod
Encapsulation of getting hold of a class'shashCodemethod.- Parameters:
clazz- The class from which to extract the hashCode method.- Returns:
- The hashCode method reference
- Throws:
NoSuchMethodException- Should indicate an attempt to extract hashCode method from interface.
-
overridesEquals
Determine if the given class defines anObject.equals(java.lang.Object)override.- Parameters:
clazz- The class to check- Returns:
- True if clazz defines an equals override.
-
overridesHashCode
Determine if the given class defines aObject.hashCode()override.- Parameters:
clazz- The class to check- Returns:
- True if clazz defines an hashCode override.
-
implementsInterface
Determine if the given class implements the given interface.- Parameters:
clazz- The class to checkintf- The interface to check it against.- Returns:
- True if the class does implement the interface, false otherwise.
-
classForName
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- Parameters:
name- The class namecaller- The class from which this call originated (in order to access that class's loader).- Returns:
- The class reference.
- Throws:
ClassNotFoundException- FromClass.forName(String, boolean, ClassLoader).
-
classForName
Perform resolution of a class name. Same asclassForName(String, Class)except that here we delegate toClass.forName(String)if the context classloader lookup is unsuccessful.- Parameters:
name- The class name- Returns:
- The class reference.
- Throws:
ClassNotFoundException- FromClass.forName(String).
-
isPublic
Is this member publicly accessible. Short-hand forisPublic(Class, Member)passing the member +Member.getDeclaringClass()- Parameters:
member- The member to check- Returns:
- True if the member is publicly accessible.
-
isPublic
Is this member publicly accessible.- Parameters:
clazz- The class which defines the membermember- The memeber.- Returns:
- True if the member is publicly accessible, false otherwise.
-
reflectedPropertyClass
Attempt to resolve the specified property type through reflection.- Parameters:
className- The name of the class owning the property.name- The name of the property.- Returns:
- The type of the property.
- Throws:
MappingException- Indicates we were unable to locate the property.
-
getGetter
Directly retrieve theGetterreference via theBasicPropertyAccessor.- Parameters:
theClass- The class owning the propertyname- The name of the property- Returns:
- The getter.
- Throws:
MappingException- Indicates we were unable to locate the property.
-
getConstantValue
Resolve a constant to its actual value.- Parameters:
name- The name- Returns:
- The value
-
getDefaultConstructor
Retrieve the default (no arg) constructor from the given class.- Parameters:
clazz- The class for which to retrieve the default ctor.- Returns:
- The default constructor.
- Throws:
PropertyNotFoundException- Indicates there was not publicly accessible, no-arg constructor (todo : why PropertyNotFoundException???)
-
isAbstractClass
Determine if the given class is declared abstract.- Parameters:
clazz- The class to check.- Returns:
- True if the class is abstract, false otherwise.
-
isFinalClass
Determine is the given class is declared final.- Parameters:
clazz- The class to check.- Returns:
- True if the class is final, flase 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.- Parameters:
clazz- The class needing instantiationtypes- The types representing the required ctor param signature- Returns:
- The matching constructor.
- Throws:
PropertyNotFoundException- Indicates we could not locate an appropriate constructor (todo : again with PropertyNotFoundException???)
-
getMethod
-