org.loom.util
Class ClassUtils

java.lang.Object
  extended by org.loom.util.ClassUtils

public class ClassUtils
extends java.lang.Object

Yet Another ClassUtils implementation.


Constructor Summary
ClassUtils()
           
 
Method Summary
static java.lang.reflect.Method findMethod(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?>... arguments)
           
static java.lang.reflect.Method[] findMethods(java.lang.Class<?> clazz, java.lang.Class<?> returnType, java.lang.Class<?>... arguments)
           
static java.lang.reflect.Method[] findMethodsReturning(java.lang.Class<?> clazz, java.lang.Class<?> returnType)
           
static java.lang.Class<?> forName(java.lang.String className)
           
static java.lang.reflect.Field getField(java.lang.Class<?> clazz, java.lang.String fieldName)
           
static java.lang.Object getFieldValue(java.lang.Object container, java.lang.reflect.Field field)
          Gets a field value, but all the throwable exceptions are translated to Runtime
static java.lang.reflect.Method getGetter(java.lang.Class<?> clazz, java.lang.String property)
           
static java.lang.reflect.Method getMethod(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?>... types)
           
static java.beans.PropertyDescriptor getPropertyDescriptor(java.lang.Class<?> containerClass, java.lang.String propertyName)
           
static java.lang.String getPropertyName(java.lang.reflect.Method method)
          If the provided method is a getter or a setter, returns the lowercased property name, ex beanName for getBeanName
static java.lang.reflect.Method getSetter(java.lang.Class<?> clazz, java.lang.String property)
           
static java.lang.String getShortName(java.lang.Class<?> clazz)
          Deprecated. use Class.getSimpleName() instead
static java.lang.String getShortName(java.lang.reflect.Method method)
          Gets the short (unqualified) name of a Method, without the class name
static java.lang.String getSignature(java.lang.reflect.Method method, java.lang.Object[] args)
           
static java.lang.Object invoke(java.lang.Object container, java.lang.reflect.Method method, java.lang.Object... args)
          Invokes a method, but all the throwable exceptions are translated to Runtime
static boolean isAbstract(java.lang.Class<?> clazz)
           
static boolean isAssignable(java.lang.Class targetType, java.lang.Class valueType)
           
static boolean isPresent(java.lang.String className)
           
static
<T> T
newInstance(java.lang.Class<T> clazz)
           
static java.lang.Object newInstance(java.lang.String classname)
           
static void setFieldValue(java.lang.Object container, java.lang.reflect.Field field, java.lang.Object value)
          Sets a field value, but all the throwable exceptions are translated to Runtime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassUtils

public ClassUtils()
Method Detail

getShortName

public static java.lang.String getShortName(java.lang.Class<?> clazz)
Deprecated. use Class.getSimpleName() instead

Gets the short (unqualified) name of a Class


getShortName

public static java.lang.String getShortName(java.lang.reflect.Method method)
Gets the short (unqualified) name of a Method, without the class name


newInstance

public static <T> T newInstance(java.lang.Class<T> clazz)
Returns:
new instance of type clazz

newInstance

public static java.lang.Object newInstance(java.lang.String classname)

invoke

public static java.lang.Object invoke(java.lang.Object container,
                                      java.lang.reflect.Method method,
                                      java.lang.Object... args)
Invokes a method, but all the throwable exceptions are translated to Runtime


getSignature

public static java.lang.String getSignature(java.lang.reflect.Method method,
                                            java.lang.Object[] args)
Returns:
the signature of a given method with the given params

setFieldValue

public static void setFieldValue(java.lang.Object container,
                                 java.lang.reflect.Field field,
                                 java.lang.Object value)
Sets a field value, but all the throwable exceptions are translated to Runtime


getFieldValue

public static java.lang.Object getFieldValue(java.lang.Object container,
                                             java.lang.reflect.Field field)
Gets a field value, but all the throwable exceptions are translated to Runtime


getPropertyDescriptor

public static java.beans.PropertyDescriptor getPropertyDescriptor(java.lang.Class<?> containerClass,
                                                                  java.lang.String propertyName)
Returns:
the introspection PropertyDescriptor object for the required property, null if there is none

getGetter

public static java.lang.reflect.Method getGetter(java.lang.Class<?> clazz,
                                                 java.lang.String property)
Returns:
the method of class clazz that is getter for property, null if none

getSetter

public static java.lang.reflect.Method getSetter(java.lang.Class<?> clazz,
                                                 java.lang.String property)
Returns:
the method of class clazz that is setter for property, null if none

getField

public static java.lang.reflect.Field getField(java.lang.Class<?> clazz,
                                               java.lang.String fieldName)
Returns:
the required field, null if none. Looks in the parent classes. Searches also private Fields.

getMethod

public static java.lang.reflect.Method getMethod(java.lang.Class<?> clazz,
                                                 java.lang.String methodName,
                                                 java.lang.Class<?>... types)
Returns:
the required method, null if none. Looks in the parent classes

findMethod

public static java.lang.reflect.Method findMethod(java.lang.Class<?> clazz,
                                                  java.lang.String methodName,
                                                  java.lang.Class<?>... arguments)
Returns:
a reasonable guess for the required method with these arguments

findMethodsReturning

public static java.lang.reflect.Method[] findMethodsReturning(java.lang.Class<?> clazz,
                                                              java.lang.Class<?> returnType)
Returns:
a list of all methods that comply with a certain signature, ordered from Child to parent

findMethods

public static java.lang.reflect.Method[] findMethods(java.lang.Class<?> clazz,
                                                     java.lang.Class<?> returnType,
                                                     java.lang.Class<?>... arguments)
Returns:
a list of all methods that comply with a certain signature, ordered from Child to parent

isAssignable

public static boolean isAssignable(java.lang.Class targetType,
                                   java.lang.Class valueType)

isAbstract

public static boolean isAbstract(java.lang.Class<?> clazz)
Returns:
true if the class can be instantiated (is not abstract or interface)

forName

public static java.lang.Class<?> forName(java.lang.String className)

getPropertyName

public static java.lang.String getPropertyName(java.lang.reflect.Method method)
If the provided method is a getter or a setter, returns the lowercased property name, ex beanName for getBeanName

Parameters:
method -
Returns:
the property name, null if the method is not a getter or setter

isPresent

public static boolean isPresent(java.lang.String className)
Returns:
true if the provided classname is in the classpath