com.vaadin.util
Class ReflectTools

java.lang.Object
  extended by com.vaadin.util.ReflectTools
All Implemented Interfaces:
java.io.Serializable

public class ReflectTools
extends java.lang.Object
implements java.io.Serializable

An util class with helpers for reflection operations. Used internally by Vaadin and should not be used by application developers. Subject to change at any time.

Since:
6.2
See Also:
Serialized Form

Constructor Summary
ReflectTools()
           
 
Method Summary
static java.lang.reflect.Method findMethod(java.lang.Class<?> cls, java.lang.String methodName, java.lang.Class<?>... parameterTypes)
          Locates the method in the given class.
static java.lang.Object getJavaFieldValue(java.lang.Object object, java.lang.reflect.Field field)
          Returns the value of the java field.
static java.lang.Object getJavaFieldValue(java.lang.Object object, java.lang.reflect.Field field, java.lang.Class<?> propertyType)
          Returns the value of the java field that is assignable to the property type.
static void setJavaFieldValue(java.lang.Object object, java.lang.reflect.Field field, java.lang.Object value)
          Sets the value of a java field.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectTools

public ReflectTools()
Method Detail

findMethod

public static java.lang.reflect.Method findMethod(java.lang.Class<?> cls,
                                                  java.lang.String methodName,
                                                  java.lang.Class<?>... parameterTypes)
                                           throws java.lang.ExceptionInInitializerError
Locates the method in the given class. Returns null if the method is not found. Throws an ExceptionInInitializerError if there is a problem locating the method as this is mainly called from static blocks.

Parameters:
cls - Class that contains the method
methodName - The name of the method
parameterTypes - The parameter types for the method.
Returns:
A reference to the method
Throws:
java.lang.ExceptionInInitializerError - Wraps any exception in an ExceptionInInitializerError so this method can be called from a static initializer.

getJavaFieldValue

public static java.lang.Object getJavaFieldValue(java.lang.Object object,
                                                 java.lang.reflect.Field field)
                                          throws java.lang.IllegalArgumentException,
                                                 java.lang.IllegalAccessException,
                                                 java.lang.reflect.InvocationTargetException
Returns the value of the java field.

Uses getter if present, otherwise tries to access even private fields directly.

Parameters:
object - The object containing the field
field - The field we want to get the value for
Returns:
The value of the field in the object
Throws:
java.lang.reflect.InvocationTargetException - If the value could not be retrieved
java.lang.IllegalAccessException - If the value could not be retrieved
java.lang.IllegalArgumentException - If the value could not be retrieved

getJavaFieldValue

public static java.lang.Object getJavaFieldValue(java.lang.Object object,
                                                 java.lang.reflect.Field field,
                                                 java.lang.Class<?> propertyType)
                                          throws java.lang.IllegalArgumentException,
                                                 java.lang.IllegalAccessException,
                                                 java.lang.reflect.InvocationTargetException
Returns the value of the java field that is assignable to the property type.

Uses getter if a getter for the correct return type is present, otherwise tries to access even private fields directly. If the java field is not assignable to the property type throws an IllegalArgumentException.

Parameters:
object - The object containing the field
field - The field we want to get the value for
propertyType - The type the field must be assignable to
Returns:
The value of the field in the object
Throws:
java.lang.reflect.InvocationTargetException - If the value could not be retrieved
java.lang.IllegalAccessException - If the value could not be retrieved
java.lang.IllegalArgumentException - If the value could not be retrieved

setJavaFieldValue

public static void setJavaFieldValue(java.lang.Object object,
                                     java.lang.reflect.Field field,
                                     java.lang.Object value)
                              throws java.lang.IllegalAccessException,
                                     java.lang.IllegalArgumentException,
                                     java.lang.reflect.InvocationTargetException
Sets the value of a java field.

Uses setter if present, otherwise tries to access even private fields directly.

Parameters:
object - The object containing the field
field - The field we want to set the value for
value - The value to set
Throws:
java.lang.IllegalAccessException - If the value could not be assigned to the field
java.lang.IllegalArgumentException - If the value could not be assigned to the field
java.lang.reflect.InvocationTargetException - If the value could not be assigned to the field


Copyright © 2000-2014 Vaadin Ltd. All Rights Reserved.