railo.runtime.reflection
Class Reflector

java.lang.Object
  extended by railo.runtime.reflection.Reflector

public final class Reflector
extends Object

Class to reflect on Objects and classes


Constructor Summary
Reflector()
           
 
Method Summary
static Object _convert(Object src, Class trgClass)
           
static Object callConstructor(Class clazz, Object[] args)
          call constructor of a class with matching arguments
static Object callConstructor(Class clazz, Object[] args, Object defaultValue)
           
static Object callGetter(Object obj, String prop)
          to invoke a getter Method of a Object
static Object callMethod(Object obj, Collection.Key methodName, Object[] args)
           
static Object callMethod(Object obj, String methodName, Object[] args)
          calls a Method of a Objct
static void callSetter(Object obj, String prop, Object value)
          to invoke a setter Method of a Object
static void callSetterEL(Object obj, String prop, Object value)
          do nothing when not exist
static Object callStaticMethod(Class clazz, String methodName, Object[] args)
          calls a Static Method on the given CLass
static boolean canConvert(Class from, Class to)
          check if given class "from" can be converted to class "to" without explicit casting
static Object convert(Object src, Class trgClass, RefInteger rating)
          convert Object from src to trg Type, if possible
static Class[] getClasses(Object[] objs)
          get all Classes from a Object Array
static ConstructorInstance getConstructorInstance(Class clazz, Object[] args)
          gets Constructor Instance matching given parameter
static ConstructorInstance getConstructorInstance(Class clazz, Object[] args, ConstructorInstance defaultValue)
           
static Method[] getDeclaredMethods(Class clazz)
          return all methods that are defined by the class itself (not extended)
static String getDspMethods(Class[] clazzArgs)
          creates a string list with class arguments in a displable form
static Object getField(Object obj, String prop)
          to get a visible Field of a object
static Object getField(Object obj, String prop, Object defaultValue)
           
static Field[] getFieldsIgnoreCase(Class clazz, String name)
          same like method getField from Class but ignore case from field name
static Field[] getFieldsIgnoreCase(Class clazz, String name, Field[] defaultValue)
           
static MethodInstance getGetter(Class clazz, String prop)
          to get a Getter Method of a Object
static MethodInstance getGetterEL(Class clazz, String prop)
          to get a Getter Method of a Object
static Method[] getGetters(Class clazz)
           
static MethodInstance getMethodInstance(Class clazz, String methodName, Object[] args)
          gets the MethodInstance matching given Parameter
static MethodInstance getMethodInstanceEL(Class clazz, Collection.Key methodName, Object[] args)
          gets the MethodInstance matching given Parameter
static Object getProperty(Object obj, String prop)
          to get a visible Propety (Field or Getter) of a object
static Object getProperty(Object obj, String prop, Object defaultValue)
          to get a visible Propety (Field or Getter) of a object
static String[] getPropertyKeys(Class clazz)
           
static MethodInstance getSetter(Object obj, String prop, Object value)
          to invoke a setter Method of a Object
static MethodInstance getSetter(Object obj, String prop, Object value, MethodInstance defaultValue)
          to invoke a setter Method of a Object
static MethodInstance getSetterEL(Object obj, String prop, Object value)
          Deprecated. use instead getSetter(Object obj, String prop,Object value, MethodInstance defaultValue)
static Method[] getSetters(Class clazz)
           
static boolean hasFieldIgnoreCase(Class clazz, String name)
           
static boolean hasPropertyIgnoreCase(Class clazz, String name)
           
static boolean isGetter(Method method)
           
static boolean isInstaneOf(Class src, Class trg)
          check if Class is instanceof a a other Class
static boolean isInstaneOf(Class src, String trgClassName)
          check if Class is instanceof a a other Class
static boolean isInstaneOf(String srcClassName, Class trg)
          check if Class is instanceof a a other Class
static boolean isInstaneOf(String srcClassName, String trgClassName)
          check if Class is instanceof a a other Class
static boolean isInstaneOfIgnoreCase(Class src, String trg)
           
static boolean isSetter(Method method)
           
static boolean like(Class src, Class trg)
          checks if src Class is "like" trg class
static String removeGetterPrefix(String name)
           
static boolean setField(Object obj, String prop, Object value)
          assign a value to a visible Field of a object
static void setProperty(Object obj, String prop, Object value)
          assign a value to a visible Property (Field or Setter) of a object
static void setPropertyEL(Object obj, String prop, Object value)
          assign a value to a visible Property (Field or Setter) of a object
static ExpressionException throwCall(Object obj, Collection.Key methodName, Object[] args)
           
static ExpressionException throwCall(Object obj, String methodName, Object[] args)
           
static Class toReferenceClass(Class c)
          convert a primitive class Type to a Reference Type (Example: int -> java.lang.Integer)
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Reflector

public Reflector()
Method Detail

isInstaneOf

public static boolean isInstaneOf(String srcClassName,
                                  Class trg)
check if Class is instanceof a a other Class

Parameters:
srcClassName - Class name to check
trg - is Class of?
Returns:
is Class Class of...

isInstaneOf

public static boolean isInstaneOf(String srcClassName,
                                  String trgClassName)
check if Class is instanceof a a other Class

Parameters:
srcClassName - Class name to check
trgClassName - is Class of?
Returns:
is Class Class of...

isInstaneOf

public static boolean isInstaneOf(Class src,
                                  String trgClassName)
check if Class is instanceof a a other Class

Parameters:
src - is Class of?
trgClassName - Class name to check
Returns:
is Class Class of...

isInstaneOfIgnoreCase

public static boolean isInstaneOfIgnoreCase(Class src,
                                            String trg)

isInstaneOf

public static boolean isInstaneOf(Class src,
                                  Class trg)
check if Class is instanceof a a other Class

Parameters:
src - Class to check
trg - is Class of?
Returns:
is Class Class of...

getClasses

public static Class[] getClasses(Object[] objs)
get all Classes from a Object Array

Parameters:
objs - Objects to get
Returns:
classes from Objects

toReferenceClass

public static Class toReferenceClass(Class c)
convert a primitive class Type to a Reference Type (Example: int -> java.lang.Integer)

Parameters:
c - Class to convert
Returns:
converted Class (if primitive)

getDspMethods

public static String getDspMethods(Class[] clazzArgs)
creates a string list with class arguments in a displable form

Parameters:
clazzArgs - arguments to display
Returns:
list

like

public static boolean like(Class src,
                           Class trg)
checks if src Class is "like" trg class

Parameters:
src - Source Class
trg - Target Class
Returns:
is similar

convert

public static Object convert(Object src,
                             Class trgClass,
                             RefInteger rating)
                      throws PageException
convert Object from src to trg Type, if possible

Parameters:
src - Object to convert
srcClass - Source Class
trgClass - Target Class
Returns:
converted Object
Throws:
PageException

_convert

public static Object _convert(Object src,
                              Class trgClass)
                       throws PageException
Throws:
PageException

getConstructorInstance

public static ConstructorInstance getConstructorInstance(Class clazz,
                                                         Object[] args)
                                                  throws NoSuchMethodException
gets Constructor Instance matching given parameter

Parameters:
clazz - Clazz to Invoke
args - Matching args
Returns:
Matching ConstructorInstance
Throws:
NoSuchMethodException
PageException

getConstructorInstance

public static ConstructorInstance getConstructorInstance(Class clazz,
                                                         Object[] args,
                                                         ConstructorInstance defaultValue)

getMethodInstanceEL

public static MethodInstance getMethodInstanceEL(Class clazz,
                                                 Collection.Key methodName,
                                                 Object[] args)
gets the MethodInstance matching given Parameter

Parameters:
clazz - Class Of the Method to get
methodName - Name of the Method to get
args - Arguments of the Method to get
Returns:
return Matching Method
Throws:

getMethodInstance

public static MethodInstance getMethodInstance(Class clazz,
                                               String methodName,
                                               Object[] args)
                                        throws NoSuchMethodException
gets the MethodInstance matching given Parameter

Parameters:
clazz - Class Of the Method to get
methodName - Name of the Method to get
args - Arguments of the Method to get
Returns:
return Matching Method
Throws:
NoSuchMethodException
PageException

getFieldsIgnoreCase

public static Field[] getFieldsIgnoreCase(Class clazz,
                                          String name)
                                   throws NoSuchFieldException
same like method getField from Class but ignore case from field name

Parameters:
clazz - class to search the field
name - name to search
Returns:
Matching Field
Throws:
NoSuchFieldException

getFieldsIgnoreCase

public static Field[] getFieldsIgnoreCase(Class clazz,
                                          String name,
                                          Field[] defaultValue)

getPropertyKeys

public static String[] getPropertyKeys(Class clazz)

hasPropertyIgnoreCase

public static boolean hasPropertyIgnoreCase(Class clazz,
                                            String name)

hasFieldIgnoreCase

public static boolean hasFieldIgnoreCase(Class clazz,
                                         String name)

callConstructor

public static Object callConstructor(Class clazz,
                                     Object[] args)
                              throws PageException
call constructor of a class with matching arguments

Parameters:
clazz - Class to get Instance
args - Arguments for the Class
Returns:
invoked Instance
Throws:
PageException

callConstructor

public static Object callConstructor(Class clazz,
                                     Object[] args,
                                     Object defaultValue)

callMethod

public static Object callMethod(Object obj,
                                String methodName,
                                Object[] args)
                         throws PageException
calls a Method of a Objct

Parameters:
obj - Object to call Method on it
methodName - Name of the Method to get
args - Arguments of the Method to get
Returns:
return return value of the called Method
Throws:
PageException

callMethod

public static Object callMethod(Object obj,
                                Collection.Key methodName,
                                Object[] args)
                         throws PageException
Throws:
PageException

throwCall

public static ExpressionException throwCall(Object obj,
                                            String methodName,
                                            Object[] args)

throwCall

public static ExpressionException throwCall(Object obj,
                                            Collection.Key methodName,
                                            Object[] args)

callStaticMethod

public static Object callStaticMethod(Class clazz,
                                      String methodName,
                                      Object[] args)
                               throws PageException
calls a Static Method on the given CLass

Parameters:
clazz - Class to call Method on it
methodName - Name of the Method to get
args - Arguments of the Method to get
Returns:
return return value of the called Method
Throws:
PageException

getGetter

public static MethodInstance getGetter(Class clazz,
                                       String prop)
                                throws PageException,
                                       NoSuchMethodException
to get a Getter Method of a Object

Parameters:
clazz - Class to invoke method from
prop - Name of the Method without get
Returns:
return Value of the getter Method
Throws:
NoSuchMethodException
PageException

getGetterEL

public static MethodInstance getGetterEL(Class clazz,
                                         String prop)
to get a Getter Method of a Object

Parameters:
clazz - Class to invoke method from
prop - Name of the Method without get
Returns:
return Value of the getter Method

callGetter

public static Object callGetter(Object obj,
                                String prop)
                         throws PageException
to invoke a getter Method of a Object

Parameters:
obj - Object to invoke method from
prop - Name of the Method without get
Returns:
return Value of the getter Method
Throws:
PageException

getSetter

public static MethodInstance getSetter(Object obj,
                                       String prop,
                                       Object value)
                                throws NoSuchMethodException
to invoke a setter Method of a Object

Parameters:
obj - Object to invoke method from
prop - Name of the Method without get
value - Value to set to the Method
Returns:
MethodInstance
Throws:
NoSuchMethodException
PageException

getSetterEL

public static MethodInstance getSetterEL(Object obj,
                                         String prop,
                                         Object value)
Deprecated. use instead getSetter(Object obj, String prop,Object value, MethodInstance defaultValue)

to invoke a setter Method of a Object

Parameters:
obj - Object to invoke method from
prop - Name of the Method without get
value - Value to set to the Method
Returns:
MethodInstance

getSetter

public static MethodInstance getSetter(Object obj,
                                       String prop,
                                       Object value,
                                       MethodInstance defaultValue)
to invoke a setter Method of a Object

Parameters:
obj - Object to invoke method from
prop - Name of the Method without get
value - Value to set to the Method
Returns:
MethodInstance

callSetter

public static void callSetter(Object obj,
                              String prop,
                              Object value)
                       throws PageException
to invoke a setter Method of a Object

Parameters:
obj - Object to invoke method from
prop - Name of the Method without get
value - Value to set to the Method
Throws:
PageException

callSetterEL

public static void callSetterEL(Object obj,
                                String prop,
                                Object value)
                         throws PageException
do nothing when not exist

Parameters:
obj -
prop -
value -
Throws:
PageException

getField

public static Object getField(Object obj,
                              String prop)
                       throws PageException
to get a visible Field of a object

Parameters:
obj - Object to invoke
prop - property to call
Returns:
property value
Throws:
PageException

getField

public static Object getField(Object obj,
                              String prop,
                              Object defaultValue)

setField

public static boolean setField(Object obj,
                               String prop,
                               Object value)
                        throws PageException
assign a value to a visible Field of a object

Parameters:
obj - Object to assign value to his property
prop - name of property
value - Value to assign
Throws:
PageException

getProperty

public static Object getProperty(Object obj,
                                 String prop)
                          throws PageException
to get a visible Propety (Field or Getter) of a object

Parameters:
obj - Object to invoke
prop - property to call
Returns:
property value
Throws:
PageException

getProperty

public static Object getProperty(Object obj,
                                 String prop,
                                 Object defaultValue)
to get a visible Propety (Field or Getter) of a object

Parameters:
obj - Object to invoke
prop - property to call
Returns:
property value

setProperty

public static void setProperty(Object obj,
                               String prop,
                               Object value)
                        throws PageException
assign a value to a visible Property (Field or Setter) of a object

Parameters:
obj - Object to assign value to his property
prop - name of property
value - Value to assign
Throws:
PageException

setPropertyEL

public static void setPropertyEL(Object obj,
                                 String prop,
                                 Object value)
assign a value to a visible Property (Field or Setter) of a object

Parameters:
obj - Object to assign value to his property
prop - name of property
value - Value to assign

isGetter

public static boolean isGetter(Method method)

isSetter

public static boolean isSetter(Method method)

getDeclaredMethods

public static Method[] getDeclaredMethods(Class clazz)
return all methods that are defined by the class itself (not extended)

Parameters:
clazz -
Returns:

getSetters

public static Method[] getSetters(Class clazz)

getGetters

public static Method[] getGetters(Class clazz)

canConvert

public static boolean canConvert(Class from,
                                 Class to)
check if given class "from" can be converted to class "to" without explicit casting

Parameters:
from - source class
to - target class
Returns:
is it possible to convert from "from" to "to"

removeGetterPrefix

public static String removeGetterPrefix(String name)


Copyright © 2012 Railo