org.ckkloverdos.reflect
Class ReflectUtil

java.lang.Object
  extended by org.ckkloverdos.reflect.ReflectUtil

public final class ReflectUtil
extends java.lang.Object

Reflection-based utilities.

Author:
Christos KK Loverdos

Method Summary
static IReflectiveAccessor getAccesorForSelect(java.lang.Class c, java.lang.String propertyName, boolean isMethodCall)
           
static java.lang.reflect.Constructor getConstructor(java.lang.Class clazz, java.lang.Class[] types, int yesModifiers)
          Gets a Constructor without throwing any exceptions.
static java.lang.reflect.Constructor getConstructor(java.lang.Class clazz, java.lang.Class[] types, int yesMod, int noMod)
          Gets a Constructor without throwing any exceptions.
static java.lang.reflect.Field getField(java.lang.Class clazz, java.lang.String name)
          This is a wrapper around Class.getField(String), but with no exceptions thrown.
static java.lang.reflect.Method getMethod(java.lang.Class clazz, java.lang.String name, java.lang.Class[] types)
          This is a wrapper around Class.getMethod(String, Class[]) but with no exceptions thrown.
static java.lang.reflect.Method getMethodNoArgs(java.lang.Class clazz, java.lang.String name)
          Returns a method with the given name and no arguments of class clazz.
static IReflectiveAccessor getPropertyAccessor(java.lang.Class c, java.lang.String name)
          Obtains the accessor of javabean property.
static java.lang.Object newInstance(java.lang.Class clazz)
          Creates and returns a new instance for the class clazz.
static java.lang.Object newInstance(java.lang.String className)
          Creates and returns a new instance for the class with name className.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getPropertyAccessor

public static IReflectiveAccessor getPropertyAccessor(java.lang.Class c,
                                                      java.lang.String name)
Obtains the accessor of javabean property. First it will try to locate a getter method, then it will try to locate the field (property) itself.

Parameters:
c -
name -

getMethodNoArgs

public static java.lang.reflect.Method getMethodNoArgs(java.lang.Class clazz,
                                                       java.lang.String name)
Returns a method with the given name and no arguments of class clazz.

Parameters:
clazz -
name -

getMethod

public static java.lang.reflect.Method getMethod(java.lang.Class clazz,
                                                 java.lang.String name,
                                                 java.lang.Class[] types)
This is a wrapper around Class.getMethod(String, Class[]) but with no exceptions thrown.

Parameters:
clazz -
name -
types -
Returns:
the method with the given name and parameters or null if not found.

getField

public static java.lang.reflect.Field getField(java.lang.Class clazz,
                                               java.lang.String name)
This is a wrapper around Class.getField(String), but with no exceptions thrown.

Parameters:
clazz -
name -
Returns:
the field of class clazz with the given name or null if not found.

getConstructor

public static java.lang.reflect.Constructor getConstructor(java.lang.Class clazz,
                                                           java.lang.Class[] types,
                                                           int yesModifiers)
Gets a Constructor without throwing any exceptions.

Returns:
the Constructor object iff no exception is thrown by Class.getConstructor(Class[]) and the constructor has the requested modifiers.

getConstructor

public static java.lang.reflect.Constructor getConstructor(java.lang.Class clazz,
                                                           java.lang.Class[] types,
                                                           int yesMod,
                                                           int noMod)
Gets a Constructor without throwing any exceptions.

Returns:
the Constructor object iff no exception is thrown by Class.getConstructor(Class[]) and the constructor has the requested modifiers.

newInstance

public static java.lang.Object newInstance(java.lang.String className)
Creates and returns a new instance for the class with name className. It returns null if the instance cannot be created. No exceptions are thrown.

Parameters:
className -

newInstance

public static java.lang.Object newInstance(java.lang.Class clazz)
Creates and returns a new instance for the class clazz. It returns null if the instance cannot be created. No exceptions are thrown.

Parameters:
clazz -

getAccesorForSelect

public static IReflectiveAccessor getAccesorForSelect(java.lang.Class c,
                                                      java.lang.String propertyName,
                                                      boolean isMethodCall)


Copyright © 1999-2007 Christos KK Loverdos. All Rights Reserved.