cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r776338 - in /cxf/dosgi/trunk/dsw/cxf-dsw/src: main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java test/java/org/apache/cxf/dosgi/dsw/OsgiUtilsTest.java
Date Tue, 19 May 2009 14:47:41 GMT
Author: davidb
Date: Tue May 19 14:47:40 2009
New Revision: 776338

URL: http://svn.apache.org/viewvc?rev=776338&view=rev
Log:
Fix for bug CXF-2173.
New unit tests added.

Modified:
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/OsgiUtilsTest.java

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java?rev=776338&r1=776337&r2=776338&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java Tue
May 19 14:47:40 2009
@@ -453,6 +453,21 @@
             || value instanceof String && Boolean.parseBoolean((String)value);
     }
     
+    @SuppressWarnings("unchecked")
+    public static Collection<String> getMultiValueProperty(Object property) {
+        if (property == null) {
+            return null;
+        }
+        
+        if (property instanceof Collection) {
+            return (Collection<String>) property;
+        } else if (property instanceof String []) {
+            return Arrays.asList((String []) property);
+        } else {
+            return Collections.singleton(property.toString());
+        }
+    }
+
     public static String getProperty(ServiceEndpointDescription sd, String name) { 
         return getProperty(sd, name, String.class, null); 
     }
@@ -469,8 +484,8 @@
 
     public static String[] getPublishableInterfaces(ServiceEndpointDescription sd,
                                                     ServiceReference sref) {
-        Object publishProperty = 
-            sd.getProperty(DistributionConstants.REMOTE_INTERFACES);
+        Collection<String> publishProperty = 
+            getMultiValueProperty(sd.getProperty(DistributionConstants.REMOTE_INTERFACES));
         String[] actualInterfaces = 
             (String[])sref.getProperty(org.osgi.framework.Constants.OBJECTCLASS);
         String[] publishableInterfaces = null;
@@ -480,24 +495,22 @@
             && actualInterfaces.length > 0
             && publishProperty != null) {
 
-            if (INTERFACE_WILDCARD.equals(publishProperty)) {
+            if (publishProperty.size() == 1 
+                    && INTERFACE_WILDCARD.equals(publishProperty.iterator().next()))
{                    
                 // wildcard indicates all interfaces should be published
                 //
                 publishableInterfaces = actualInterfaces;
             } else {
-
-                String[] requestedInterfaces =
-                    publishProperty instanceof String
-                    ? tokenize((String)publishProperty, ",")
-                    : publishProperty instanceof String[]
-                      ? (String[])publishProperty
-                      : publishProperty instanceof Collection
-                      ? (String[])((Collection)publishProperty).toArray(
-                            new String[((Collection)publishProperty).size()])
-                         : null;
+                String [] requestedInterfaces;
+                if (publishProperty.size() == 0) {
+                    requestedInterfaces = null;
+                } else if (publishProperty.size() == 1) {
+                    requestedInterfaces = tokenize(publishProperty.iterator().next(), ",");
+                } else {
+                    requestedInterfaces = publishProperty.toArray(new String[publishProperty.size()]);
+                }
 
                 ArrayList<String> publishableList = new ArrayList<String>();
-
                 for (int i = 0; requestedInterfaces != null 
                                 && i < requestedInterfaces.length; i++) {
                     if (contains(actualInterfaces, requestedInterfaces[i])) {

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/OsgiUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/OsgiUtilsTest.java?rev=776338&r1=776337&r2=776338&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/OsgiUtilsTest.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/OsgiUtilsTest.java
Tue May 19 14:47:40 2009
@@ -1,6 +1,7 @@
 package org.apache.cxf.dosgi.dsw;
 
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Dictionary;
@@ -100,6 +101,12 @@
                                        new String[] {"snafu", "foo", "bar"});
     }
 
+    public void testGetPublishableInterfacesWildcardedInArray() throws Exception {
+        doTestGetPublishableInterfaces(Arrays.asList("*"),
+                                       new String[] {"snafu", "foo", "bar"},
+                                       new String[] {"snafu", "foo", "bar"});
+    }
+
     public void doTestGetPublishableInterfaces(Object requested, 
                                                String[] actual, 
                                                String[] expected)
@@ -237,4 +244,26 @@
         assertEquals("SomeService", rsElements.get(0).getChild("provide", ns).getAttributeValue("interface"));
         assertEquals("SomeOtherService", rsElements.get(1).getChild("provide", ns).getAttributeValue("interface"));
     }
+
+    public void testMultiValuePropertyAsString() {
+        assertEquals(Collections.singleton("hi"), 
+            OsgiUtils.getMultiValueProperty("hi"));            
+    }
+    
+    public void testMultiValuePropertyAsArray() {
+        assertEquals(Arrays.asList("a", "b"), 
+                OsgiUtils.getMultiValueProperty(new String [] {"a", "b"}));
+    }
+    
+    public void testMultiValuePropertyAsCollection() {
+        List<String> list = new ArrayList<String>();
+        list.add("1");
+        list.add("2");
+        list.add("3");
+        assertEquals(list, OsgiUtils.getMultiValueProperty(list)); 
+    }
+    
+    public void testMultiValuePropertyNull() {
+        assertNull(OsgiUtils.getMultiValueProperty(null));            
+    }
 }



Mime
View raw message