avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application BlockEntry.java BlockInvocationHandler.java
Date Fri, 11 Oct 2002 05:59:51 GMT
donaldp     2002/10/10 22:59:51

  Modified:    src/java/org/apache/avalon/phoenix/components/application
                        BlockEntry.java BlockInvocationHandler.java
  Removed:     src/java/org/apache/avalon/phoenix
                        AbstractChainedInvocable.java
  Log:
  Remove Interceptor stuff and place it in branch rather than in main trunk.
  
  Revision  Changes    Path
  1.22      +4 -8      jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/BlockEntry.java
  
  Index: BlockEntry.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/BlockEntry.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- BlockEntry.java	4 Oct 2002 00:33:25 -0000	1.21
  +++ BlockEntry.java	11 Oct 2002 05:59:51 -0000	1.22
  @@ -19,9 +19,7 @@
   class BlockEntry
   {
       private Object m_object;
  -
       private BlockMetaData m_blockMetaData;
  -
       private BlockInvocationHandler m_invocationHandler;
   
       public BlockEntry( final BlockMetaData blockMetaData )
  @@ -52,10 +50,8 @@
           if( null != object && ! getMetaData().isDisableProxy() )
           {
               final BlockInfo blockInfo = getMetaData().getBlockInfo();
  -            final ClassLoader classLoader = object.getClass().getClassLoader();
  -            final Class[] interfaces = getServiceClasses( classLoader, blockInfo.getServices()
);
  -            m_invocationHandler = new BlockInvocationHandler( classLoader, interfaces );
  -            m_invocationHandler.setObject( object );
  +            final Class[] interfaces = getServiceClasses( object, blockInfo.getServices()
);
  +            m_invocationHandler = new BlockInvocationHandler( object, interfaces );
           }
           m_object = object;
       }
  @@ -89,10 +85,10 @@
           m_object = null;
       }
   
  -    private Class[] getServiceClasses( final ClassLoader classLoader, 
  -                                       final ServiceDescriptor[] services )
  +    private Class[] getServiceClasses( final Object block, final ServiceDescriptor[] services
)
       {
           final Class[] classes = new Class[ services.length + 1 ];
  +        final ClassLoader classLoader = block.getClass().getClassLoader();
   
           for( int i = 0; i < services.length; i++ )
           {
  
  
  
  1.11      +44 -9     jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/BlockInvocationHandler.java
  
  Index: BlockInvocationHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/BlockInvocationHandler.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- BlockInvocationHandler.java	4 Oct 2002 00:37:41 -0000	1.10
  +++ BlockInvocationHandler.java	11 Oct 2002 05:59:51 -0000	1.11
  @@ -7,10 +7,11 @@
    */
   package org.apache.avalon.phoenix.components.application;
   
  +import java.lang.reflect.InvocationHandler;
  +import java.lang.reflect.InvocationTargetException;
  +import java.lang.reflect.Method;
   import java.lang.reflect.Proxy;
   
  -import org.apache.avalon.phoenix.AbstractChainedInvocable;
  -
   /**
    * This makes a dynamic proxy for an object.  The object can be represented
    * by one, some or all of it's interfaces.
  @@ -28,10 +29,10 @@
    * @author <a href="mailto:Paul_Hammant@yahoo.com">Paul Hammant</a>
    * @version CVS $Revision$ $Date$
    */
  -final class BlockInvocationHandler extends AbstractChainedInvocable
  +final class BlockInvocationHandler
  +    implements InvocationHandler
   {
       private transient Object m_object;
  -
       private transient Object m_proxy;
   
       /**
  @@ -40,10 +41,11 @@
        * @param object the underlying object
        * @param interfaces the interfaces to proxy
        */
  -    protected BlockInvocationHandler( final ClassLoader classLoader,
  -                                      final Class[] interfaces )
  +    protected BlockInvocationHandler( final Object object, final Class[] interfaces )
       {
  -        super();
  +        final ClassLoader classLoader = object.getClass().getClassLoader();
  +
  +        m_object = object;
           m_proxy = Proxy.newProxyInstance( classLoader, interfaces, this );
       }
   
  @@ -53,7 +55,7 @@
        */
       public void invalidate()
       {
  -        setObject( null );
  +        m_object = null;
           m_proxy = null;
       }
   
  @@ -65,5 +67,38 @@
       public Object getProxy()
       {
           return m_proxy;
  +    }
  +
  +    /**
  +     * Invoke the specified method on underlying object.
  +     * This is called by proxy object.
  +     *
  +     * @param proxy the proxy object
  +     * @param method the method invoked on proxy object
  +     * @param args the arguments supplied to method
  +     * @return the return value of method
  +     * @throws Throwable if an error occurs
  +     */
  +    public Object invoke( final Object proxy,
  +                          final Method method,
  +                          final Object[] args )
  +        throws Throwable
  +    {
  +        if( null != m_object )
  +        {
  +            try
  +            {
  +                return method.invoke( m_object, args );
  +            }
  +            catch( final InvocationTargetException ite )
  +            {
  +                throw ite.getTargetException();
  +            }
  +        }
  +        else
  +        {
  +            throw new IllegalStateException( "Using a stale object reference "
  +                                             + "to call a disposed Block." );
  +        }
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message