donaldp     01/12/05 13:28:55

  Modified:    src/java/org/apache/avalon/excalibur/proxy DynamicProxy.java
  Log:
  May I suggest the following small change to DynamicProxy? The goal of
  the change is to make the proxy really transparent. With the current
  code, the proxy object users will be getting an ugly agregate of
  
  UndeclaredThrowableException(InvocationTargetException(OriginalException))
  
  if the original method throws OriginalException (which is not an
  instance of RuntimeException).
  
  Submitted By: Gregory Steuck <[EMAIL PROTECTED]>
  
  Revision  Changes    Path
  1.4       +23 -15    
jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/proxy/DynamicProxy.java
  
  Index: DynamicProxy.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/proxy/DynamicProxy.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DynamicProxy.java 2001/11/19 12:08:48     1.3
  +++ DynamicProxy.java 2001/12/05 21:28:55     1.4
  @@ -7,27 +7,28 @@
    */
   package org.apache.avalon.excalibur.proxy;
   
  +import java.lang.reflect.InvocationHandler;
  +import java.lang.reflect.InvocationTargetException;
   import java.lang.reflect.Method;
   import java.lang.reflect.Proxy;
  -import java.lang.reflect.InvocationHandler;
   
   /**
  - * This makes a dynamic proxy for an object.  The object can be represented 
  + * This makes a dynamic proxy for an object.  The object can be represented
    * by one, some of all of it's interfaces.
    *
  - * Amongst other things, it's an anti hackinge measure.  Suitable armed code 
  - * could have case an interface for a thing back to it's impl and used 
methods 
  + * Amongst other things, it's an anti hackinge measure.  Suitable armed code
  + * could have case an interface for a thing back to it's impl and used 
methods
    * and properties that were not it's authors intention.  Reflection too 
allows
    * some powerful introspection things and some traversal even more things
    * including private member vars by a serialisation trick... hence the 
transient.
  - * 
  - * 
  + *
  + *
    * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
  - * @author <a href="mailto:[EMAIL PROTECTED]">Paul Hammant</a> 
  - * @version CVS $Revision: 1.3 $ $Date: 2001/11/19 12:08:48 $
  + * @author <a href="mailto:[EMAIL PROTECTED]">Paul Hammant</a>
  + * @version CVS $Revision: 1.4 $ $Date: 2001/12/05 21:28:55 $
    * @since 4.0b5
    */
  -public final class DynamicProxy 
  +public final class DynamicProxy
       implements InvocationHandler
   {
       private transient Object m_object;
  @@ -37,13 +38,13 @@
        *
        * @param object the underlying object
        */
  -    private DynamicProxy( final Object object ) 
  +    private DynamicProxy( final Object object )
       {
           m_object = object;
       }
   
       /**
  -     * Create a proxy object that has all of it's underlying 
  +     * Create a proxy object that has all of it's underlying
        * interfaces implemented by proxy.
        *
        * @param object the underling object to proxy
  @@ -78,11 +79,18 @@
        * @return the return value of method
        * @exception Throwable if an error occurs
        */
  -    public Object invoke( final Object proxy, 
  -                          final Method method, 
  -                          final Object[] args ) 
  +    public Object invoke( final Object proxy,
  +                          final Method method,
  +                          final Object[] args )
           throws Throwable
       {
  -        return method.invoke( m_object, args );
  +        try
  +        {
  +            return method.invoke( m_object, args );
  +        }
  +        catch( final InvocationTargetException ite )
  +        {
  +            throw ite.getTargetException();
  +        }
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to