cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1220841 - in /cxf/dosgi/trunk/dsw/cxf-dsw/src: main/java/org/apache/cxf/dosgi/dsw/ClassUtils.java test/java/org/apache/cxf/dosgi/dsw/ClassUtilsTest.java
Date Mon, 19 Dec 2011 16:52:02 GMT
Author: sergeyb
Date: Mon Dec 19 16:52:01 2011
New Revision: 1220841

URL: http://svn.apache.org/viewvc?rev=1220841&view=rev
Log:
[DOSGI-94] Applying a patch on behalf of Ivanhoe Abrahams

Modified:
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/ClassUtils.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ClassUtilsTest.java

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/ClassUtils.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/ClassUtils.java?rev=1220841&r1=1220840&r2=1220841&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/ClassUtils.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/ClassUtils.java Mon
Dec 19 16:52:01 2011
@@ -35,9 +35,49 @@ public final class ClassUtils {
                 return intf;
             }
         }
+        
         if (serviceClass.getName().equals(interfaceName)) {
             return serviceClass;
         }
+        
+        Class<?> interfaceOnProxiedClass = getInterfaceClassOnSuperClasses(serviceClass,
interfaceName);
+        if (interfaceOnProxiedClass != null){
+        	return interfaceOnProxiedClass;
+        }
+        
         return null;
     }    
+    
+    /**
+     * <pre>
+     * 
+     * The following method tries to deal specifically with classes that might have been
proxied 
+     * eg. CGLIB proxies of which there might be a chain of proxies as different osgi frameworks
+     * might be proxying the original service class that has been registered and then proxying
the proxy.
+     * 
+     * </pre>
+     * 
+     * @param serviceClass
+     * @param interfaceName
+     * @return
+     */
+    private static Class<?> getInterfaceClassOnSuperClasses(Class<?> serviceClass,
String interfaceName){
+        Class<?> superClass = serviceClass.getSuperclass();
+		if (superClass != null){
+		    for (Class<?> iClass : superClass.getInterfaces()) {
+	            if (iClass.getName().equals(interfaceName)) {
+	                return iClass;
+	            }
+	            Class<?> intf = getInterfaceClass(iClass, interfaceName);
+	            if (intf != null) {
+	                return intf;
+	            }
+	        }
+		    Class<?> foundOnSuperclass = getInterfaceClassOnSuperClasses(superClass, interfaceName);
+		    if (foundOnSuperclass != null){
+		    	return foundOnSuperclass;
+		    }
+		}
+    	return null;
+    }
 }

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ClassUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ClassUtilsTest.java?rev=1220841&r1=1220840&r2=1220841&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ClassUtilsTest.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ClassUtilsTest.java
Mon Dec 19 16:52:01 2011
@@ -20,7 +20,9 @@ package org.apache.cxf.dosgi.dsw;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import junit.framework.TestCase;
 
@@ -32,4 +34,18 @@ public class ClassUtilsTest extends Test
         assertEquals(List.class, ClassUtils.getInterfaceClass(new ArrayList(), "java.util.List"));
         assertEquals(Collection.class, ClassUtils.getInterfaceClass(new ArrayList(), "java.util.Collection"));
     }
+    
+    public void testGetInterfaceClassFromSubclass() {
+	    assertEquals(Map.class, ClassUtils.getInterfaceClass(new MySubclassFour(), "java.util.Map"));
+	    assertNull(ClassUtils.getInterfaceClass(new MySubclassFour(), "java.util.UnknownType"));
+    }
+    static class MyMapSubclass extends HashMap{}
+
+    static class MySubclassOne extends MyMapSubclass{}
+
+    static class MySubclassTwo extends MySubclassOne{}
+
+    static class MySubclassThree extends MySubclassTwo{}
+
+    static class MySubclassFour extends MySubclassThree{}
 }



Mime
View raw message