org.springframework.expression.spel.support
Class ReflectionHelper

java.lang.Object
  extended by org.springframework.expression.spel.support.ReflectionHelper

public class ReflectionHelper
extends Object

Utility methods used by the reflection resolver code to discover the appropriae methods/constructors and fields that should be used in expressions.

Since:
3.0
Author:
Andy Clement, Juergen Hoeller

Nested Class Summary
static class ReflectionHelper.ArgsMatchKind
           
static class ReflectionHelper.ArgumentsMatchInfo
          An instance of ArgumentsMatchInfo describes what kind of match was achieved between two sets of arguments - the set that a method/constructor is expecting and the set that are being supplied at the point of invocation.
 
Constructor Summary
ReflectionHelper()
           
 
Method Summary
static ReflectionHelper.ArgumentsMatchInfo compareArguments(Class[] expectedArgTypes, Class[] suppliedArgTypes, TypeConverter typeConverter)
          Compare argument arrays and return information about whether they match.
static ReflectionHelper.ArgumentsMatchInfo compareArgumentsVarargs(Class[] expectedArgTypes, Class[] suppliedArgTypes, TypeConverter typeConverter)
          Compare argument arrays and return information about whether they match.
static void convertAllArguments(Class[] parameterTypes, boolean isVarargs, TypeConverter converter, Object[] arguments)
          Convert a supplied set of arguments into the requested types.
static void convertArguments(Class[] requiredParameterTypes, boolean isVarargs, TypeConverter converter, int[] argumentsRequiringConversion, Object[] arguments)
          Takes an input set of argument values and, following the positions specified in the int array, it converts them to the types specified as the required parameter types.
static Object[] setupArgumentsForVarargsInvocation(Class[] requiredParameterTypes, Object... args)
          Package up the arguments so that they correctly match what is expected in parameterTypes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionHelper

public ReflectionHelper()
Method Detail

compareArguments

public static ReflectionHelper.ArgumentsMatchInfo compareArguments(Class[] expectedArgTypes,
                                                                   Class[] suppliedArgTypes,
                                                                   TypeConverter typeConverter)
Compare argument arrays and return information about whether they match. A supplied type converter and conversionAllowed flag allow for matches to take into account that a type may be transformed into a different type by the converter.

Parameters:
expectedArgTypes - the array of types the method/constructor is expecting
suppliedArgTypes - the array of types that are being supplied at the point of invocation
typeConverter - a registered type converter
Returns:
a MatchInfo object indicating what kind of match it was or null if it was not a match

compareArgumentsVarargs

public static ReflectionHelper.ArgumentsMatchInfo compareArgumentsVarargs(Class[] expectedArgTypes,
                                                                          Class[] suppliedArgTypes,
                                                                          TypeConverter typeConverter)
Compare argument arrays and return information about whether they match. A supplied type converter and conversionAllowed flag allow for matches to take into account that a type may be transformed into a different type by the converter. This variant of compareArguments also allows for a varargs match.

Parameters:
expectedArgTypes - the array of types the method/constructor is expecting
suppliedArgTypes - the array of types that are being supplied at the point of invocation
typeConverter - a registered type converter
Returns:
a MatchInfo object indicating what kind of match it was or null if it was not a match

convertArguments

public static void convertArguments(Class[] requiredParameterTypes,
                                    boolean isVarargs,
                                    TypeConverter converter,
                                    int[] argumentsRequiringConversion,
                                    Object[] arguments)
                             throws EvaluationException
Takes an input set of argument values and, following the positions specified in the int array, it converts them to the types specified as the required parameter types. The arguments are converted 'in-place' in the input array.

Parameters:
requiredParameterTypes - the types that the caller would like to have
isVarargs - whether the requiredParameterTypes is a varargs list
converter - the type converter to use for attempting conversions
argumentsRequiringConversion - details which of the input arguments need conversion
arguments - the actual arguments that need conversion
Throws:
EvaluationException - if a problem occurs during conversion

convertAllArguments

public static void convertAllArguments(Class[] parameterTypes,
                                       boolean isVarargs,
                                       TypeConverter converter,
                                       Object[] arguments)
                                throws SpelEvaluationException
Convert a supplied set of arguments into the requested types. If the parameterTypes are related to a varargs method then the final entry in the parameterTypes array is going to be an array itself whose component type should be used as the conversion target for extraneous arguments. (For example, if the parameterTypes are {Integer, String[]} and the input arguments are {Integer, boolean, float} then both the boolean and float must be converted to strings). This method does not repackage the arguments into a form suitable for the varargs invocation

Parameters:
parameterTypes - the types to be converted to
isVarargs - whether parameterTypes relates to a varargs method
converter - the converter to use for type conversions
arguments - the arguments to convert to the requested parameter types
Throws:
SpelEvaluationException - if there is a problem with conversion

setupArgumentsForVarargsInvocation

public static Object[] setupArgumentsForVarargsInvocation(Class[] requiredParameterTypes,
                                                          Object... args)
Package up the arguments so that they correctly match what is expected in parameterTypes. For example, if parameterTypes is (int, String[]) because the second parameter was declared String... then if arguments is [1,"a","b"] then it must be repackaged as [1,new String[]{"a","b"}] in order to match the expected parameterTypes.

Parameters:
requiredParameterTypes - the types of the parameters for the invocation
args - the arguments to be setup ready for the invocation
Returns:
a repackaged array of arguments where any varargs setup has been done