rdonkin 2002/11/21 10:53:33 Modified: lang/src/java/org/apache/commons/lang/reflect MethodUtils.java lang/src/test/org/apache/commons/lang/reflect MethodUtilsTestCase.java Log: Converted invokeMethod to use ReflectionExceptions Revision Changes Path 1.7 +26 -27 jakarta-commons/lang/src/java/org/apache/commons/lang/reflect/MethodUtils.java Index: MethodUtils.java =================================================================== RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/reflect/MethodUtils.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- MethodUtils.java 20 Nov 2002 22:31:40 -0000 1.6 +++ MethodUtils.java 21 Nov 2002 18:53:32 -0000 1.7 @@ -204,11 +204,7 @@ * @param methodName get method with this name, must not be null * @param arg use this argument, must not be null * - * @throws NoSuchMethodException if there is no such accessible method - * @throws InvocationTargetException wraps an exception thrown by the - * method invoked - * @throws IllegalAccessException if the requested method is not accessible - * via reflection + * @throws ReflectionException if an error occurs during reflection * @throws IllegalArgumentException if any parameter is null */ public static Object invokeMethod( @@ -216,9 +212,7 @@ String methodName, Object arg) throws - NoSuchMethodException, - IllegalAccessException, - InvocationTargetException { + ReflectionException { if (objectToInvoke == null) { throw new IllegalArgumentException("The object to invoke must not be null"); @@ -248,11 +242,7 @@ * @param methodName get method with this name, must not be null * @param args use these arguments - treat null as empty array * - * @throws NoSuchMethodException if there is no such accessible method - * @throws InvocationTargetException wraps an exception thrown by the - * method invoked - * @throws IllegalAccessException if the requested method is not accessible - * via reflection + * @throws ReflectionException if an error occurs during reflection * @throws IllegalArgumentException if the objectToInvoke, methodName or any argument is null */ public static Object invokeMethod( @@ -260,9 +250,7 @@ String methodName, Object[] args) throws - NoSuchMethodException, - IllegalAccessException, - InvocationTargetException { + ReflectionException { if (objectToInvoke == null) { throw new IllegalArgumentException("The object to invoke must not be null"); @@ -298,11 +286,7 @@ * @param args use these arguments - treat null as empty array * @param parameterTypes match these parameters - treat null as empty array * - * @throws NoSuchMethodException if there is no such accessible method - * @throws InvocationTargetException wraps an exception thrown by the - * method invoked - * @throws IllegalAccessException if the requested method is not accessible - * via reflection + * @throws ReflectionException if an error occurs during reflection */ public static Object invokeMethod( Object object, @@ -310,9 +294,7 @@ Object[] args, Class[] parameterTypes) throws - NoSuchMethodException, - IllegalAccessException, - InvocationTargetException { + ReflectionException { if (parameterTypes == null) { parameterTypes = ArrayUtils.EMPTY_CLASS_ARRAY; @@ -326,9 +308,26 @@ methodName, parameterTypes); if (method == null) - throw new NoSuchMethodException("No such accessible method: " + + throw new ReflectionException("No such accessible method: " + methodName + "() on object: " + object.getClass().getName()); - return method.invoke(object, args); + + try { + + return method.invoke(object, args); + + } catch (IllegalAccessException ex) { + throw new ReflectionException( + ReflectionUtils.getThrowableText( + ex, "invoking method", object.getClass().getName(), parameterTypes, methodName) + , ex); + + } catch (InvocationTargetException ex) { + throw new ReflectionException( + ReflectionUtils.getThrowableText( + ex, "invoking method", object.getClass().getName(), parameterTypes, methodName) + , ex); + + } } /** 1.3 +1 -1 jakarta-commons/lang/src/test/org/apache/commons/lang/reflect/MethodUtilsTestCase.java Index: MethodUtilsTestCase.java =================================================================== RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/reflect/MethodUtilsTestCase.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MethodUtilsTestCase.java 18 Nov 2002 22:18:44 -0000 1.2 +++ MethodUtilsTestCase.java 21 Nov 2002 18:53:32 -0000 1.3 @@ -295,7 +295,7 @@ // should get here! fail("No exception thrown when no appropriate method exists"); - } catch (NoSuchMethodException e) { + } catch (ReflectionException e) { // this is what we're expecting! }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>