avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From leosu...@apache.org
Subject cvs commit: avalon-excalibur/component/src/java/org/apache/avalon/excalibur/component ComponentProxyGenerator.java
Date Thu, 01 May 2003 10:22:13 GMT
leosutic    2003/05/01 03:22:13

  Modified:    component/src/java/org/apache/avalon/excalibur/component
                        ComponentProxyGenerator.java
  Log:
  Added method for creating backwards-compatible proxies.
  
  Revision  Changes    Path
  1.5       +45 -0     avalon-excalibur/component/src/java/org/apache/avalon/excalibur/component/ComponentProxyGenerator.java
  
  Index: ComponentProxyGenerator.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/component/src/java/org/apache/avalon/excalibur/component/ComponentProxyGenerator.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ComponentProxyGenerator.java	25 Feb 2003 16:28:21 -0000	1.4
  +++ ComponentProxyGenerator.java	1 May 2003 10:22:13 -0000	1.5
  @@ -60,6 +60,9 @@
   import java.lang.reflect.Method;
   import java.lang.reflect.Proxy;
   
  +import java.util.HashSet;
  +import java.util.Set;
  +
   import org.apache.avalon.framework.component.Component;
   
   /**
  @@ -100,12 +103,54 @@
        */
       public Component getProxy( String role, Object service ) throws Exception
       {
  +        // Trim any trailing "/type" from the role name.
  +        if( role.indexOf( '/' ) != -1 )
  +        {
  +            role = role.substring( 0, role.indexOf( '/' ) );
  +        }
  +        
           Class serviceInterface = m_classLoader.loadClass( role );
   
           return (Component)Proxy.newProxyInstance( m_classLoader,
                                                     new Class[]{Component.class, serviceInterface},
                                                     new ComponentInvocationHandler( service
) );
       }
  +    
  +    /**
  +     * Get the component wrapped in a proxy. The proxy will implement all the
  +     * object's interfaces, for compatibility with, for example, the pool code.
  +     * The proxy is guaranteed to implement Component.
  +     */
  +    public Component getCompatibleProxy( Object service ) throws Exception 
  +    {
  +        Set interfaces = new HashSet();
  +        getAllInterfaces( service.getClass(), interfaces );
  +        
  +        interfaces.add( Component.class );
  +        
  +        Class[] proxyInterfaces = (Class[]) interfaces.toArray( new Class[0] );
  +        
  +        return (Component)Proxy.newProxyInstance( m_classLoader,
  +            proxyInterfaces,
  +            new ComponentInvocationHandler( service ) );
  +    }
  +    
  +    private void getAllInterfaces( Class clazz, Set interfaces ) throws Exception
  +    {
  +        if (clazz == null)
  +        {
  +            return;
  +        }
  +        
  +        Class[] objectInterfaces = clazz.getInterfaces();
  +        for( int i = 0; i < objectInterfaces.length; i++ )
  +        {
  +            interfaces.add( objectInterfaces[i] );
  +        }
  +        
  +        getAllInterfaces( clazz.getSuperclass(), interfaces );
  +    }
  +    
   
       /**
        * Internal class to handle the wrapping with Component
  
  
  

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


Mime
View raw message