mcconnell    2003/08/27 16:57:37

  Modified:    merlin/activation/src/java/org/apache/avalon/activation/appliance/impl
                        DefaultBlock.java
  Log:
  Improve hanlding of java.lang.Object operations on proxy.
  
  Revision  Changes    Path
  1.9       +55 -6     
avalon-sandbox/merlin/activation/src/java/org/apache/avalon/activation/appliance/impl/DefaultBlock.java
  
  Index: DefaultBlock.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/merlin/activation/src/java/org/apache/avalon/activation/appliance/impl/DefaultBlock.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DefaultBlock.java 26 Aug 2003 22:45:24 -0000      1.8
  +++ DefaultBlock.java 27 Aug 2003 23:57:37 -0000      1.9
  @@ -198,7 +198,8 @@
   
           try
           {
  -            BlockInvocationHandler handler = new BlockInvocationHandler( this );
  +            Logger log = getLogger().getChildLogger( "proxy" );
  +            BlockInvocationHandler handler = new BlockInvocationHandler( log, this 
);
               Class[] classes = getInterfaceClasses();
               m_proxy = Proxy.newProxyInstance( 
                 m_model.getClassLoaderModel().getClassLoader(),
  @@ -948,7 +949,8 @@
       final class BlockInvocationHandler
           implements InvocationHandler
       {
  -        private DefaultBlock m_block;
  +        private final DefaultBlock m_block;
  +        private final Logger m_logger;
   
          /**
           * Create a proxy invocation handler.
  @@ -956,10 +958,12 @@
           * @param block the underlying block implementation
           * @exception if an invocation handler establishment error occurs
           */
  -        protected BlockInvocationHandler( final DefaultBlock block )
  +        protected BlockInvocationHandler( final Logger logger, final DefaultBlock 
block )
               throws Exception
           {
  +            if( block == null ) throw new NullPointerException( "block" );
               m_block = block;
  +            m_logger = logger;
           }
   
           /**
  @@ -977,6 +981,32 @@
                   final Object[] args )
                   throws Throwable
           {
  +            if( proxy == null ) throw new NullPointerException( "proxy" );
  +            if( method == null ) throw new NullPointerException( "method" );
  +
  +            //
  +            // if the invocation is against java.lang.Object then
  +            // delegate the operation to the block
  +            //
  +
  +            if( method.getDeclaringClass().equals( java.lang.Object.class ) )
  +            {
  +                m_logger.debug( "invocation: " +  method.getName() );
  +                m_logger.debug( "object invocation" );
  +                if( args == null ) 
  +                {
  +                    return method.invoke( m_block, new Object[0] );
  +                }
  +                else
  +                {
  +                    return method.invoke( m_block, args );
  +                }
  +            }
  +
  +            //
  +            // otherwise we are delegating to an implementation component
  +            //
  +
               try
               {
                   //
  @@ -989,16 +1019,26 @@
                   String path = service.getPath();
                   Appliance provider = 
                     (Appliance) m_block.resolveAppliance( path );
  +                m_logger.debug( 
  +                  "delegating: " +  method.getName() );
   
                   //
                   // resolve the service object from the appliance
                   // and delegate the invocation to that provider
                   //
   
  -                Object object = provider.resolve( this );
  +                Object object = null;
                   try
                   {
  -                    return method.invoke( object, args );
  +                    object = provider.resolve( this );
  +                    if( args == null ) 
  +                    {
  +                        return method.invoke( object, new Object[0] );
  +                    }
  +                    else
  +                    {
  +                        return method.invoke( object, args );
  +                    }
                   }
                   catch( Throwable e )
                   {
  @@ -1007,6 +1047,10 @@
                         + object.getClass();
                       throw new ApplianceException( error, e );
                   }
  +                finally
  +                {
  +                    if( object != null ) provider.release( this, object );
  +                }
               }
               catch( Throwable e )
               {
  @@ -1017,6 +1061,11 @@
                     + "' in appliance: " + m_block;
                   throw new ApplianceException( error, e );
               }
  +        }
  +
  +        public String toString()
  +        {
  +            return m_block.toString();
           }
       }
   }
  
  
  

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

Reply via email to