com.finalist.tools.database
Class MethodInvoker

java.lang.Object
  extended bycom.finalist.tools.database.MethodInvoker

public class MethodInvoker
extends java.lang.Object

Helper class used to reflectively call setters and getters of beans and determine the return type.

Version:
1.0
Author:
P.S.D.Reitsma, Finalist IT Group

Constructor Summary
MethodInvoker()
           
 
Method Summary
static java.lang.reflect.Method getBeanMethod(java.lang.Class beanClass, java.lang.String property, java.lang.String prefix)
          Returns the method of a bean using taking the property name and a prefix.
static java.util.ArrayList getGetterNames(java.lang.Object bean)
          Returns the names of all the getters of the tested bean
static java.lang.Object getProperty(java.lang.Object bean, java.lang.String property)
          Executes the getter method of a property of a bean.
static java.lang.String getReturnType(java.lang.Object bean, java.lang.String property)
          Returns the object classname of a property of a bean.
static boolean getterExists(java.lang.Object bean, java.lang.String property)
          Test a bean whether a certain getter exists for a property.
static void setProperty(java.lang.Object bean, java.lang.String property, java.lang.Object value)
          Executes the setter method of a property of a bean.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MethodInvoker

public MethodInvoker()
Method Detail

getBeanMethod

public static java.lang.reflect.Method getBeanMethod(java.lang.Class beanClass,
                                                     java.lang.String property,
                                                     java.lang.String prefix)
                                              throws java.lang.NoSuchMethodException
Returns the method of a bean using taking the property name and a prefix. It is used to find getters or setters (prefix="get" or "set") for a certain property. This method is not case sensitive. In case the method is not found in the current class, it recursively looks in superclasses until java.lang.Object is met.

Parameters:
beanClass - class of the bean object that owns the method
property - that is get or set by the method
prefix - String that is concatenated to the property
Returns:
the desired method
Throws:
java.lang.NoSuchMethodException - thrown when the method is not found

getGetterNames

public static java.util.ArrayList getGetterNames(java.lang.Object bean)
Returns the names of all the getters of the tested bean

Returns:
ArrayList containing the names

getProperty

public static java.lang.Object getProperty(java.lang.Object bean,
                                           java.lang.String property)
                                    throws java.lang.IllegalAccessException,
                                           java.lang.IllegalArgumentException,
                                           java.lang.reflect.InvocationTargetException,
                                           java.lang.NoSuchMethodException
Executes the getter method of a property of a bean.

Parameters:
bean - the bean of which the method should be called
property - the property that should be derived
Returns:
the value of the property
Throws:
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException

setProperty

public static void setProperty(java.lang.Object bean,
                               java.lang.String property,
                               java.lang.Object value)
                        throws java.lang.IllegalAccessException,
                               java.lang.IllegalArgumentException,
                               java.lang.reflect.InvocationTargetException,
                               java.lang.NoSuchMethodException
Executes the setter method of a property of a bean.

Parameters:
bean - the bean of which the method should be called
property - the property that is set
Throws:
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException

getReturnType

public static java.lang.String getReturnType(java.lang.Object bean,
                                             java.lang.String property)
                                      throws java.lang.IllegalArgumentException,
                                             java.lang.NoSuchMethodException
Returns the object classname of a property of a bean.

Parameters:
bean - the bean to be examined
property - the property of which the return type is returned
Throws:
java.lang.IllegalArgumentException
java.lang.NoSuchMethodException

getterExists

public static boolean getterExists(java.lang.Object bean,
                                   java.lang.String property)
Test a bean whether a certain getter exists for a property.

Parameters:
bean - the bean that should be tested
property - the property of which the return type is returned
Returns:
boolean


Copyright © 2003-2004 SourceForge. All Rights Reserved.