org.peaseplate.internal.util
Class ReflectionUtils

java.lang.Object
  extended by org.peaseplate.internal.util.ReflectionUtils

public class ReflectionUtils
extends java.lang.Object


Constructor Summary
ReflectionUtils()
           
 
Method Summary
static java.lang.Object[] callParameterCommands(BuildContext context, ICommand[] parameterCommands, java.lang.reflect.Method method, java.lang.Object... initialParameters)
          Calls the specified parameter commands and converts them to the specified parameter types and returns them as array.
static java.lang.reflect.Method findMethod(java.lang.Class<?> clazz, java.lang.String name, int numberOfParameters)
          Searches the specified class for a method with the specified name.
static java.lang.String formatMethodName(java.lang.Class<?> clazz, java.lang.Object name, int numberOfParameters)
           
static java.lang.Class<?> getClass(java.lang.Object value)
          Returns the class of the value.
static java.lang.reflect.Method scanMethods(java.lang.Class<?> clazz, java.lang.String name, int numberOfParameters)
          Scans the specified class for the method with the specified name.
static java.lang.reflect.Method scanMethods(java.lang.reflect.Method[] methods, java.lang.String name, int numberOfParameters)
          Scans the specified class for the method with the specified name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionUtils

public ReflectionUtils()
Method Detail

getClass

public static java.lang.Class<?> getClass(java.lang.Object value)
Returns the class of the value. If the value is null, it returns the Void class

Parameters:
value - the value
Returns:
the class, never null

findMethod

public static java.lang.reflect.Method findMethod(java.lang.Class<?> clazz,
                                                  java.lang.String name,
                                                  int numberOfParameters)
                                           throws ReflectionException
Searches the specified class for a method with the specified name. If there is no method with the exact name, it tries to find a method that starts with "get" or "is" and the name.

Parameters:
clazz - the class
name - the name
the - number of parameters the method must have
Returns:
the method or null if not found
Throws:
ReflectionException - if there are multiple methods with the same name

scanMethods

public static java.lang.reflect.Method scanMethods(java.lang.Class<?> clazz,
                                                   java.lang.String name,
                                                   int numberOfParameters)
                                            throws ReflectionException
Scans the specified class for the method with the specified name.

Parameters:
clazz - the class
name - the name
the - number of parameters the method must have (at least)
Returns:
the method or null if not found
Throws:
ReflectionException - if there are multiple method with the same name

scanMethods

public static java.lang.reflect.Method scanMethods(java.lang.reflect.Method[] methods,
                                                   java.lang.String name,
                                                   int numberOfParameters)
                                            throws ReflectionException
Scans the specified class for the method with the specified name.

Parameters:
methods - the methods to be scanned
name - the name
the - number of parameters the method must have (at least)
Returns:
the method or null if not found
Throws:
ReflectionException - if there are multiple method with the same name

callParameterCommands

public static java.lang.Object[] callParameterCommands(BuildContext context,
                                                       ICommand[] parameterCommands,
                                                       java.lang.reflect.Method method,
                                                       java.lang.Object... initialParameters)
                                                throws TemplateRuntimeException,
                                                       ReflectionException
Calls the specified parameter commands and converts them to the specified parameter types and returns them as array. The method is capable of varargs as parameter type. The resulting object array has the same length as the parameter types array. If the parameter commands array is shorter than the parameter types array, the remaining values will be set to null. If there are any initial parameters set, the resulting array will contain these parameters eventually converted. After them the parameter commands are following. Uses the conversion service to convert the parameters to the correct types.

Parameters:
context - the build context
parameterCommands - the parameter commands, may be null
parameterTypes - the parameter types
allowVarArgs - true if the parameter types contain a varargs as last parameter
initialParameters - if set, these will be converted and inserted in the result prior to the parameter command results.
Returns:
a somehow filled array
Throws:
TemplateRuntimeException - on occasion
ReflectionException

formatMethodName

public static java.lang.String formatMethodName(java.lang.Class<?> clazz,
                                                java.lang.Object name,
                                                int numberOfParameters)


Copyright © 2008. All Rights Reserved.