public final class

ReflectHelper

extends Object
java.lang.Object
   ↳ org.hibernate.util.ReflectHelper

Class Overview

Utility class for various reflection operations.

Summary

Fields
public static final Object[] NO_PARAMS
public static final Class[] NO_PARAM_SIGNATURE
public static final Class[] SINGLE_OBJECT_PARAM_SIGNATURE
Public Methods
static Class classForName(String name, Class caller)
Perform resolution of a class name.
static Class classForName(String name)
Perform resolution of a class name.
static Method extractEqualsMethod(Class clazz)
Encapsulation of getting hold of a class's equals method.
static Method extractHashCodeMethod(Class clazz)
Encapsulation of getting hold of a class's hashCode method.
static Object getConstantValue(String name)
Resolve a constant to its actual value.
static Constructor getConstructor(Class clazz, Type[] types)
Retrieve a constructor for the given class, with arguments matching the specified Hibernate mapping types.
static Constructor getDefaultConstructor(Class clazz)
Retrieve the default (no arg) constructor from the given class.
static Getter getGetter(Class theClass, String name)
Directly retrieve the Getter reference via the BasicPropertyAccessor.
static Method getMethod(Class clazz, Method method)
static boolean implementsInterface(Class clazz, Class intf)
Determine if the given class implements the given interface.
static boolean isAbstractClass(Class clazz)
Determine if the given class is declared abstract.
static boolean isFinalClass(Class clazz)
Determine is the given class is declared final.
static boolean isPublic(Member member)
Is this member publicly accessible.
static boolean isPublic(Class clazz, Member member)
Is this member publicly accessible.
static boolean overridesEquals(Class clazz)
Determine if the given class defines an equals(Object) override.
static boolean overridesHashCode(Class clazz)
Determine if the given class defines a hashCode() override.
static Class reflectedPropertyClass(String className, String name)
Attempt to resolve the specified property type through reflection.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

public static final Object[] NO_PARAMS

public static final Class[] NO_PARAM_SIGNATURE

public static final Class[] SINGLE_OBJECT_PARAM_SIGNATURE

Public Methods

public static Class classForName (String name, Class caller)

Perform resolution of a class name.

Here we first check the context classloader, if one, before delegating to forName(String, boolean, ClassLoader) using the caller's classloader

Parameters
name The class name
caller The class from which this call originated (in order to access that class's loader).
Returns
  • The class reference.

public static Class classForName (String name)

Perform resolution of a class name.

Same as classForName(String, Class) except that here we delegate to forName(String) if the context classloader lookup is unsuccessful.

Parameters
name The class name
Returns
  • The class reference.

public static Method extractEqualsMethod (Class clazz)

Encapsulation of getting hold of a class's equals method.

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.

public static Method extractHashCodeMethod (Class clazz)

Encapsulation of getting hold of a class's hashCode method.

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.

public static Object getConstantValue (String name)

Resolve a constant to its actual value.

Parameters
name The name
Returns
  • The value

public static Constructor getConstructor (Class clazz, Type[] types)

Retrieve a constructor for the given class, with arguments matching the specified Hibernate mapping types.

Parameters
clazz The class needing instantiation
types 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???)

public static Constructor getDefaultConstructor (Class clazz)

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???)

public static Getter getGetter (Class theClass, String name)

Directly retrieve the Getter reference via the BasicPropertyAccessor.

Parameters
theClass The class owning the property
name The name of the property
Returns
  • The getter.
Throws
MappingException Indicates we were unable to locate the property.

public static Method getMethod (Class clazz, Method method)

public static boolean implementsInterface (Class clazz, Class intf)

Determine if the given class implements the given interface.

Parameters
clazz The class to check
intf The interface to check it against.
Returns
  • True if the class does implement the interface, false otherwise.

public static boolean isAbstractClass (Class clazz)

Determine if the given class is declared abstract.

Parameters
clazz The class to check.
Returns
  • True if the class is abstract, false otherwise.

public static boolean isFinalClass (Class clazz)

Determine is the given class is declared final.

Parameters
clazz The class to check.
Returns
  • True if the class is final, flase otherwise.

public static boolean isPublic (Member member)

Is this member publicly accessible.

Short-hand for isPublic(Class, Member) passing the member + getDeclaringClass()

Parameters
member The member to check
Returns
  • True if the member is publicly accessible.

public static boolean isPublic (Class clazz, Member member)

Is this member publicly accessible.

Parameters
clazz The class which defines the member
member The memeber.
Returns
  • True if the member is publicly accessible, false otherwise.

public static boolean overridesEquals (Class clazz)

Determine if the given class defines an equals(Object) override.

Parameters
clazz The class to check
Returns
  • True if clazz defines an equals override.

public static boolean overridesHashCode (Class clazz)

Determine if the given class defines a hashCode() override.

Parameters
clazz The class to check
Returns
  • True if clazz defines an hashCode override.

public static Class reflectedPropertyClass (String className, String name)

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.