commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang/reflect MethodUtilsTestCase.java
Date Thu, 21 Nov 2002 18:53:33 GMT
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:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message