commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject svn commit: r278949 - in /jakarta/commons/sandbox/proxy/trunk/src: java/org/apache/commons/proxy/factory/util/AbstractProxyClassGenerator.java test/org/apache/commons/proxy/factory/AbstractSubclassingProxyFactoryTestCase.java
Date Tue, 06 Sep 2005 09:14:28 GMT
Author: knut
Date: Tue Sep  6 02:14:17 2005
New Revision: 278949

URL: http://svn.apache.org/viewcvs?rev=278949&view=rev
Log:
- assert that clashing final and non-final methods are not overridden by the proxy

Modified:
    jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/util/AbstractProxyClassGenerator.java
    jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/AbstractSubclassingProxyFactoryTestCase.java

Modified: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/util/AbstractProxyClassGenerator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/util/AbstractProxyClassGenerator.java?rev=278949&r1=278948&r2=278949&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/util/AbstractProxyClassGenerator.java
(original)
+++ jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/util/AbstractProxyClassGenerator.java
Tue Sep  6 02:14:17 2005
@@ -18,9 +18,10 @@
 
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.util.Collection;
+import java.util.HashMap;
 import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 /**
@@ -38,15 +39,15 @@
     /**
      * Returns all methods that a proxy class must implement from the proxy interfaces. 
This method makes sure there
      * are no method signature clashes. For methods with the same signature (name and parameter
types), the one
-     * encountered first will be returned in the result.
+     * encountered first will be returned in the result. Final methods are also excluded
from the result.
      *
      * @param proxyClasses the interfaces the proxy class must implement
      * @return all methods that the proxy class must implement
      */
     public static Method[] getImplementationMethods( Class... proxyClasses )
     {
-        final Set<MethodSignature> signatures = new HashSet<MethodSignature>();
-        final List<Method> resultingMethods = new LinkedList<Method>();
+        final Map<MethodSignature, Method> signatureMethodMap = new HashMap<MethodSignature,
Method>();
+        final Set<MethodSignature> finalizedSignatures = new HashSet<MethodSignature>();
         for( int i = 0; i < proxyClasses.length; i++ )
         {
             Class proxyInterface = proxyClasses[i];
@@ -54,12 +55,20 @@
             for( int j = 0; j < methods.length; j++ )
             {
                 final MethodSignature signature = new MethodSignature( methods[j] );
-                if( !signatures.contains( signature ) && !Modifier.isFinal( methods[j].getModifiers()
) )
+                if( Modifier.isFinal( methods[j].getModifiers() ) )
                 {
-                    signatures.add( signature );
-                    resultingMethods.add( methods[j] );
+                    finalizedSignatures.add( signature );
+                }
+                else if( !signatureMethodMap.containsKey( signature ) )
+                {
+                    signatureMethodMap.put( signature, methods[j] );
                 }
             }
+        }
+        final Collection<Method> resultingMethods = signatureMethodMap.values();
+        for( MethodSignature signature : finalizedSignatures )
+        {
+            resultingMethods.remove( signatureMethodMap.get( signature ) );
         }
         final Method[] results = new Method[resultingMethods.size()];
         return resultingMethods.toArray( results );

Modified: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/AbstractSubclassingProxyFactoryTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/AbstractSubclassingProxyFactoryTestCase.java?rev=278949&r1=278948&r2=278949&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/AbstractSubclassingProxyFactoryTestCase.java
(original)
+++ jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/AbstractSubclassingProxyFactoryTestCase.java
Tue Sep  6 02:14:17 2005
@@ -39,6 +39,7 @@
         assertTrue( factory.canProxy( Echo.class ) );
         assertTrue( factory.canProxy( EchoImpl.class ) );
         assertFalse( factory.canProxy( FinalEcho.class ) );
+        assertTrue( factory.canProxy( FinalMethodEcho.class, Echo.class ) );
         assertFalse( factory.canProxy( NoDefaultConstructorEcho.class ) );
         assertTrue( factory.canProxy( ProtectedConstructorEcho.class ) );
         assertFalse( factory.canProxy( InvisibleEcho.class ) );
@@ -66,6 +67,21 @@
         assertTrue( echo instanceof EchoImpl );
     }
 
+    public void testProxiesWithFinalMethodSuperclass()
+    {
+        Echo proxy = ( Echo )factory.createDelegatorProxy(
+                new ConstantProvider( new EchoImpl() ), Echo.class, FinalMethodEcho.class
);
+        assertTrue( proxy instanceof FinalMethodEcho );
+
+        proxy = ( Echo )factory.createInterceptorProxy(
+                new EchoImpl(), new NoOpMethodInterceptor(), Echo.class, FinalMethodEcho.class
);
+        assertTrue( proxy instanceof EchoImpl );
+
+        proxy = ( Echo )factory.createInvocationHandlerProxy(
+                new NullInvocationHandler(), Echo.class, FinalMethodEcho.class );
+        assertTrue( proxy instanceof FinalMethodEcho );
+    }
+
     public void testDelegatorWithMultipleSuperclasses()
     {
         try
@@ -107,6 +123,15 @@
 
     public static final class FinalEcho extends EchoImpl
     {
+    }
+
+    public static class FinalMethodEcho extends EchoImpl
+    {
+        @Override
+        public final void echo()
+        {
+            super.echo();
+        }
     }
 
     public static class NoDefaultConstructorEcho extends EchoImpl



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message