jp.develop.common.util.amf.beans
Class ClassUtil

java.lang.Object
  extended by jp.develop.common.util.amf.beans.ClassUtil

public final class ClassUtil
extends Object

Utilities for class operation.

Author:
Waki Takeya

Method Summary
static Class<?> findClass(String name)
          Find class instance by class name.
static Class<?> getRawClass(Type type)
          Get Raw Class from Type.
static boolean isAssignable(Type fromType, Type toType)
          Is assignable? This method check not only Class.isAssignableFrom(), but also actual type arguments of parameterized type.
static
<T> T
newInstance(Class<T> clazz)
          Constructs a new instance.
static Type resolveActualFieldClass(Type parent, Field field)
          Resolve actual field class by field instance.
static Type resolveActualFieldType(Type parent, Field field)
          Resolve actual field type by field instance.
static Type resolveActualFieldType(Type parent, String fieldName)
          Resolve actual field type by name.
static Type resolveActualParameterClass(Type parent, Method method, int paramIndex)
          Resolve actual parameter class by method instance and parameter index.
static Type resolveActualParameterType(Type parent, Method method, int paramIndex)
          Resolve actual parameter type by method instance and parameter index.
static Type[] resolveActualParameterTypes(Type parent, Method method)
          Resolve actual parameter types by method instance.
static Type[] resolveActualParameterTypes(Type parent, String methodName, Class<?>... parameterClasses)
          Resolve actual parameter types by method name.
static Class<?> resolveActualReturnClass(Type parent, Method method)
          Resolve actual return class by method instance.
static Type resolveActualReturnType(Type parent, Method method)
          Resolve actual return type by method instance.
static Type resolveActualReturnType(Type parent, String methodName, Class<?>... parameterClasses)
          Resolve actual return type by method name.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

findClass

public static Class<?> findClass(String name)
Find class instance by class name.

Parameters:
name - The class name to find.
Returns:
Class instance of specified class name. It is null, failed to find.

newInstance

public static <T> T newInstance(Class<T> clazz)
Constructs a new instance.

Type Parameters:
T - Type of a instance.
Parameters:
clazz - The class to be instantiated.
Returns:
The instance of specified class. It is null, if instantiation is failed.

getRawClass

public static Class<?> getRawClass(Type type)
Get Raw Class from Type.

Parameters:
type - Target type.
Returns:
Raw class of type parameter.

isAssignable

public static boolean isAssignable(Type fromType,
                                   Type toType)
Is assignable? This method check not only Class.isAssignableFrom(), but also actual type arguments of parameterized type.

Parameters:
fromType - Type of assigning from.
toType - Type of assigning to.
Returns:
true, if it is assignable.

resolveActualFieldType

public static Type resolveActualFieldType(Type parent,
                                          String fieldName)
Resolve actual field type by name.

Parameters:
parent - Type of parent.
fieldName - The field name to be resolved.
Returns:
Actual type of specified field name.

resolveActualFieldType

public static Type resolveActualFieldType(Type parent,
                                          Field field)
Resolve actual field type by field instance.

Parameters:
parent - Type of parent.
field - The field to be resolved.
Returns:
Actual type of specified field.

resolveActualFieldClass

public static Type resolveActualFieldClass(Type parent,
                                           Field field)
Resolve actual field class by field instance.

Parameters:
parent - Type of parent.
field - The field to be resolved.
Returns:
Actual class of specified field.

resolveActualParameterTypes

public static Type[] resolveActualParameterTypes(Type parent,
                                                 String methodName,
                                                 Class<?>... parameterClasses)
Resolve actual parameter types by method name.

Parameters:
parent - Type of parent.
methodName - The method name to be resolved.
parameterClasses - The classes of the method parameter.
Returns:
Actual parameter types of specified method name.

resolveActualParameterTypes

public static Type[] resolveActualParameterTypes(Type parent,
                                                 Method method)
Resolve actual parameter types by method instance.

Parameters:
parent - Type of parent.
method - The method to be resolved.
Returns:
Actual parameter types of specified method.

resolveActualParameterType

public static Type resolveActualParameterType(Type parent,
                                              Method method,
                                              int paramIndex)
Resolve actual parameter type by method instance and parameter index.

Parameters:
parent - Type of parent.
method - The method to be resolved.
paramIndex - The index of target parameter.
Returns:
Actual parameter type of specified method and index.

resolveActualParameterClass

public static Type resolveActualParameterClass(Type parent,
                                               Method method,
                                               int paramIndex)
Resolve actual parameter class by method instance and parameter index.

Parameters:
parent - Type of parent.
method - The method to be resolved.
paramIndex - The index of target parameter.
Returns:
Actual parameter class of specified method and index.

resolveActualReturnType

public static Type resolveActualReturnType(Type parent,
                                           String methodName,
                                           Class<?>... parameterClasses)
Resolve actual return type by method name.

Parameters:
parent - Type of parent.
methodName - The method name to be resolved.
parameterClasses - The classes of the method parameter.
Returns:
Actual return type of specified method name.

resolveActualReturnType

public static Type resolveActualReturnType(Type parent,
                                           Method method)
Resolve actual return type by method instance.

Parameters:
parent - Type of parent.
method - The method to be resolved.
Returns:
Actual return type of specified method.

resolveActualReturnClass

public static Class<?> resolveActualReturnClass(Type parent,
                                                Method method)
Resolve actual return class by method instance.

Parameters:
parent - Type of parent.
method - The method to be resolved.
Returns:
Actual return class of specified method.