Author: eglynn
Date: Mon Apr 20 16:40:05 2009
New Revision: 766746
URL: http://svn.apache.org/viewvc?rev=766746&view=rev
Log:
[dOSGi] fix for CXF-2173
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=766746&r1=766745&r2=766746&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
Mon Apr 20 16:40:05 2009
@@ -21,6 +21,7 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
import java.util.Enumeration;
@@ -145,7 +146,7 @@
public static ServiceEndpointDescription[]
flattenServiceDescription(ServiceEndpointDescription sd) {
ServiceEndpointDescription[] list = null;
- int interfaceNameCount = sd.getProvidedInterfaces().size();
+ int interfaceNameCount = sd.getProvidedInterfaces().size();
if (sd.getProvidedInterfaces() == null || interfaceNameCount <= 1) {
list = new ServiceEndpointDescription[] {sd};
} else {
@@ -277,7 +278,7 @@
public static String[] getProvidedInterfaces(ServiceEndpointDescription
sd, String interfaceName) {
- int interfaceNameCount = sd.getProvidedInterfaces().size();
+ int interfaceNameCount = sd.getProvidedInterfaces().size();
String[] interfaceNames = (String[])
sd.getProvidedInterfaces().toArray(new String[interfaceNameCount]);
if (interfaceName == null) {
@@ -467,26 +468,37 @@
public static String[] getPublishableInterfaces(ServiceEndpointDescription
sd,
ServiceReference sref) {
- String publishProperty =
- (String)sd.getProperty(Constants.REMOTE_INTERFACES_PROPERTY);
+ Object publishProperty =
+ sd.getProperty(Constants.REMOTE_INTERFACES_PROPERTY);
String[] actualInterfaces =
(String[])sref.getProperty(org.osgi.framework.Constants.OBJECTCLASS);
String[] publishableInterfaces = null;
+
if (actualInterfaces != null
&& actualInterfaces.length > 0
- && publishProperty != null
- && publishProperty.length() > 0) {
+ && publishProperty != null) {
if (INTERFACE_WILDCARD.equals(publishProperty)) {
// wildcard indicates all interfaces should be published
//
publishableInterfaces = actualInterfaces;
} else {
- String[] requestedInterfaces = tokenize(publishProperty, ",");
+
+ 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;
+
ArrayList<String> publishableList = new ArrayList<String>();
- for (int i = 0; i < requestedInterfaces.length; i++) {
+ for (int i = 0; requestedInterfaces != null
+ && i < requestedInterfaces.length; i++) {
if (contains(actualInterfaces, requestedInterfaces[i])) {
publishableList.add(requestedInterfaces[i]);
} else {
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=766746&r1=766745&r2=766746&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
Mon Apr 20 16:40:05 2009
@@ -28,31 +28,79 @@
new String[] {"foo", "bar", "snafu"});
}
+ public void testGetPublishableInterfacesAllStringArray() throws Exception {
+ doTestGetPublishableInterfaces(new String[] {"foo", "bar", "snafu"},
+ new String[] {"snafu", "foo", "bar"},
+ new String[] {"foo", "bar", "snafu"});
+ }
+
+ public void testGetPublishableInterfacesAllCollection() throws Exception {
+ doTestGetPublishableInterfaces(Arrays.asList("foo", "bar", "snafu"),
+ new String[] {"snafu", "foo", "bar"},
+ new String[] {"foo", "bar", "snafu"});
+ }
+
public void testGetPublishableInterfacesSubset() throws Exception {
doTestGetPublishableInterfaces("foo,snafu",
new String[] {"snafu", "foo", "bar"},
new String[] {"foo", "snafu"});
}
+ public void testGetPublishableInterfacesSubsetStringArray() throws
Exception {
+ doTestGetPublishableInterfaces(new String[] {"foo", "snafu"},
+ new String[] {"snafu", "foo", "bar"},
+ new String[] {"foo", "snafu"});
+ }
+
+ public void testGetPublishableInterfacesSubsetCollection() throws
Exception {
+ doTestGetPublishableInterfaces(Arrays.asList("foo", "snafu"),
+ new String[] {"snafu", "foo", "bar"},
+ new String[] {"foo", "snafu"});
+ }
+
public void testGetPublishableInterfacesSuperset() throws Exception {
doTestGetPublishableInterfaces("foo,bar,snafu",
new String[] {"snafu", "bar"},
new String[] {"bar", "snafu"});
}
+ public void testGetPublishableInterfacesSupersetStringArray() throws
Exception {
+ doTestGetPublishableInterfaces(new String[] {"foo", "bar", "snafu"},
+ new String[] {"snafu", "bar"},
+ new String[] {"bar", "snafu"});
+ }
+
+ public void testGetPublishableInterfacesSupersetCollection() throws
Exception {
+ doTestGetPublishableInterfaces(Arrays.asList("foo", "bar", "snafu"),
+ new String[] {"snafu", "bar"},
+ new String[] {"bar", "snafu"});
+ }
+
public void testGetPublishableInterfacesNonexistant() throws Exception {
doTestGetPublishableInterfaces("foo,bar,tofu",
new String[] {"snafu", "foo", "bar"},
new String[] {"foo", "bar"});
}
+ public void testGetPublishableInterfacesNonexistantStringArray() throws
Exception {
+ doTestGetPublishableInterfaces(new String[] {"foo", "bar", "tofu"},
+ new String[] {"snafu", "foo", "bar"},
+ new String[] {"foo", "bar"});
+ }
+
+ public void testGetPublishableInterfacesNonexistantCollection() throws
Exception {
+ doTestGetPublishableInterfaces(Arrays.asList("foo", "bar", "tofu"),
+ new String[] {"snafu", "foo", "bar"},
+ new String[] {"foo", "bar"});
+ }
+
public void testGetPublishableInterfacesWildcarded() throws Exception {
doTestGetPublishableInterfaces("*",
new String[] {"snafu", "foo", "bar"},
new String[] {"snafu", "foo", "bar"});
}
- public void doTestGetPublishableInterfaces(String requested,
+ public void doTestGetPublishableInterfaces(Object requested,
String[] actual,
String[] expected)
throws Exception {