|
|||||||||
| Home >> All >> org >> apache >> commons >> [ beanutils overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.commons.beanutils
Class MethodUtils

java.lang.Objectorg.apache.commons.beanutils.MethodUtils
- public class MethodUtils
- extends java.lang.Object
Utility reflection methods focussed on methods in general rather than properties in particular.
Known Limitations
Accessing Public Methods In A Default Access Superclass
There is an issue when invoking public methods contained in a default access superclass.
Reflection locates these methods fine and correctly assigns them as public.
However, an IllegalAccessException is thrown if the method is invoked.
MethodUtils contains a workaround for this situation.
It will attempt to call setAccessible on this method.
If this call succeeds, then the method can be invoked as normal.
This call will only succeed when the application has sufficient security privilages.
If this call fails then a warning will be logged and the method may fail.
| Nested Class Summary | |
private static class |
MethodUtils.MethodDescriptor
Represents the key to looking up a Method by reflection. |
| Field Summary | |
private static java.util.WeakHashMap |
cache
Stores a cache of Methods against MethodDescriptors, in a WeakHashMap. |
private static java.lang.Class[] |
emptyClassArray
An empty class array |
private static java.lang.Object[] |
emptyObjectArray
An empty object array |
private static org.apache.commons.logging.Log |
log
All logging goes through this logger |
private static boolean |
loggedAccessibleWarning
Only log warning about accessibility work around once |
| Constructor Summary | |
MethodUtils()
|
|
| Method Summary | |
static java.lang.reflect.Method |
getAccessibleMethod(java.lang.Class clazz,
java.lang.String methodName,
java.lang.Class parameterType)
Return an accessible method (that is, one that can be invoked via reflection) with given name and a single parameter. |
static java.lang.reflect.Method |
getAccessibleMethod(java.lang.Class clazz,
java.lang.String methodName,
java.lang.Class[] parameterTypes)
Return an accessible method (that is, one that can be invoked via reflection) with given name and parameters. |
static java.lang.reflect.Method |
getAccessibleMethod(java.lang.reflect.Method method)
Return an accessible method (that is, one that can be invoked via reflection) that implements the specified Method. |
private static java.lang.reflect.Method |
getAccessibleMethodFromInterfaceNest(java.lang.Class clazz,
java.lang.String methodName,
java.lang.Class[] parameterTypes)
Return an accessible method (that is, one that can be invoked via reflection) that implements the specified method, by scanning through all implemented interfaces and subinterfaces. |
static java.lang.reflect.Method |
getMatchingAccessibleMethod(java.lang.Class clazz,
java.lang.String methodName,
java.lang.Class[] parameterTypes)
Find an accessible method that matches the given name and has compatible parameters. |
static java.lang.Class |
getPrimitiveType(java.lang.Class wrapperType)
Gets the class for the primitive type corresponding to the primitive wrapper class given. |
static java.lang.Class |
getPrimitiveWrapper(java.lang.Class primitiveType)
Gets the wrapper object class for the given primitive type class. |
static java.lang.Object |
invokeExactMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object arg)
Invoke a method whose parameter type matches exactly the object type. |
static java.lang.Object |
invokeExactMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object[] args)
Invoke a method whose parameter types match exactly the object types. |
static java.lang.Object |
invokeExactMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object[] args,
java.lang.Class[] parameterTypes)
Invoke a method whose parameter types match exactly the parameter types given. |
static java.lang.Object |
invokeMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object arg)
Invoke a named method whose parameter type matches the object type. |
static java.lang.Object |
invokeMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object[] args)
Invoke a named method whose parameter type matches the object type. |
static java.lang.Object |
invokeMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object[] args,
java.lang.Class[] parameterTypes)
Invoke a named method whose parameter type matches the object type. |
static boolean |
isAssignmentCompatible(java.lang.Class parameterType,
java.lang.Class parameterization)
Determine whether a type can be used as a parameter in a method invocation. |
static java.lang.Class |
toNonPrimitiveClass(java.lang.Class clazz)
Find a non primitive representation for given primitive class. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
log
private static org.apache.commons.logging.Log log
- All logging goes through this logger
loggedAccessibleWarning
private static boolean loggedAccessibleWarning
- Only log warning about accessibility work around once
emptyClassArray
private static final java.lang.Class[] emptyClassArray
- An empty class array
emptyObjectArray
private static final java.lang.Object[] emptyObjectArray
- An empty object array
cache
private static java.util.WeakHashMap cache
- Stores a cache of Methods against MethodDescriptors, in a WeakHashMap.
| Constructor Detail |
MethodUtils
public MethodUtils()
| Method Detail |
invokeMethod
public static java.lang.Object invokeMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object arg) throws java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
Invoke a named method whose parameter type matches the object type.
The behaviour of this method is less deterministic than
invokeExactMethod(java.lang.Object, java.lang.String, java.lang.Object)55 . It loops through all methods with names that match and then executes the first it finds with compatable parameters.This method supports calls to methods taking primitive parameters via passing in wrapping classes. So, for example, a
Booleanclass would match abooleanprimitive.This is a convenient wrapper for
invokeMethod(Object object,String methodName,Object [] args)55 .
invokeMethod
public static java.lang.Object invokeMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object[] args) throws java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
Invoke a named method whose parameter type matches the object type.
The behaviour of this method is less deterministic than
invokeExactMethod(Object object,String methodName,Object [] args)55 . It loops through all methods with names that match and then executes the first it finds with compatable parameters.This method supports calls to methods taking primitive parameters via passing in wrapping classes. So, for example, a
Booleanclass would match abooleanprimitive.This is a convenient wrapper for
invokeMethod(Object object,String methodName,Object [] args,Class[] parameterTypes)55 .
invokeMethod
public static java.lang.Object invokeMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object[] args, java.lang.Class[] parameterTypes) throws java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
Invoke a named method whose parameter type matches the object type.
The behaviour of this method is less deterministic than
invokeExactMethod(Object object,String methodName,Object [] args,Class[] parameterTypes)55 . It loops through all methods with names that match and then executes the first it finds with compatable parameters.This method supports calls to methods taking primitive parameters via passing in wrapping classes. So, for example, a
Booleanclass would match abooleanprimitive.
invokeExactMethod
public static java.lang.Object invokeExactMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object arg) throws java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
Invoke a method whose parameter type matches exactly the object type.
This is a convenient wrapper for
invokeExactMethod(Object object,String methodName,Object [] args)55 .
invokeExactMethod
public static java.lang.Object invokeExactMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object[] args) throws java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
Invoke a method whose parameter types match exactly the object types.
This uses reflection to invoke the method obtained from a call to
getAccessibleMethod(java.lang.Class, java.lang.String, java.lang.Class)55 .
invokeExactMethod
public static java.lang.Object invokeExactMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object[] args, java.lang.Class[] parameterTypes) throws java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
Invoke a method whose parameter types match exactly the parameter types given.
This uses reflection to invoke the method obtained from a call to
getAccessibleMethod(java.lang.Class, java.lang.String, java.lang.Class)55 .
getAccessibleMethod
public static java.lang.reflect.Method getAccessibleMethod(java.lang.Class clazz, java.lang.String methodName, java.lang.Class parameterType)
Return an accessible method (that is, one that can be invoked via reflection) with given name and a single parameter. If no such method can be found, return
null. Basically, a convenience wrapper that constructs aClassarray for you.
getAccessibleMethod
public static java.lang.reflect.Method getAccessibleMethod(java.lang.Class clazz, java.lang.String methodName, java.lang.Class[] parameterTypes)
Return an accessible method (that is, one that can be invoked via reflection) with given name and parameters. If no such method can be found, return
null. This is just a convenient wrapper forgetAccessibleMethod(Method method)55 .
getAccessibleMethod
public static java.lang.reflect.Method getAccessibleMethod(java.lang.reflect.Method method)
Return an accessible method (that is, one that can be invoked via reflection) that implements the specified Method. If no such method can be found, return
null.
getAccessibleMethodFromInterfaceNest
private static java.lang.reflect.Method getAccessibleMethodFromInterfaceNest(java.lang.Class clazz, java.lang.String methodName, java.lang.Class[] parameterTypes)
Return an accessible method (that is, one that can be invoked via reflection) that implements the specified method, by scanning through all implemented interfaces and subinterfaces. If no such method can be found, return
null.There isn't any good reason why this method must be private. It is because there doesn't seem any reason why other classes should call this rather than the higher level methods.
getMatchingAccessibleMethod
public static java.lang.reflect.Method getMatchingAccessibleMethod(java.lang.Class clazz, java.lang.String methodName, java.lang.Class[] parameterTypes)
Find an accessible method that matches the given name and has compatible parameters. Compatible parameters mean that every method parameter is assignable from the given parameters. In other words, it finds a method with the given name that will take the parameters given.
This method is slightly undeterminstic since it loops through methods names and return the first matching method.
This method is used by
invokeMethod(Object object,String methodName,Object [] args,Class[] parameterTypes)55 .This method can match primitive parameter by passing in wrapper classes. For example, a
Booleanwill match a primitivebooleanparameter.
isAssignmentCompatible
public static final boolean isAssignmentCompatible(java.lang.Class parameterType, java.lang.Class parameterization)
Determine whether a type can be used as a parameter in a method invocation. This method handles primitive conversions correctly.
In order words, it will match a
Booleanto aboolean, aLongto along, aFloatto afloat, aIntegerto aint, and aDoubleto adouble. Now logic widening matches are allowed. For example, aLongwill not match aint.
getPrimitiveWrapper
public static java.lang.Class getPrimitiveWrapper(java.lang.Class primitiveType)
- Gets the wrapper object class for the given primitive type class.
For example, passing
boolean.classreturnsBoolean.class
getPrimitiveType
public static java.lang.Class getPrimitiveType(java.lang.Class wrapperType)
- Gets the class for the primitive type corresponding to the primitive wrapper class given.
For example, an instance of
Boolean.classreturns aboolean.class.
toNonPrimitiveClass
public static java.lang.Class toNonPrimitiveClass(java.lang.Class clazz)
- Find a non primitive representation for given primitive class.
|
|||||||||
| Home >> All >> org >> apache >> commons >> [ beanutils overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.apache.commons.beanutils.MethodUtils