org.vraptor.reflection
Class ReflectionUtil

java.lang.Object
  extended by org.vraptor.reflection.ReflectionUtil

public class ReflectionUtil
extends Object

Wrapper class to deal with some reflection. TODO: this is too much procedural work, should change to an instance. Take care of synchronization issues.

Author:
Guilherme Silveira, Paulo Silveira

Constructor Summary
ReflectionUtil()
           
 
Method Summary
static
<T extends Annotation>
T
findAnnotation(Annotation[] annotations, Class<T> clazz)
          Tries to find an specific annotation inside an array
static Method findGetter(Class type, String property)
           
static Method findSetter(Object current, String property)
          Retrieves the setter method in an object for the specified property
static Object genericInstantiate(Class<?> type)
          Tries to instantiate an array of size 0 or type
static Object get(Object component, Field field)
           
static Field getField(Class containingType, String field)
           
static Map<String,Method> getGetters(Class clazz)
          Returns all getter (and iser) methods from the given class, excluding inherited ones, mapped by its property name.
static Method getPrefixedMethod(Class<?> clazz, String prefix, String name, Class... parameterTypes)
          Returns a prefixed method.
static
<T> T
instantiate(Class<T> clazz)
          Instantiates a class.
static Object instantiate(String clazz)
          Tries to instantiate this class
static Object instantiateCollection(Type type)
           
static Object invoke(Object object, Method method, Object... parameters)
          Wrapper for method invocation
static boolean isGetter(Method m)
           
static
<T> List<Outjecter>
loadOutjecters(Class<T> type)
           
static
<T extends Annotation>
List<FieldAnnotation<T>>
readAnnotations(Class type, Class<T> annot)
          Read all field annotations from one type
static void setField(Object component, Field field, Object value)
          Sets a field (must be accessible)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionUtil

public ReflectionUtil()
Method Detail

instantiate

public static <T> T instantiate(Class<T> clazz)
                     throws ComponentInstantiationException
Instantiates a class.

Returns:
the new object
Throws:
ComponentInstantiationException - if something wrong occurs

invoke

public static Object invoke(Object object,
                            Method method,
                            Object... parameters)
                     throws MethodInvocationException
Wrapper for method invocation

Parameters:
object - object
method - method
parameters - parameters
Returns:
the method's return
Throws:
MethodInvocationException

setField

public static void setField(Object component,
                            Field field,
                            Object value)
                     throws SettingException
Sets a field (must be accessible)

Parameters:
component - component
field - field
value - new value
Throws:
SettingException - unable to call setter

get

public static Object get(Object component,
                         Field field)
                  throws GettingException
Throws:
GettingException

findGetter

public static Method findGetter(Class type,
                                String property)
                         throws MethodInvocationException
Throws:
MethodInvocationException

findSetter

public static Method findSetter(Object current,
                                String property)
Retrieves the setter method in an object for the specified property

Parameters:
current - the current object
property - the setter to find
Returns:
the setter or null if not found

readAnnotations

public static <T extends Annotation> List<FieldAnnotation<T>> readAnnotations(Class type,
                                                                              Class<T> annot)
Read all field annotations from one type


genericInstantiate

public static Object genericInstantiate(Class<?> type)
                                 throws ComponentInstantiationException
Tries to instantiate an array of size 0 or type

Parameters:
type - type
Returns:
instantiates
Throws:
ComponentInstantiationException - problem instantiating it

instantiateCollection

public static Object instantiateCollection(Type type)
                                    throws ComponentInstantiationException
Throws:
ComponentInstantiationException

findAnnotation

public static <T extends Annotation> T findAnnotation(Annotation[] annotations,
                                                      Class<T> clazz)
Tries to find an specific annotation inside an array

Type Parameters:
T - the annotation type
Parameters:
annotations - the array
clazz - the annotation class to be found
Returns:
the annotation found or null if not found

instantiate

public static Object instantiate(String clazz)
                          throws ComponentInstantiationException
Tries to instantiate this class

Parameters:
class - the class to instantiate
Returns:
the instance
Throws:
ComponentInstantiationException

getPrefixedMethod

public static Method getPrefixedMethod(Class<?> clazz,
                                       String prefix,
                                       String name,
                                       Class... parameterTypes)
Returns a prefixed method.

Parameters:
clazz - the clazz where we are looking for a method
prefix - the method prefix
name - the suffix
Returns:
the found prefixed method
Throws:
MethodInvocationException - unsufficient rights to look for such method

getField

public static Field getField(Class containingType,
                             String field)
                      throws GettingException
Throws:
GettingException

getGetters

public static Map<String,Method> getGetters(Class clazz)
Returns all getter (and iser) methods from the given class, excluding inherited ones, mapped by its property name. Ignores any method simply called "get".
              name -> getName
              closed -> isClosed
 

Parameters:
clazz -
Returns:

isGetter

public static boolean isGetter(Method m)

loadOutjecters

public static <T> List<Outjecter> loadOutjecters(Class<T> type)


Copyright © 2004-2008 VRaptor. All Rights Reserved.