You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by da...@apache.org on 2009/09/17 13:11:26 UTC

svn commit: r816138 - 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

Author: davidb
Date: Thu Sep 17 11:11:25 2009
New Revision: 816138

URL: http://svn.apache.org/viewvc?rev=816138&view=rev
Log:
Fix for CXF-2337.
New unit tests included.

Added:
    cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ClassUtilsTest.java   (with props)
Modified:
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/ClassUtils.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=816138&r1=816137&r2=816138&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 Thu Sep 17 11:11:25 2009
@@ -19,21 +19,25 @@
 package org.apache.cxf.dosgi.dsw;
 
 public final class ClassUtils {
-
-    private ClassUtils() {
-        
-    }
+    private ClassUtils() {}
     
     public static Class<?> getInterfaceClass(Object service, String interfaceName) {
-        for (Class iClass : service.getClass().getInterfaces()) {
+        return getInterfaceClass(service.getClass(), interfaceName);
+    }
+    
+    private static Class<?> getInterfaceClass(Class<?> serviceClass, String interfaceName) {
+        for (Class<?> iClass : serviceClass.getInterfaces()) {
             if (iClass.getName().equals(interfaceName)) {
                 return iClass;
             }
+            Class<?> intf = getInterfaceClass(iClass, interfaceName);
+            if (intf != null) {
+                return intf;
+            }
         }
-        if (service.getClass().getName().equals(interfaceName)) {
-            return service.getClass();
+        if (serviceClass.getName().equals(interfaceName)) {
+            return serviceClass;
         }
         return null;
-    }
-    
+    }    
 }

Added: 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=816138&view=auto
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ClassUtilsTest.java (added)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ClassUtilsTest.java Thu Sep 17 11:11:25 2009
@@ -0,0 +1,35 @@
+/** 
+  * Licensed to the Apache Software Foundation (ASF) under one 
+  * or more contributor license agreements. See the NOTICE file 
+  * distributed with this work for additional information 
+  * regarding copyright ownership. The ASF licenses this file 
+  * to you under the Apache License, Version 2.0 (the 
+  * "License"); you may not use this file except in compliance 
+  * with the License. You may obtain a copy of the License at 
+  * 
+  * http://www.apache.org/licenses/LICENSE-2.0 
+  * 
+  * Unless required by applicable law or agreed to in writing, 
+  * software distributed under the License is distributed on an 
+  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
+  * KIND, either express or implied. See the License for the 
+  * specific language governing permissions and limitations 
+  * under the License. 
+  */
+package org.apache.cxf.dosgi.dsw;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+public class ClassUtilsTest extends TestCase {
+    @SuppressWarnings("unchecked")
+    public void testGetInterfaceClass() {
+        assertEquals(String.class, ClassUtils.getInterfaceClass("Hello", "java.lang.String"));
+        assertNull(ClassUtils.getInterfaceClass("Hello", "java.lang.Integer"));
+        assertEquals(List.class, ClassUtils.getInterfaceClass(new ArrayList(), "java.util.List"));
+        assertEquals(Collection.class, ClassUtils.getInterfaceClass(new ArrayList(), "java.util.Collection"));
+    }
+}

Propchange: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ClassUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ClassUtilsTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date