You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by am...@apache.org on 2013/06/13 20:11:34 UTC
svn commit: r1492790 - in /cxf/dosgi/trunk:
discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/
discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/util/...
Author: amichai
Date: Thu Jun 13 18:11:34 2013
New Revision: 1492790
URL: http://svn.apache.org/r1492790
Log:
Extract more utility methods
Modified:
cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java
cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/util/Utils.java
cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java
cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java
cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/util/Utils.java
Modified: cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java?rev=1492790&r1=1492789&r2=1492790&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java (original)
+++ cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java Thu Jun 13 18:11:34 2013
@@ -21,8 +21,6 @@ package org.apache.cxf.dosgi.discovery.z
import java.io.File;
import java.io.IOException;
import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.Properties;
import org.apache.cxf.dosgi.discovery.zookeeper.server.util.Utils;
import org.apache.log4j.Level;
@@ -63,7 +61,7 @@ public class ZookeeperStarter implements
}
}
- public void setDefaults(Dictionary<String, Object> dict) throws IOException {
+ private void setDefaults(Dictionary<String, Object> dict) throws IOException {
Utils.removeEmptyValues(dict); // to avoid NumberFormatExceptions
Utils.setDefault(dict, "tickTime", "2000");
Utils.setDefault(dict, "initLimit", "10");
@@ -90,13 +88,8 @@ public class ZookeeperStarter implements
@SuppressWarnings("rawtypes")
private QuorumPeerConfig parseConfig(Dictionary dict) throws IOException, ConfigException {
- Properties props = new Properties();
- for (Enumeration e = dict.keys(); e.hasMoreElements();) {
- Object key = e.nextElement();
- props.put(key, dict.get(key));
- }
QuorumPeerConfig config = new QuorumPeerConfig();
- config.parseProperties(props);
+ config.parseProperties(Utils.toProperties(dict));
return config;
}
Modified: cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/util/Utils.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/util/Utils.java?rev=1492790&r1=1492789&r2=1492790&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/util/Utils.java (original)
+++ cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/util/Utils.java Thu Jun 13 18:11:34 2013
@@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.List;
+import java.util.Properties;
/**
* General purpose utility methods.
@@ -65,4 +66,21 @@ public final class Utils {
dict.put(key, value);
}
}
+
+ /**
+ * Converts a Dictionary into a Properties instance.
+ *
+ * @param dict a dictionary
+ * @param <K> the key type
+ * @param <V> the value type
+ * @return the properties
+ */
+ public static <K, V> Properties toProperties(Dictionary<K, V> dict) {
+ Properties props = new Properties();
+ for (Enumeration<K> e = dict.keys(); e.hasMoreElements();) {
+ K key = e.nextElement();
+ props.put(key, dict.get(key));
+ }
+ return props;
+ }
}
Modified: cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java?rev=1492790&r1=1492789&r2=1492790&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java (original)
+++ cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java Thu Jun 13 18:11:34 2013
@@ -118,10 +118,8 @@ public class LocalDiscovery implements B
}
}
- private Collection<String> addListener(ServiceReference reference,
- EndpointListener listener) {
- List<String> filters =
- Utils.getStringPlusProperty(reference, EndpointListener.ENDPOINT_LISTENER_SCOPE);
+ private Collection<String> addListener(ServiceReference reference, EndpointListener listener) {
+ List<String> filters = Utils.getStringPlusProperty(reference, EndpointListener.ENDPOINT_LISTENER_SCOPE);
if (filters.isEmpty()) {
return filters;
}
Modified: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java?rev=1492790&r1=1492789&r2=1492790&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java Thu Jun 13 18:11:34 2013
@@ -130,28 +130,13 @@ public class EndpointListenerNotifier {
static List<Filter> getFiltersFromEndpointListenerScope(ServiceReference sref, BundleContext bctx) {
List<Filter> filters = new ArrayList<Filter>();
- try {
- Object fo = sref.getProperty(EndpointListener.ENDPOINT_LISTENER_SCOPE);
- if (fo instanceof String) {
- filters.add(bctx.createFilter((String) fo));
- } else if (fo instanceof String[]) {
- String[] foArray = (String[]) fo;
- for (String f : foArray) {
- filters.add(bctx.createFilter(f));
- }
- } else if (fo instanceof Collection) {
- @SuppressWarnings("rawtypes")
- Collection c = (Collection) fo;
- for (Object o : c) {
- if (o instanceof String) {
- filters.add(bctx.createFilter((String) o));
- } else {
- LOG.warn("Component of a EndpointListener filter is not a string -> skipped!");
- }
- }
+ String[] scopes = Utils.getStringPlusProperty(sref.getProperty(EndpointListener.ENDPOINT_LISTENER_SCOPE));
+ for (String scope : scopes) {
+ try {
+ filters.add(bctx.createFilter(scope));
+ } catch (InvalidSyntaxException e) {
+ LOG.error("invalid endpoint listener scope: {}", scope, e);
}
- } catch (InvalidSyntaxException e) {
- LOG.error(e.getMessage(), e);
}
return filters;
}
Modified: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/util/Utils.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/util/Utils.java?rev=1492790&r1=1492789&r2=1492790&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/util/Utils.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/util/Utils.java Thu Jun 13 18:11:34 2013
@@ -18,6 +18,7 @@
*/
package org.apache.cxf.dosgi.topologymanager.util;
+import java.util.Collection;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.UUID;
@@ -63,6 +64,35 @@ public final class Utils {
return null;
}
+ /**
+ * Returns the value of a "string+" property as an array of strings.
+ * <p>
+ * A "string+" property can have a value which is either a string,
+ * an array of strings, or a collection of strings.
+ * <p>
+ * If the given value is not of one of the valid types, or is null,
+ * an empty array is returned.
+ *
+ * @param property a "string+" property value
+ * @return the property value as an array of strings, or an empty array
+ */
+ public static String[] getStringPlusProperty(Object property) {
+ if (property instanceof String) {
+ return new String[] {(String)property};
+ } else if (property instanceof String[]) {
+ return (String[])property;
+ } else if (property instanceof Collection) {
+ try {
+ @SuppressWarnings("unchecked")
+ Collection<String> strings = (Collection<String>)property;
+ return strings.toArray(new String[strings.size()]);
+ } catch (ArrayStoreException ase) {
+ // ignore collections with wrong type
+ }
+ }
+ return new String[0];
+ }
+
public static String getUUID(BundleContext bctx) {
synchronized ("org.osgi.framework.uuid") {
String uuid = bctx.getProperty("org.osgi.framework.uuid");