| Method from org.hibernate.util.ReflectHelper Detail: |
public static Class classForName(String name) throws ClassNotFoundException {
try {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
if ( contextClassLoader != null ) {
return contextClassLoader.loadClass(name);
}
}
catch ( Throwable ignore ) {
}
return Class.forName( name );
}
|
public static Class classForName(String name,
Class caller) throws ClassNotFoundException {
try {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
if ( contextClassLoader != null ) {
return contextClassLoader.loadClass( name );
}
}
catch ( Throwable ignore ) {
}
return Class.forName( name, true, caller.getClassLoader() );
}
|
public static Method extractEqualsMethod(Class clazz) throws NoSuchMethodException {
return clazz.getMethod( "equals", SINGLE_OBJECT_PARAM_SIGNATURE );
}
Encapsulation of getting hold of a class's equals method. |
public static Method extractHashCodeMethod(Class clazz) throws NoSuchMethodException {
return clazz.getMethod( "hashCode", NO_PARAM_SIGNATURE );
}
Encapsulation of getting hold of a class's hashCode method. |
public static Object getConstantValue(String name) {
Class clazz;
try {
clazz = classForName( StringHelper.qualifier( name ) );
}
catch ( Throwable t ) {
return null;
}
try {
return clazz.getField( StringHelper.unqualify( name ) ).get( null );
}
catch ( Throwable t ) {
return null;
}
}
Resolve a constant to its actual value. |
public static Constructor getConstructor(Class clazz,
Type[] types) throws PropertyNotFoundException {
final Constructor[] candidates = clazz.getConstructors();
for ( int i = 0; i < candidates.length; i++ ) {
final Constructor constructor = candidates[i];
final Class[] params = constructor.getParameterTypes();
if ( params.length == types.length ) {
boolean found = true;
for ( int j = 0; j < params.length; j++ ) {
final boolean ok = params[j].isAssignableFrom( types[j].getReturnedClass() ) || (
types[j] instanceof PrimitiveType &&
params[j] == ( ( PrimitiveType ) types[j] ).getPrimitiveClass()
);
if ( !ok ) {
found = false;
break;
}
}
if ( found ) {
if ( !isPublic( clazz, constructor ) ) {
constructor.setAccessible( true );
}
return constructor;
}
}
}
throw new PropertyNotFoundException( "no appropriate constructor in class: " + clazz.getName() );
}
Retrieve a constructor for the given class, with arguments matching the specified Hibernate mapping
types . |
public static Constructor getDefaultConstructor(Class clazz) throws PropertyNotFoundException {
if ( isAbstractClass( clazz ) ) {
return null;
}
try {
Constructor constructor = clazz.getDeclaredConstructor( NO_PARAM_SIGNATURE );
if ( !isPublic( clazz, constructor ) ) {
constructor.setAccessible( true );
}
return constructor;
}
catch ( NoSuchMethodException nme ) {
throw new PropertyNotFoundException(
"Object class [" + clazz.getName() + "] must declare a default (no-argument) constructor"
);
}
}
Retrieve the default (no arg) constructor from the given class. |
public static Getter getGetter(Class theClass,
String name) throws MappingException {
return BASIC_PROPERTY_ACCESSOR.getGetter( theClass, name );
}
|
public static Method getMethod(Class clazz,
Method method) {
try {
return clazz.getMethod( method.getName(), method.getParameterTypes() );
}
catch (Exception e) {
return null;
}
}
|
public static boolean implementsInterface(Class clazz,
Class intf) {
assert intf.isInterface() : "Interface to check was not an interface";
return intf.isAssignableFrom( clazz );
}
Determine if the given class implements the given interface. |
public static boolean isAbstractClass(Class clazz) {
int modifier = clazz.getModifiers();
return Modifier.isAbstract(modifier) || Modifier.isInterface(modifier);
}
Determine if the given class is declared abstract. |
public static boolean isFinalClass(Class clazz) {
return Modifier.isFinal( clazz.getModifiers() );
}
Determine is the given class is declared final. |
public static boolean isPublic(Member member) {
return isPublic( member.getDeclaringClass(), member );
}
|
public static boolean isPublic(Class clazz,
Member member) {
return Modifier.isPublic( member.getModifiers() ) && Modifier.isPublic( clazz.getModifiers() );
}
Is this member publicly accessible. |
public static boolean overridesEquals(Class clazz) {
Method equals;
try {
equals = extractEqualsMethod( clazz );
}
catch ( NoSuchMethodException nsme ) {
return false; //its an interface so we can't really tell anything...
}
return !OBJECT_EQUALS.equals( equals );
}
|
public static boolean overridesHashCode(Class clazz) {
Method hashCode;
try {
hashCode = extractHashCodeMethod( clazz );
}
catch ( NoSuchMethodException nsme ) {
return false; //its an interface so we can't really tell anything...
}
return !OBJECT_HASHCODE.equals( hashCode );
}
|
public static Class reflectedPropertyClass(String className,
String name) throws MappingException {
try {
Class clazz = ReflectHelper.classForName( className );
return getter( clazz, name ).getReturnType();
}
catch ( ClassNotFoundException cnfe ) {
throw new MappingException( "class " + className + " not found while looking for property: " + name, cnfe );
}
}
Attempt to resolve the specified property type through reflection. |