cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1494576 - in /cxf/dosgi/trunk/dsw/cxf-dsw/src: main/java/org/apache/cxf/dosgi/dsw/util/ClassUtils.java test/java/org/apache/cxf/dosgi/dsw/util/ClassUtilsTest.java test/java/org/apache/cxf/dosgi/dsw/util/Provider.java
Date Wed, 19 Jun 2013 12:13:29 GMT
Author: sergeyb
Date: Wed Jun 19 12:13:29 2013
New Revision: 1494576

URL: http://svn.apache.org/r1494576
Log:
[DOSGI-166] Support for registering providers using List

Added:
    cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/Provider.java
  (with props)
Modified:
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ClassUtils.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/ClassUtilsTest.java

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ClassUtils.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ClassUtils.java?rev=1494576&r1=1494575&r2=1494576&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ClassUtils.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ClassUtils.java
Wed Jun 19 12:13:29 2013
@@ -24,6 +24,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.cxf.helpers.CastUtils;
 import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -104,12 +105,23 @@ public final class ClassUtils {
             } else if (serviceProviders.getClass() == String.class) {
                 String[] classNames = serviceProviders.toString().split(",");
                 return loadProviders(callingContext, classNames);
+            } else if (serviceProviders instanceof List) { 
+                List<Object> list = CastUtils.cast((List<?>)serviceProviders);
+                if (!list.isEmpty()) {
+                    List<Object> providers;
+                    if (list.get(0).getClass() == String.class) {
+                        providers = loadProviders(callingContext, list.toArray(new String[]{}));
+                    } else {
+                        providers = list;
+                    }
+                    return providers;
+                }
             } else {
                 return Arrays.asList(serviceProviders);
             }
-        } else {
-            return Collections.emptyList();
         }
+        return Collections.emptyList();
+        
     }
 
     private static List<Object> loadProviders(BundleContext callingContext, String[]
classNames) {

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/ClassUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/ClassUtilsTest.java?rev=1494576&r1=1494575&r2=1494576&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/ClassUtilsTest.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/ClassUtilsTest.java
Wed Jun 19 12:13:29 2013
@@ -20,24 +20,99 @@ package org.apache.cxf.dosgi.dsw.util;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
 import junit.framework.TestCase;
 
+import org.easymock.classextension.EasyMock;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
 public class ClassUtilsTest extends TestCase {
 
     public void testGetInterfaceClass() {
-        assertEquals(String.class, ClassUtils.getInterfaceClass("Hello", "java.lang.String"));
+        assertEquals(String.class,
+                ClassUtils.getInterfaceClass("Hello", "java.lang.String"));
         assertNull(ClassUtils.getInterfaceClass("Hello", "java.lang.Integer"));
-        assertEquals(List.class, ClassUtils.getInterfaceClass(new ArrayList<String>(),
"java.util.List"));
-        assertEquals(Collection.class, ClassUtils.getInterfaceClass(new ArrayList<String>(),
"java.util.Collection"));
+        assertEquals(List.class, ClassUtils.getInterfaceClass(
+                new ArrayList<String>(), "java.util.List"));
+        assertEquals(Collection.class, ClassUtils.getInterfaceClass(
+                new ArrayList<String>(), "java.util.Collection"));
     }
 
     public void testGetInterfaceClassFromSubclass() {
-        assertEquals(Map.class, ClassUtils.getInterfaceClass(new MySubclassFour(), "java.util.Map"));
-        assertNull(ClassUtils.getInterfaceClass(new MySubclassFour(), "java.util.UnknownType"));
+        assertEquals(Map.class, ClassUtils.getInterfaceClass(
+                new MySubclassFour(), "java.util.Map"));
+        assertNull(ClassUtils.getInterfaceClass(new MySubclassFour(),
+                "java.util.UnknownType"));
+    }
+
+    public void testLoadProvidersAsString() throws Exception {
+        BundleContext bc = mockBundleContext();
+        List<Object> providers = ClassUtils
+            .loadProviderClasses(bc, Collections.singletonMap("providers",
+                                Provider.class.getName()), "providers");
+        assertEquals(1, providers.size());
+        assertTrue(providers.get(0) instanceof Provider);
+    }
+
+    public void testLoadProvidersAsStringArray() throws Exception {
+        BundleContext bc = mockBundleContext();
+        List<Object> providers = ClassUtils
+           .loadProviderClasses(bc, Collections.singletonMap("providers",
+               new String[]{Provider.class.getName()}), "providers");
+        assertEquals(1, providers.size());
+        assertTrue(providers.get(0) instanceof Provider);
+    }
+
+    public void testLoadProvidersAsObject() throws Exception {
+        List<Object> providers = ClassUtils.loadProviderClasses(null,
+            Collections.singletonMap("providers", new Provider()),
+                "providers");
+        assertEquals(1, providers.size());
+        assertTrue(providers.get(0) instanceof Provider);
+    }
+
+    public void testLoadProvidersAsObjectArray() throws Exception {
+        List<Object> providers = ClassUtils.loadProviderClasses(null,
+            Collections.singletonMap("providers",
+                new Object[]{new Provider()}), "providers");
+        assertEquals(1, providers.size());
+        assertTrue(providers.get(0) instanceof Provider);
+    }
+
+    public void testLoadProvidersAsObjectList() throws Exception {
+        List<Object> list = new LinkedList<Object>();
+        list.add(new Provider());
+        List<Object> providers = ClassUtils.loadProviderClasses(null,
+            Collections.singletonMap("providers", list), "providers");
+        assertEquals(1, providers.size());
+        assertTrue(providers.get(0) instanceof Provider);
+    }
+
+    public void testLoadProvidersAsStringList() throws Exception {
+        List<Object> list = new LinkedList<Object>();
+        list.add(Provider.class.getName());
+        List<Object> providers = ClassUtils.loadProviderClasses(
+            mockBundleContext(),
+            Collections.singletonMap("providers", list), "providers");
+        assertEquals(1, providers.size());
+        assertTrue(providers.get(0) instanceof Provider);
+    }
+
+    private BundleContext mockBundleContext() throws Exception {
+        BundleContext bc = EasyMock.createMock(BundleContext.class);
+        Bundle bundle = EasyMock.createMock(Bundle.class);
+        bc.getBundle();
+        EasyMock.expectLastCall().andReturn(bundle);
+        bundle.loadClass(Provider.class.getName());
+        EasyMock.expectLastCall().andReturn(Provider.class);
+        EasyMock.replay(bc, bundle);
+        return bc;
     }
 
     @SuppressWarnings({ "serial", "rawtypes" })

Added: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/Provider.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/Provider.java?rev=1494576&view=auto
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/Provider.java
(added)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/Provider.java
Wed Jun 19 12:13:29 2013
@@ -0,0 +1,23 @@
+/**
+ * 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.util;
+
+
+public class Provider {
+}

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

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



Mime
View raw message