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/12 00:29:28 UTC

svn commit: r1491995 [2/2] - in /cxf/dosgi/trunk: discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/util/ discovery/dis...

Copied: cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/util/EndpointUtils.java (from r1491250, cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtils.java)
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/util/EndpointUtils.java?p2=cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/util/EndpointUtils.java&p1=cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtils.java&r1=1491250&r2=1491995&rev=1491995&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtils.java (original)
+++ cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/util/EndpointUtils.java Tue Jun 11 22:29:27 2013
@@ -1,581 +1,545 @@
-/**
- * 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.discovery.local;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.Array;
-import java.lang.reflect.Constructor;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.JDOMException;
-import org.jdom.Namespace;
-import org.jdom.input.SAXBuilder;
-import org.jdom.output.Format;
-import org.jdom.output.XMLOutputter;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.remoteserviceadmin.EndpointDescription;
-import org.osgi.service.remoteserviceadmin.RemoteConstants;
-import org.slf4j.LoggerFactory;
-
-public final class LocalDiscoveryUtils {
-
-    private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(LocalDiscoveryUtils.class);
-
-    private static final String REMOTE_SERVICES_HEADER_NAME = "Remote-Service";
-    private static final String REMOTE_SERVICES_DIRECTORY = "OSGI-INF/remote-service/";
-    // this one was replaced by the RSA one in the spec
-    private static final String REMOTE_SERVICES_NS = "http://www.osgi.org/xmlns/sd/v1.0.0";
-    private static final String REMOTE_SERVICES_ADMIN_NS = "http://www.osgi.org/xmlns/rsa/v1.0.0";
-
-    private static final String SERVICE_DESCRIPTION_ELEMENT = "service-description";
-    private static final String ENDPOINT_DESCRIPTION_ELEMENT = "endpoint-description";
-
-    private static final String PROVIDE_INTERFACE_ELEMENT = "provide";
-    private static final String PROVIDE_INTERFACE_NAME_ATTRIBUTE = "interface";
-
-    private static final String PROPERTY_ELEMENT = "property";
-    private static final String PROPERTY_NAME_ATTRIBUTE = "name";
-    private static final String PROPERTY_VALUE_ATTRIBUTE = "value";
-    private static final String PROPERTY_VALUE_TYPE_ATTRIBUTE = "value-type";
-    private static final String PROPERTY_INTERFACE_ATTRIBUTE = "interface";
-
-    private static final String INTERFACE_SEPARATOR = ":";
-
-    private LocalDiscoveryUtils() {
-    }
-
-    public static List<EndpointDescription> getAllEndpointDescriptions(Bundle b) {
-        List<Element> elements = getAllDescriptionElements(b);
-
-        List<EndpointDescription> eds = new ArrayList<EndpointDescription>(elements.size());
-        for (Element el : elements) {
-            if (ENDPOINT_DESCRIPTION_ELEMENT.equals(el.getName())) {
-                eds.add(getEndpointDescription(el));
-            } else if (SERVICE_DESCRIPTION_ELEMENT.equals(el.getName())) {
-                eds.add(getLegacyEndpointDescription(el));
-            }
-        }
-        return eds;
-    }
-
-    @SuppressWarnings("unchecked")
-    public static EndpointDescription getEndpointDescription(Element endpointDescriptionElement) {
-        Map<String, Object> map = new HashMap<String, Object>();
-
-        List<Element> properties = endpointDescriptionElement.getChildren(PROPERTY_ELEMENT,
-                Namespace.getNamespace(REMOTE_SERVICES_ADMIN_NS));
-        for (Element prop : properties) {
-            boolean handled = handleArray(prop, map);
-            if (handled) {
-                continue;
-            }
-            handled = handleCollection(prop, map);
-            if (handled) {
-                continue;
-            }
-            handled = handleXML(prop, map);
-            if (handled) {
-                continue;
-            }
-
-            String name = prop.getAttributeValue(PROPERTY_NAME_ATTRIBUTE);
-            String value = prop.getAttributeValue(PROPERTY_VALUE_ATTRIBUTE);
-            if (value == null) {
-                value = prop.getText();
-            }
-            String type = getTypeName(prop);
-            map.put(name, instantiate(type, value));
-        }
-        return new EndpointDescription(map);
-    }
-
-    @SuppressWarnings("unchecked")
-    private static EndpointDescription getLegacyEndpointDescription(Element el) {
-        Namespace ns = Namespace.getNamespace(REMOTE_SERVICES_NS);
-
-        List<String> iNames = getProvidedInterfaces(el.getChildren(PROVIDE_INTERFACE_ELEMENT, ns));
-        Map<String, Object> remoteProps = getProperties(el.getChildren(PROPERTY_ELEMENT, ns));
-
-        if (remoteProps.get(Constants.OBJECTCLASS) == null) {
-            remoteProps.put(Constants.OBJECTCLASS, iNames.toArray(new String[] {}));
-        }
-
-        Object uri = remoteProps.get("org.apache.cxf.ws.address");
-        if (uri == null) {
-            uri = remoteProps.get("osgi.remote.configuration.pojo.address");
-        }
-        if (uri == null) {
-            String firstIntf = iNames.get(0);
-            uri = "http://localhost:9000/" + firstIntf.replace('.', '/');
-        }
-        remoteProps.put(RemoteConstants.ENDPOINT_ID, uri.toString());
-
-        Object exportedConfigs = remoteProps.get(RemoteConstants.SERVICE_EXPORTED_CONFIGS);
-        if (exportedConfigs == null) {
-            exportedConfigs = "org.apache.cxf.ws";
-        }
-        remoteProps.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, exportedConfigs);
-
-        for (Iterator<String> it = remoteProps.keySet().iterator(); it.hasNext();) {
-            if (it.next().startsWith("service.exported.")) {
-                it.remove();
-            }
-        }
-
-        return new EndpointDescription(remoteProps);
-    }
-
-    private static String getTypeName(Element prop) {
-        String type = prop.getAttributeValue(PROPERTY_VALUE_TYPE_ATTRIBUTE);
-        if (type == null) {
-            type = "String";
-        }
-        return type;
-    }
-
-    @SuppressWarnings("unchecked")
-    private static boolean handleArray(Element prop, Map<String, Object> map) {
-        Element arrayEl = prop.getChild("array", Namespace.getNamespace(REMOTE_SERVICES_ADMIN_NS));
-        if (arrayEl == null) {
-            return false;
-        }
-
-        List<Element> values = arrayEl.getChildren(PROPERTY_VALUE_ATTRIBUTE,
-                Namespace.getNamespace(REMOTE_SERVICES_ADMIN_NS));
-        String type = getTypeName(prop);
-        Class<?> cls = null;
-        if ("long".equals(type)) {
-            cls = long.class;
-        } else if ("double".equals(type)) {
-            cls = double.class;
-        } else if ("float".equals(type)) {
-            cls = float.class;
-        } else if ("int".equals(type)) {
-            cls = int.class;
-        } else if ("byte".equals(type)) {
-            cls = byte.class;
-        } else if ("boolean".equals(type)) {
-            cls = boolean.class;
-        } else if ("short".equals(type)) {
-            cls = short.class;
-        }
-
-        try {
-            if (cls == null) {
-                cls = ClassLoader.getSystemClassLoader().loadClass("java.lang." + type);
-            }
-            Object array = Array.newInstance(cls, values.size());
-
-            for (int i = 0; i < values.size(); i++) {
-                Element vEl = values.get(i);
-                Object val = handleValue(vEl, type);
-                Array.set(array, i, val);
-            }
-
-            String name = prop.getAttributeValue(PROPERTY_NAME_ATTRIBUTE);
-            map.put(name, array);
-            return true;
-        } catch (Exception e) {
-            LOG.warn("Could not create array for Endpoint Description", e);
-            return false;
-        }
-    }
-
-    @SuppressWarnings("unchecked")
-    private static boolean handleCollection(Element prop, Map<String, Object> map) {
-        Collection<Object> col = null;
-        Element el = prop.getChild("list",
-                Namespace.getNamespace(REMOTE_SERVICES_ADMIN_NS));
-        if (el != null) {
-            col = new ArrayList<Object>();
-        } else {
-            el = prop.getChild("set", Namespace.getNamespace(REMOTE_SERVICES_ADMIN_NS));
-            if (el != null) {
-                col = new HashSet<Object>();
-            }
-        }
-
-        if (el == null) {
-            return false;
-        }
-
-        String type = getTypeName(prop);
-        List<Element> values = el.getChildren(PROPERTY_VALUE_ATTRIBUTE,
-                Namespace.getNamespace(REMOTE_SERVICES_ADMIN_NS));
-        for (Element val : values) {
-            Object obj = handleValue(val, type);
-            col.add(obj);
-        }
-
-        String name = prop.getAttributeValue(PROPERTY_NAME_ATTRIBUTE);
-        map.put(name, col);
-        return true;
-    }
-
-    private static boolean handleXML(Element prop, Map<String, Object> map) {
-        String sb = readXML(prop);
-        if (sb == null) {
-            return false;
-        }
-
-        String name = prop.getAttributeValue(PROPERTY_NAME_ATTRIBUTE);
-        map.put(name, sb);
-        return true;
-    }
-
-    @SuppressWarnings("unchecked")
-    private static String readXML(Element prop) {
-        Element el = prop.getChild("xml", Namespace.getNamespace(REMOTE_SERVICES_ADMIN_NS));
-        if (el == null) {
-            return null;
-        }
-
-        String type = getTypeName(prop);
-        if (!"String".equals(type)) {
-            LOG.warn("Embedded XML must be of type String, found: " + type);
-            return null;
-        }
-
-        XMLOutputter outputter = new XMLOutputter(Format.getCompactFormat());
-        StringBuilder sb = new StringBuilder();
-        List<Element> children = el.getChildren();
-        for (Element child : children) {
-            sb.append(outputter.outputString(child));
-        }
-        return sb.toString();
-    }
-
-    private static Object handleValue(Element val, String type) {
-        String xml = readXML(val);
-        if (xml != null) {
-            return xml;
-        } else {
-            return instantiate(type, val.getText());
-        }
-    }
-
-    private static Object instantiate(String type, String value) {
-        if ("String".equals(type)) {
-            return value;
-        }
-
-        value = value.trim();
-        String boxedType = null;
-        if ("long".equals(type)) {
-            boxedType = "Long";
-        } else if ("double".equals(type)) {
-            boxedType = "Double";
-        } else if ("float".equals(type)) {
-            boxedType = "Float";
-        } else if ("int".equals(type)) {
-            boxedType = "Integer";
-        } else if ("byte".equals(type)) {
-            boxedType = "Byte";
-        } else if ("char".equals(type)) {
-            boxedType = "Character";
-        } else if ("boolean".equals(type)) {
-            boxedType = "Boolean";
-        } else if ("short".equals(type)) {
-            boxedType = "Short";
-        }
-
-        if (boxedType == null) {
-            boxedType = type;
-        }
-        String javaType = "java.lang." + boxedType;
-
-        try {
-            if ("Character".equals(boxedType)) {
-                return new Character(value.charAt(0));
-            } else {
-                Class<?> cls = ClassLoader.getSystemClassLoader().loadClass(javaType);
-                Constructor<?> ctor = cls.getConstructor(String.class);
-                return ctor.newInstance(value);
-            }
-        } catch (Exception e) {
-            LOG.warn("Could not create Endpoint Property of type " + type + " and value " + value);
-            return null;
-        }
-    }
-
-    static List<Element> getAllDescriptionElements(Bundle b) {
-        Object header = null;
-
-        Dictionary<?, ?> headers = b.getHeaders();
-        if (headers != null) {
-            header = headers.get(REMOTE_SERVICES_HEADER_NAME);
-        }
-
-        if (header == null) {
-            header = REMOTE_SERVICES_DIRECTORY;
-        }
-
-        String dir = header.toString();
-        String filePattern = "*.xml";
-        if (dir.endsWith("/")) {
-            dir = dir.substring(0, dir.length() - 1);
-        } else {
-            int idx = dir.lastIndexOf('/');
-            if (idx >= 0 & dir.length() > idx) {
-                filePattern = dir.substring(idx + 1);
-                dir = dir.substring(0, idx);
-            } else {
-                filePattern = dir;
-                dir = "";
-            }
-        }
-
-        Enumeration<?> urls = b.findEntries(dir, filePattern, false);
-        if (urls == null) {
-            return Collections.emptyList();
-        }
-
-        List<Element> elements = new ArrayList<Element>();
-        while (urls.hasMoreElements()) {
-            URL resourceURL = (URL) urls.nextElement();
-            try {
-                elements.addAll(getElements(resourceURL.openStream()));
-            } catch (Exception ex) {
-                LOG.warn("Problem parsing: " + resourceURL, ex);
-            }
-        }
-        return elements;
-    }
-
-    private static Map<String, Object> getProperties(List<Element> elements) {
-        Map<String, Object> props = new HashMap<String, Object>();
-
-        for (Element p : elements) {
-            String key = p.getAttributeValue(PROPERTY_NAME_ATTRIBUTE);
-            String value = p.getAttributeValue(PROPERTY_VALUE_ATTRIBUTE);
-            if (value == null) {
-                value = p.getTextTrim();
-            }
-
-            String iface = p.getAttributeValue(PROPERTY_INTERFACE_ATTRIBUTE);
-            if (key != null) {
-                props.put(iface == null || iface.isEmpty()
-                          ? key
-                          : key + INTERFACE_SEPARATOR + iface,
-                          value);
-            }
-        }
-
-        return props;
-    }
-
-    private static List<String> getProvidedInterfaces(List<Element> elements) {
-        List<String> names = new ArrayList<String>();
-
-        for (Element p : elements) {
-            String name = p.getAttributeValue(PROVIDE_INTERFACE_NAME_ATTRIBUTE);
-            if (name != null) {
-                names.add(name);
-            }
-        }
-
-        return names;
-    }
-
-    public static List<String> getStringPlusProperty(ServiceReference sr, String key) {
-        Object value = sr.getProperty(key);
-        if (value == null) {
-            return Collections.emptyList();
-        }
-
-        if (value instanceof String) {
-            return Collections.singletonList((String) value);
-        }
-
-        if (value instanceof String[]) {
-            String[] values = (String[]) value;
-            List<String> result = new ArrayList<String>(values.length);
-            for (String v : values) {
-                if (v != null) {
-                    result.add(v);
-                }
-            }
-            return Collections.unmodifiableList(result);
-        }
-
-        if (value instanceof Collection<?>) {
-            Collection<?> values = (Collection<?>) value;
-            List<String> result = new ArrayList<String>(values.size());
-            for (Object v : values) {
-                if (v instanceof String) {
-                    result.add((String) v);
-                }
-            }
-            return Collections.unmodifiableList(result);
-        }
-
-        return Collections.emptyList();
-    }
-
-    public static String getEndpointDescriptionXML(Map<String, Object> m) {
-        Document d = new Document();
-        Namespace ns = Namespace.getNamespace("http://www.osgi.org/xmlns/rsa/v1.0.0");
-        Element rootEl = new Element("endpoint-descriptions", ns);
-        d.setRootElement(rootEl);
-        Element contentEl = new Element("endpoint-description", ns);
-        rootEl.addContent(contentEl);
-
-        for (Map.Entry<String, Object> entry : m.entrySet()) {
-            String key = entry.getKey();
-            Object val = entry.getValue();
-
-            Element propEl = new Element("property", ns);
-            propEl.setAttribute("name", key);
-            if (val.getClass().isArray()) {
-                Element arrayEl = new Element("array", ns);
-                propEl.addContent(arrayEl);
-                for (Object o : normalizeArray(val)) {
-                    setValueType(propEl, o);
-                    Element valueEl = new Element("value", ns);
-                    arrayEl.addContent(valueEl);
-                    valueEl.addContent(o.toString());
-                }
-            } else if (val instanceof List) {
-                Element listEl = new Element("list", ns);
-                propEl.addContent(listEl);
-                handleCollectionValue(ns, (Collection<?>) val, propEl, listEl);
-            } else if (val instanceof Set) {
-                Element setEl = new Element("set", ns);
-                propEl.addContent(setEl);
-                handleCollectionValue(ns, (Collection<?>) val, propEl, setEl);
-            } else if (val instanceof String
-                    || val instanceof Character
-                    || val instanceof Boolean
-                    || val instanceof Byte) {
-                setValueType(propEl, val);
-                propEl.setAttribute("value", val.toString());
-            } else if (val instanceof Long
-                    || val instanceof Double
-                    || val instanceof Float
-                    || val instanceof Integer
-                    || val instanceof Short) {
-                // various numbers..   maybe "val instanceof Number"?
-                setValueType(propEl, val);
-                propEl.setAttribute("value", val.toString());
-            } else {
-                // Don't add this property as the value type is not supported
-                continue;
-            }
-            contentEl.addContent(propEl);
-        }
-
-        return new XMLOutputter(Format.getPrettyFormat()).outputString(d);
-    }
-
-    private static Object[] normalizeArray(Object val) {
-        List<Object> l = new ArrayList<Object>();
-        if (val instanceof int[]) {
-            int[] ia = (int[]) val;
-            for (int i : ia) {
-                l.add(i);
-            }
-        } else if (val instanceof long[]) {
-            long[] la = (long[]) val;
-            for (long i : la) {
-                l.add(i);
-            }
-        } else if (val instanceof float[]) {
-            float[] fa = (float[]) val;
-            for (float f : fa) {
-                l.add(f);
-            }
-        } else if (val instanceof byte[]) {
-            byte[] ba = (byte[]) val;
-            for (byte b : ba) {
-                l.add(b);
-            }
-        } else if (val instanceof boolean[]) {
-            boolean[] ba = (boolean[]) val;
-            for (boolean b : ba) {
-                l.add(b);
-            }
-        } else if (val instanceof short[]) {
-            short[] sa = (short[]) val;
-            for (short s : sa) {
-                l.add(s);
-            }
-        } else if (val instanceof char[]) {
-            char[] ca = (char[]) val;
-            for (char c : ca) {
-                l.add(c);
-            }
-        } else {
-            return (Object[]) val;
-        }
-        return l.toArray();
-    }
-
-    private static void handleCollectionValue(Namespace ns, Collection<?> val, Element propEl, Element listEl) {
-        for (Object o : val) {
-            setValueType(propEl, o);
-            Element valueEl = new Element("value", ns);
-            listEl.addContent(valueEl);
-            valueEl.addContent(o.toString());
-        }
-    }
-
-    private static void setValueType(Element propEl, Object val) {
-        if (val instanceof String) {
-            return;
-        }
-
-        String dataType = val.getClass().getName();
-        if (dataType.startsWith("java.lang.")) {
-            dataType = dataType.substring("java.lang.".length());
-        }
-        propEl.setAttribute("value-type", dataType);
-    }
-
-    @SuppressWarnings("unchecked")
-    public static List<Element> getElements(InputStream in) throws JDOMException, IOException {
-        List<Element> elements = new ArrayList<Element>();
-
-        Document d = new SAXBuilder().build(in);
-        if (d.getRootElement().getNamespaceURI().equals(REMOTE_SERVICES_ADMIN_NS)) {
-            elements.addAll(d.getRootElement().getChildren(ENDPOINT_DESCRIPTION_ELEMENT,
-                                                           Namespace.getNamespace(REMOTE_SERVICES_ADMIN_NS)));
-        }
-
-        Namespace nsOld = Namespace.getNamespace(REMOTE_SERVICES_NS);
-        elements.addAll(d.getRootElement().getChildren(SERVICE_DESCRIPTION_ELEMENT, nsOld));
-
-        return elements;
-    }
-}
+/**
+ * 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.discovery.local.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Array;
+import java.lang.reflect.Constructor;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.Namespace;
+import org.jdom.input.SAXBuilder;
+import org.jdom.output.Format;
+import org.jdom.output.XMLOutputter;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.service.remoteserviceadmin.EndpointDescription;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class EndpointUtils {
+
+    private static final Logger LOG = LoggerFactory.getLogger(EndpointUtils.class);
+
+    private static final String REMOTE_SERVICES_HEADER_NAME = "Remote-Service";
+    private static final String REMOTE_SERVICES_DIRECTORY = "OSGI-INF/remote-service/";
+    // this one was replaced by the RSA one in the spec
+    private static final String REMOTE_SERVICES_NS = "http://www.osgi.org/xmlns/sd/v1.0.0";
+    private static final String REMOTE_SERVICES_ADMIN_NS = "http://www.osgi.org/xmlns/rsa/v1.0.0";
+
+    private static final String SERVICE_DESCRIPTION_ELEMENT = "service-description";
+    private static final String ENDPOINT_DESCRIPTION_ELEMENT = "endpoint-description";
+
+    private static final String PROVIDE_INTERFACE_ELEMENT = "provide";
+    private static final String PROVIDE_INTERFACE_NAME_ATTRIBUTE = "interface";
+
+    private static final String PROPERTY_ELEMENT = "property";
+    private static final String PROPERTY_NAME_ATTRIBUTE = "name";
+    private static final String PROPERTY_VALUE_ATTRIBUTE = "value";
+    private static final String PROPERTY_VALUE_TYPE_ATTRIBUTE = "value-type";
+    private static final String PROPERTY_INTERFACE_ATTRIBUTE = "interface";
+
+    private static final String INTERFACE_SEPARATOR = ":";
+
+    private EndpointUtils() {
+    }
+
+    public static List<EndpointDescription> getAllEndpointDescriptions(Bundle b) {
+        List<Element> elements = getAllDescriptionElements(b);
+
+        List<EndpointDescription> eds = new ArrayList<EndpointDescription>(elements.size());
+        for (Element el : elements) {
+            if (ENDPOINT_DESCRIPTION_ELEMENT.equals(el.getName())) {
+                eds.add(getEndpointDescription(el));
+            } else if (SERVICE_DESCRIPTION_ELEMENT.equals(el.getName())) {
+                eds.add(getLegacyEndpointDescription(el));
+            }
+        }
+        return eds;
+    }
+
+    @SuppressWarnings("unchecked")
+    private static EndpointDescription getEndpointDescription(Element endpointDescriptionElement) {
+        Map<String, Object> map = new HashMap<String, Object>();
+
+        List<Element> properties = endpointDescriptionElement.getChildren(PROPERTY_ELEMENT,
+                Namespace.getNamespace(REMOTE_SERVICES_ADMIN_NS));
+        for (Element prop : properties) {
+            boolean handled = handleArray(prop, map);
+            if (handled) {
+                continue;
+            }
+            handled = handleCollection(prop, map);
+            if (handled) {
+                continue;
+            }
+            handled = handleXML(prop, map);
+            if (handled) {
+                continue;
+            }
+
+            String name = prop.getAttributeValue(PROPERTY_NAME_ATTRIBUTE);
+            String value = prop.getAttributeValue(PROPERTY_VALUE_ATTRIBUTE);
+            if (value == null) {
+                value = prop.getText();
+            }
+            String type = getTypeName(prop);
+            map.put(name, instantiate(type, value));
+        }
+        return new EndpointDescription(map);
+    }
+
+    @SuppressWarnings("unchecked")
+    private static EndpointDescription getLegacyEndpointDescription(Element el) {
+        Namespace ns = Namespace.getNamespace(REMOTE_SERVICES_NS);
+
+        List<String> iNames = getProvidedInterfaces(el.getChildren(PROVIDE_INTERFACE_ELEMENT, ns));
+        Map<String, Object> remoteProps = getProperties(el.getChildren(PROPERTY_ELEMENT, ns));
+
+        if (remoteProps.get(Constants.OBJECTCLASS) == null) {
+            remoteProps.put(Constants.OBJECTCLASS, iNames.toArray(new String[] {}));
+        }
+
+        Object uri = remoteProps.get("org.apache.cxf.ws.address");
+        if (uri == null) {
+            uri = remoteProps.get("osgi.remote.configuration.pojo.address");
+        }
+        if (uri == null) {
+            String firstIntf = iNames.get(0);
+            uri = "http://localhost:9000/" + firstIntf.replace('.', '/');
+        }
+        remoteProps.put(RemoteConstants.ENDPOINT_ID, uri.toString());
+
+        Object exportedConfigs = remoteProps.get(RemoteConstants.SERVICE_EXPORTED_CONFIGS);
+        if (exportedConfigs == null) {
+            exportedConfigs = "org.apache.cxf.ws";
+        }
+        remoteProps.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, exportedConfigs);
+
+        for (Iterator<String> it = remoteProps.keySet().iterator(); it.hasNext();) {
+            if (it.next().startsWith("service.exported.")) {
+                it.remove();
+            }
+        }
+
+        return new EndpointDescription(remoteProps);
+    }
+
+    private static String getTypeName(Element prop) {
+        String type = prop.getAttributeValue(PROPERTY_VALUE_TYPE_ATTRIBUTE);
+        return type == null ? "String" : type;
+    }
+
+    @SuppressWarnings("unchecked")
+    private static boolean handleArray(Element prop, Map<String, Object> map) {
+        Element arrayEl = prop.getChild("array", Namespace.getNamespace(REMOTE_SERVICES_ADMIN_NS));
+        if (arrayEl == null) {
+            return false;
+        }
+
+        List<Element> values = arrayEl.getChildren(PROPERTY_VALUE_ATTRIBUTE,
+                Namespace.getNamespace(REMOTE_SERVICES_ADMIN_NS));
+        String type = getTypeName(prop);
+        Class<?> cls = null;
+        if ("long".equals(type)) {
+            cls = long.class;
+        } else if ("double".equals(type)) {
+            cls = double.class;
+        } else if ("float".equals(type)) {
+            cls = float.class;
+        } else if ("int".equals(type)) {
+            cls = int.class;
+        } else if ("byte".equals(type)) {
+            cls = byte.class;
+        } else if ("boolean".equals(type)) {
+            cls = boolean.class;
+        } else if ("short".equals(type)) {
+            cls = short.class;
+        }
+
+        try {
+            if (cls == null) {
+                cls = ClassLoader.getSystemClassLoader().loadClass("java.lang." + type);
+            }
+            Object array = Array.newInstance(cls, values.size());
+
+            for (int i = 0; i < values.size(); i++) {
+                Element vEl = values.get(i);
+                Object val = handleValue(vEl, type);
+                Array.set(array, i, val);
+            }
+
+            String name = prop.getAttributeValue(PROPERTY_NAME_ATTRIBUTE);
+            map.put(name, array);
+            return true;
+        } catch (Exception e) {
+            LOG.warn("Could not create array for Endpoint Description", e);
+            return false;
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private static boolean handleCollection(Element prop, Map<String, Object> map) {
+        Collection<Object> col = null;
+        Element el = prop.getChild("list",
+                Namespace.getNamespace(REMOTE_SERVICES_ADMIN_NS));
+        if (el != null) {
+            col = new ArrayList<Object>();
+        } else {
+            el = prop.getChild("set", Namespace.getNamespace(REMOTE_SERVICES_ADMIN_NS));
+            if (el != null) {
+                col = new HashSet<Object>();
+            }
+        }
+
+        if (el == null) {
+            return false;
+        }
+
+        String type = getTypeName(prop);
+        List<Element> values = el.getChildren(PROPERTY_VALUE_ATTRIBUTE,
+                Namespace.getNamespace(REMOTE_SERVICES_ADMIN_NS));
+        for (Element val : values) {
+            Object obj = handleValue(val, type);
+            col.add(obj);
+        }
+
+        String name = prop.getAttributeValue(PROPERTY_NAME_ATTRIBUTE);
+        map.put(name, col);
+        return true;
+    }
+
+    private static boolean handleXML(Element prop, Map<String, Object> map) {
+        String sb = readXML(prop);
+        if (sb == null) {
+            return false;
+        }
+
+        String name = prop.getAttributeValue(PROPERTY_NAME_ATTRIBUTE);
+        map.put(name, sb);
+        return true;
+    }
+
+    @SuppressWarnings("unchecked")
+    private static String readXML(Element prop) {
+        Element el = prop.getChild("xml", Namespace.getNamespace(REMOTE_SERVICES_ADMIN_NS));
+        if (el == null) {
+            return null;
+        }
+
+        String type = getTypeName(prop);
+        if (!"String".equals(type)) {
+            LOG.warn("Embedded XML must be of type String, found: " + type);
+            return null;
+        }
+
+        XMLOutputter outputter = new XMLOutputter(Format.getCompactFormat());
+        StringBuilder sb = new StringBuilder();
+        List<Element> children = el.getChildren();
+        for (Element child : children) {
+            sb.append(outputter.outputString(child));
+        }
+        return sb.toString();
+    }
+
+    private static Object handleValue(Element val, String type) {
+        String xml = readXML(val);
+        return xml != null ? xml : instantiate(type, val.getText());
+    }
+
+    private static Object instantiate(String type, String value) {
+        if ("String".equals(type)) {
+            return value;
+        }
+
+        value = value.trim();
+        String boxedType = null;
+        if ("long".equals(type)) {
+            boxedType = "Long";
+        } else if ("double".equals(type)) {
+            boxedType = "Double";
+        } else if ("float".equals(type)) {
+            boxedType = "Float";
+        } else if ("int".equals(type)) {
+            boxedType = "Integer";
+        } else if ("byte".equals(type)) {
+            boxedType = "Byte";
+        } else if ("char".equals(type)) {
+            boxedType = "Character";
+        } else if ("boolean".equals(type)) {
+            boxedType = "Boolean";
+        } else if ("short".equals(type)) {
+            boxedType = "Short";
+        }
+
+        if (boxedType == null) {
+            boxedType = type;
+        }
+        String javaType = "java.lang." + boxedType;
+
+        try {
+            if ("Character".equals(boxedType)) {
+                return new Character(value.charAt(0));
+            } else {
+                Class<?> cls = ClassLoader.getSystemClassLoader().loadClass(javaType);
+                Constructor<?> ctor = cls.getConstructor(String.class);
+                return ctor.newInstance(value);
+            }
+        } catch (Exception e) {
+            LOG.warn("Could not create Endpoint Property of type " + type + " and value " + value);
+            return null;
+        }
+    }
+
+    static List<Element> getAllDescriptionElements(Bundle b) {
+        Object header = null;
+
+        Dictionary<?, ?> headers = b.getHeaders();
+        if (headers != null) {
+            header = headers.get(REMOTE_SERVICES_HEADER_NAME);
+        }
+
+        if (header == null) {
+            header = REMOTE_SERVICES_DIRECTORY;
+        }
+
+        String dir = header.toString();
+        String filePattern = "*.xml";
+        if (dir.endsWith("/")) {
+            dir = dir.substring(0, dir.length() - 1);
+        } else {
+            int idx = dir.lastIndexOf('/');
+            if (idx >= 0 & dir.length() > idx) {
+                filePattern = dir.substring(idx + 1);
+                dir = dir.substring(0, idx);
+            } else {
+                filePattern = dir;
+                dir = "";
+            }
+        }
+
+        Enumeration<?> urls = b.findEntries(dir, filePattern, false);
+        if (urls == null) {
+            return Collections.emptyList();
+        }
+
+        List<Element> elements = new ArrayList<Element>();
+        while (urls.hasMoreElements()) {
+            URL resourceURL = (URL) urls.nextElement();
+            try {
+                elements.addAll(getElements(resourceURL.openStream()));
+            } catch (Exception ex) {
+                LOG.warn("Problem parsing: " + resourceURL, ex);
+            }
+        }
+        return elements;
+    }
+
+    private static Map<String, Object> getProperties(List<Element> elements) {
+        Map<String, Object> props = new HashMap<String, Object>();
+
+        for (Element p : elements) {
+            String key = p.getAttributeValue(PROPERTY_NAME_ATTRIBUTE);
+            String value = p.getAttributeValue(PROPERTY_VALUE_ATTRIBUTE);
+            if (value == null) {
+                value = p.getTextTrim();
+            }
+
+            String iface = p.getAttributeValue(PROPERTY_INTERFACE_ATTRIBUTE);
+            if (key != null) {
+                props.put(iface == null || iface.isEmpty()
+                          ? key
+                          : key + INTERFACE_SEPARATOR + iface,
+                          value);
+            }
+        }
+
+        return props;
+    }
+
+    private static List<String> getProvidedInterfaces(List<Element> elements) {
+        List<String> names = new ArrayList<String>();
+
+        for (Element p : elements) {
+            String name = p.getAttributeValue(PROVIDE_INTERFACE_NAME_ATTRIBUTE);
+            if (name != null) {
+                names.add(name);
+            }
+        }
+
+        return names;
+    }
+
+    public static String getEndpointDescriptionXML(Map<String, Object> m) {
+        Document d = new Document();
+        Namespace ns = Namespace.getNamespace("http://www.osgi.org/xmlns/rsa/v1.0.0");
+        Element rootEl = new Element("endpoint-descriptions", ns);
+        d.setRootElement(rootEl);
+        Element contentEl = new Element("endpoint-description", ns);
+        rootEl.addContent(contentEl);
+
+        for (Map.Entry<String, Object> entry : m.entrySet()) {
+            String key = entry.getKey();
+            Object val = entry.getValue();
+
+            Element propEl = new Element("property", ns);
+            propEl.setAttribute("name", key);
+            if (val.getClass().isArray()) {
+                Element arrayEl = new Element("array", ns);
+                propEl.addContent(arrayEl);
+                for (Object o : normalizeArray(val)) {
+                    setValueType(propEl, o);
+                    Element valueEl = new Element("value", ns);
+                    arrayEl.addContent(valueEl);
+                    valueEl.addContent(o.toString());
+                }
+            } else if (val instanceof List) {
+                Element listEl = new Element("list", ns);
+                propEl.addContent(listEl);
+                handleCollectionValue(ns, (Collection<?>) val, propEl, listEl);
+            } else if (val instanceof Set) {
+                Element setEl = new Element("set", ns);
+                propEl.addContent(setEl);
+                handleCollectionValue(ns, (Collection<?>) val, propEl, setEl);
+            } else if (val instanceof String
+                    || val instanceof Character
+                    || val instanceof Boolean
+                    || val instanceof Byte) {
+                setValueType(propEl, val);
+                propEl.setAttribute("value", val.toString());
+            } else if (val instanceof Long
+                    || val instanceof Double
+                    || val instanceof Float
+                    || val instanceof Integer
+                    || val instanceof Short) {
+                // various numbers..   maybe "val instanceof Number"?
+                setValueType(propEl, val);
+                propEl.setAttribute("value", val.toString());
+            } else {
+                // Don't add this property as the value type is not supported
+                continue;
+            }
+            contentEl.addContent(propEl);
+        }
+
+        return new XMLOutputter(Format.getPrettyFormat()).outputString(d);
+    }
+
+    private static Object[] normalizeArray(Object val) {
+        List<Object> l = new ArrayList<Object>();
+        if (val instanceof int[]) {
+            int[] ia = (int[]) val;
+            for (int i : ia) {
+                l.add(i);
+            }
+        } else if (val instanceof long[]) {
+            long[] la = (long[]) val;
+            for (long i : la) {
+                l.add(i);
+            }
+        } else if (val instanceof float[]) {
+            float[] fa = (float[]) val;
+            for (float f : fa) {
+                l.add(f);
+            }
+        } else if (val instanceof byte[]) {
+            byte[] ba = (byte[]) val;
+            for (byte b : ba) {
+                l.add(b);
+            }
+        } else if (val instanceof boolean[]) {
+            boolean[] ba = (boolean[]) val;
+            for (boolean b : ba) {
+                l.add(b);
+            }
+        } else if (val instanceof short[]) {
+            short[] sa = (short[]) val;
+            for (short s : sa) {
+                l.add(s);
+            }
+        } else if (val instanceof char[]) {
+            char[] ca = (char[]) val;
+            for (char c : ca) {
+                l.add(c);
+            }
+        } else {
+            return (Object[]) val;
+        }
+        return l.toArray();
+    }
+
+    private static void handleCollectionValue(Namespace ns, Collection<?> val, Element propEl, Element listEl) {
+        for (Object o : val) {
+            setValueType(propEl, o);
+            Element valueEl = new Element("value", ns);
+            listEl.addContent(valueEl);
+            valueEl.addContent(o.toString());
+        }
+    }
+
+    private static void setValueType(Element propEl, Object val) {
+        if (val instanceof String) {
+            return;
+        }
+
+        String dataType = val.getClass().getName();
+        if (dataType.startsWith("java.lang.")) {
+            dataType = dataType.substring("java.lang.".length());
+        }
+        propEl.setAttribute("value-type", dataType);
+    }
+
+    @SuppressWarnings("unchecked")
+    private static List<Element> getElements(InputStream in) throws JDOMException, IOException {
+        List<Element> elements = new ArrayList<Element>();
+
+        Document d = new SAXBuilder().build(in);
+        if (d.getRootElement().getNamespaceURI().equals(REMOTE_SERVICES_ADMIN_NS)) {
+            elements.addAll(d.getRootElement().getChildren(ENDPOINT_DESCRIPTION_ELEMENT,
+                                                           Namespace.getNamespace(REMOTE_SERVICES_ADMIN_NS)));
+        }
+
+        Namespace nsOld = Namespace.getNamespace(REMOTE_SERVICES_NS);
+        elements.addAll(d.getRootElement().getChildren(SERVICE_DESCRIPTION_ELEMENT, nsOld));
+
+        return elements;
+    }
+
+    public static EndpointDescription getFirstEnpointDescription(byte[] data) throws JDOMException, IOException {
+        List<Element> elements = getElements(new ByteArrayInputStream(data));
+        return elements.isEmpty() ? null : getEndpointDescription(elements.get(0));
+    }
+}

Added: cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/util/Utils.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/util/Utils.java?rev=1491995&view=auto
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/util/Utils.java (added)
+++ cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/util/Utils.java Tue Jun 11 22:29:27 2013
@@ -0,0 +1,92 @@
+/**
+ * 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.discovery.local.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.remoteserviceadmin.EndpointDescription;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class Utils {
+
+    private static final Logger LOG = LoggerFactory.getLogger(Utils.class);
+
+    private Utils() {
+        // prevent instantiation
+    }
+
+    public static List<String> getStringPlusProperty(ServiceReference sr, String key) {
+        Object value = sr.getProperty(key);
+        if (value == null) {
+            return Collections.emptyList();
+        }
+
+        if (value instanceof String) {
+            return Collections.singletonList((String) value);
+        }
+
+        if (value instanceof String[]) {
+            String[] values = (String[]) value;
+            List<String> result = new ArrayList<String>(values.length);
+            for (String v : values) {
+                if (v != null) {
+                    result.add(v);
+                }
+            }
+            return Collections.unmodifiableList(result);
+        }
+
+        if (value instanceof Collection<?>) {
+            Collection<?> values = (Collection<?>) value;
+            List<String> result = new ArrayList<String>(values.size());
+            for (Object v : values) {
+                if (v instanceof String) {
+                    result.add((String) v);
+                }
+            }
+            return Collections.unmodifiableList(result);
+        }
+
+        return Collections.emptyList();
+    }
+
+    public static boolean matchFilter(BundleContext bctx, String filter, EndpointDescription endpoint) {
+        if (filter == null) {
+            return false;
+        }
+
+        try {
+            Filter f = bctx.createFilter(filter);
+            Dictionary<String, Object> dict = new Hashtable<String, Object>(endpoint.getProperties());
+            return f.match(dict);
+        } catch (Exception e) {
+            LOG.error("Problem creating a Filter from " + filter, e);
+            return false;
+        }
+    }
+}

Copied: cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/util/EndpointUtilsTest.java (from r1491250, cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtilsTest.java)
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/util/EndpointUtilsTest.java?p2=cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/util/EndpointUtilsTest.java&p1=cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtilsTest.java&r1=1491250&r2=1491995&rev=1491995&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtilsTest.java (original)
+++ cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/util/EndpointUtilsTest.java Tue Jun 11 22:29:27 2013
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.cxf.dosgi.discovery.local;
+package org.apache.cxf.dosgi.discovery.local.util;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -48,7 +48,7 @@ import org.osgi.framework.Bundle;
 import org.osgi.service.remoteserviceadmin.EndpointDescription;
 import org.osgi.service.remoteserviceadmin.RemoteConstants;
 
-public class LocalDiscoveryUtilsTest extends TestCase {
+public class EndpointUtilsTest extends TestCase {
 
     private static final String LF = "\n";
 
@@ -56,7 +56,7 @@ public class LocalDiscoveryUtilsTest ext
         Bundle b = EasyMock.createNiceMock(Bundle.class);
         EasyMock.replay(b);
 
-        List<Element> rsElements = LocalDiscoveryUtils.getAllDescriptionElements(b);
+        List<Element> rsElements = EndpointUtils.getAllDescriptionElements(b);
         assertEquals(0, rsElements.size());
     }
 
@@ -70,7 +70,7 @@ public class LocalDiscoveryUtilsTest ext
                 Collections.enumeration(Arrays.asList(ed1URL))).anyTimes();
         EasyMock.replay(b);
 
-        List<Element> edElements = LocalDiscoveryUtils.getAllDescriptionElements(b);
+        List<Element> edElements = EndpointUtils.getAllDescriptionElements(b);
         assertEquals(4, edElements.size());
     }
 
@@ -84,7 +84,7 @@ public class LocalDiscoveryUtilsTest ext
                 Collections.enumeration(Arrays.asList(ed1URL))).anyTimes();
         EasyMock.replay(b);
 
-        List<EndpointDescription> eds = LocalDiscoveryUtils.getAllEndpointDescriptions(b);
+        List<EndpointDescription> eds = EndpointUtils.getAllEndpointDescriptions(b);
         assertEquals(4, eds.size());
         EndpointDescription ed0 = eds.get(0);
         assertEquals("http://somewhere:12345", ed0.getId());
@@ -116,7 +116,7 @@ public class LocalDiscoveryUtilsTest ext
                 Collections.enumeration(Arrays.asList(ed2URL))).anyTimes();
         EasyMock.replay(b);
 
-        List<EndpointDescription> eds = LocalDiscoveryUtils.getAllEndpointDescriptions(b);
+        List<EndpointDescription> eds = EndpointUtils.getAllEndpointDescriptions(b);
         assertEquals(2, eds.size());
         EndpointDescription ed0 = eds.get(0);
         assertEquals("foo:bar", ed0.getId());
@@ -183,7 +183,7 @@ public class LocalDiscoveryUtilsTest ext
                 Collections.enumeration(Arrays.asList(sdURL))).anyTimes();
         EasyMock.replay(b);
 
-        List<EndpointDescription> eds = LocalDiscoveryUtils.getAllEndpointDescriptions(b);
+        List<EndpointDescription> eds = EndpointUtils.getAllEndpointDescriptions(b);
         assertEquals(1, eds.size());
         EndpointDescription ed = eds.get(0);
         assertEquals("http://localhost:9090/greeter", ed.getId());
@@ -205,7 +205,7 @@ public class LocalDiscoveryUtilsTest ext
                 Collections.enumeration(Arrays.asList(sdURL))).anyTimes();
         EasyMock.replay(b);
 
-        List<EndpointDescription> eds = LocalDiscoveryUtils.getAllEndpointDescriptions(b);
+        List<EndpointDescription> eds = EndpointUtils.getAllEndpointDescriptions(b);
         assertEquals(2, eds.size());
 
         EndpointDescription ed0 = eds.get(0);
@@ -263,7 +263,7 @@ public class LocalDiscoveryUtilsTest ext
             + "</xml>";
         m.put("someXML", xml);
 
-        String actual = LocalDiscoveryUtils.getEndpointDescriptionXML(m);
+        String actual = EndpointUtils.getEndpointDescriptionXML(m);
 
         URL edURL = getClass().getResource("/ed2-generated.xml");
         String expected = new String(drainStream(edURL.openStream()));

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java?rev=1491995&r1=1491994&r2=1491995&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java Tue Jun 11 22:29:27 2013
@@ -20,8 +20,6 @@ package org.apache.cxf.dosgi.dsw;
 
 import java.util.ArrayList;
 import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
@@ -39,6 +37,7 @@ import org.apache.cxf.dosgi.dsw.qos.Inte
 import org.apache.cxf.dosgi.dsw.qos.IntentTracker;
 import org.apache.cxf.dosgi.dsw.service.RemoteServiceAdminCore;
 import org.apache.cxf.dosgi.dsw.service.RemoteServiceadminFactory;
+import org.apache.cxf.dosgi.dsw.util.Utils;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
@@ -151,20 +150,8 @@ public class Activator implements Manage
             } catch (Exception e) {
                 LOG.error(e.getMessage(), e);
             }
-            init(getMapFromDictionary(config));
+            init(Utils.toMap(config));
         }
     }
 
-    private Map<String, Object> getMapFromDictionary(Dictionary<String, Object> config) {
-        Map<String, Object> configMap = new HashMap<String, Object>();
-        if (config == null) {
-            return configMap;
-        }
-        Enumeration<String> keys = config.keys();
-        while (keys.hasMoreElements()) {
-            String key = keys.nextElement();
-            configMap.put(key, config.get(key));
-        }
-        return configMap;
-    }
 }

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java?rev=1491995&r1=1491994&r2=1491995&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java Tue Jun 11 22:29:27 2013
@@ -32,6 +32,8 @@ import org.osgi.service.remoteserviceadm
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.apache.cxf.dosgi.dsw.util.Utils.setIfNotNull;
+
 public class EventAdminHelper {
 
     private static final Logger LOG = LoggerFactory.getLogger(EventAdminHelper.class);
@@ -85,13 +87,6 @@ public class EventAdminHelper {
         notifyEventAdmins(topic, event);
     }
 
-    @SuppressWarnings({ "rawtypes", "unchecked" })
-    private static void setIfNotNull(Dictionary props, String key, Object o) {
-        if (o != null) {
-            props.put(key, o);
-        }
-    }
-
     private void notifyEventAdmins(String topic, Event event) {
         ServiceReference[] refs = null;
         try {

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java?rev=1491995&r1=1491994&r2=1491995&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java Tue Jun 11 22:29:27 2013
@@ -77,7 +77,7 @@ public class RemoteServiceAdminCore impl
     @SuppressWarnings({ "rawtypes", "unchecked" })
     public List<ExportRegistration> exportService(ServiceReference serviceReference, Map additionalProperties)
         throws IllegalArgumentException, UnsupportedOperationException {
-        Map<String, Object> serviceProperties = getProperties(serviceReference);
+        Map<String, Object> serviceProperties = OsgiUtils.getProperties(serviceReference);
         if (additionalProperties != null) {
             OsgiUtils.overlayProperties(serviceProperties, additionalProperties);
         }
@@ -215,22 +215,6 @@ public class RemoteServiceAdminCore impl
     }
 
     /**
-     * Returns a service's properties as a map.
-     *
-     * @param serviceReference a service reference
-     * @return the service's properties as a map
-     */
-    private Map<String, Object> getProperties(ServiceReference serviceReference) {
-        String[] keys = serviceReference.getPropertyKeys();
-        Map<String, Object> props = new HashMap<String, Object>(keys.length);
-        for (String key : keys) {
-            Object val = serviceReference.getProperty(key);
-            props.put(key, val);
-        }
-        return props;
-    }
-
-    /**
      * Converts the given properties map into one that can be used as a map key itself.
      * For example, if a value is an array, it is converted into a list so that the
      * equals method will compare it properly.

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminInstance.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminInstance.java?rev=1491995&r1=1491994&r2=1491995&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminInstance.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminInstance.java Tue Jun 11 22:29:27 2013
@@ -34,6 +34,8 @@ import org.osgi.service.remoteserviceadm
 import org.osgi.service.remoteserviceadmin.ImportRegistration;
 import org.osgi.service.remoteserviceadmin.RemoteServiceAdmin;
 
+import static org.apache.cxf.dosgi.dsw.util.OsgiUtils.checkPermission;
+
 public class RemoteServiceAdminInstance implements RemoteServiceAdmin {
 
     private final BundleContext bctx;
@@ -47,14 +49,8 @@ public class RemoteServiceAdminInstance 
     }
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
-    public List /* ExportRegistration */exportService(final ServiceReference ref, final Map properties)
-        throws IllegalArgumentException, UnsupportedOperationException {
-        SecurityManager sm = System.getSecurityManager();
-        if (sm != null) {
-            EndpointPermission epp = new EndpointPermission("*", EndpointPermission.EXPORT);
-            sm.checkPermission(epp);
-        }
-
+    public List /* ExportRegistration */exportService(final ServiceReference ref, final Map properties) {
+        checkPermission(new EndpointPermission("*", EndpointPermission.EXPORT));
         return AccessController.doPrivileged(new PrivilegedAction<List>() {
             public List<ExportRegistration> run() {
                 return closed ? Collections.<ExportRegistration>emptyList() : rsaCore.exportService(ref, properties);
@@ -64,37 +60,21 @@ public class RemoteServiceAdminInstance 
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
     public Collection getExportedServices() {
-        SecurityManager sm = System.getSecurityManager();
-        EndpointPermission epp = new EndpointPermission("*", EndpointPermission.READ);
-        if (sm != null) {
-            sm.checkPermission(epp);
-        }
-
+        checkPermission(new EndpointPermission("*", EndpointPermission.READ));
         return closed ? null : rsaCore.getExportedServices();
     }
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
     public Collection getImportedEndpoints() {
-        SecurityManager sm = System.getSecurityManager();
-        EndpointPermission epp = new EndpointPermission("*", EndpointPermission.READ);
-        if (sm != null) {
-            sm.checkPermission(epp);
-        }
-
+        checkPermission(new EndpointPermission("*", EndpointPermission.READ));
         return closed ? null : rsaCore.getImportedEndpoints();
     }
 
-    public ImportRegistration importService(EndpointDescription endpoint) {
-        final EndpointDescription epd = endpoint;
-        SecurityManager sm = System.getSecurityManager();
-        EndpointPermission epp = new EndpointPermission(epd, OsgiUtils.getUUID(bctx), EndpointPermission.IMPORT);
-        if (sm != null) {
-            sm.checkPermission(epp);
-        }
-
+    public ImportRegistration importService(final EndpointDescription endpoint) {
+        checkPermission(new EndpointPermission(endpoint, OsgiUtils.getUUID(bctx), EndpointPermission.IMPORT));
         return AccessController.doPrivileged(new PrivilegedAction<ImportRegistration>() {
             public ImportRegistration run() {
-                return closed ? null : rsaCore.importService(epd);
+                return closed ? null : rsaCore.importService(endpoint);
             }
         });
     }

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=1491995&r1=1491994&r2=1491995&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 Tue Jun 11 22:29:27 2013
@@ -63,14 +63,10 @@ public final class ClassUtils {
     }
 
     /**
-     * <pre>
-     *
-     * The following method tries to deal specifically with classes that might have been proxied
+     * This method tries to deal specifically with classes that might have been proxied
      * eg. CGLIB proxies of which there might be a chain of proxies as different osgi frameworks
      * might be proxying the original service class that has been registered and then proxying the proxy.
      *
-     * </pre>
-     *
      * @param serviceClass
      * @param interfaceName
      * @return

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java?rev=1491995&r1=1491994&r2=1491995&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java Tue Jun 11 22:29:27 2013
@@ -31,6 +31,7 @@ import org.osgi.framework.ServiceReferen
 import org.osgi.service.packageadmin.ExportedPackage;
 import org.osgi.service.packageadmin.PackageAdmin;
 import org.osgi.service.remoteserviceadmin.EndpointDescription;
+import org.osgi.service.remoteserviceadmin.EndpointPermission;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -173,4 +174,27 @@ public final class OsgiUtils {
             }
         }
     }
+
+    /**
+     * Returns a service's properties as a map.
+     *
+     * @param serviceReference a service reference
+     * @return the service's properties as a map
+     */
+    public static Map<String, Object> getProperties(ServiceReference serviceReference) {
+        String[] keys = serviceReference.getPropertyKeys();
+        Map<String, Object> props = new HashMap<String, Object>(keys.length);
+        for (String key : keys) {
+            Object val = serviceReference.getProperty(key);
+            props.put(key, val);
+        }
+        return props;
+    }
+
+    public static void checkPermission(EndpointPermission permission) {
+        SecurityManager sm = System.getSecurityManager();
+        if (sm != null) {
+            sm.checkPermission(permission);
+        }
+    }
 }

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/Utils.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/Utils.java?rev=1491995&r1=1491994&r2=1491995&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/Utils.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/Utils.java Tue Jun 11 22:29:27 2013
@@ -20,7 +20,11 @@ package org.apache.cxf.dosgi.dsw.util;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -28,6 +32,7 @@ import org.slf4j.LoggerFactory;
 public final class Utils {
 
     private static final Logger LOG = LoggerFactory.getLogger(Utils.class);
+
     private Utils() {
         // never constructed
     }
@@ -67,4 +72,24 @@ public final class Utils {
 
         return null;
     }
+
+    public static <K, V> Map<K, V> toMap(Dictionary<K, V> dict) {
+        Map<K, V> map = new HashMap<K, V>();
+        if (dict == null) {
+            return map;
+        }
+        Enumeration<K> keys = dict.keys();
+        while (keys.hasMoreElements()) {
+            K key = keys.nextElement();
+            map.put(key, dict.get(key));
+        }
+        return map;
+    }
+
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    public static void setIfNotNull(Dictionary dict, String key, Object val) {
+        if (val != null) {
+            dict.put(key, val);
+        }
+    }
 }

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=1491995&r1=1491994&r2=1491995&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 Tue Jun 11 22:29:27 2013
@@ -21,9 +21,9 @@ package org.apache.cxf.dosgi.topologyman
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Dictionary;
-import java.util.Hashtable;
 import java.util.List;
 
+import org.apache.cxf.dosgi.topologymanager.util.Utils;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.Filter;
@@ -156,33 +156,18 @@ public class EndpointListenerNotifier {
         return filters;
     }
 
-    private List<Filter> getMatchingFilters(List<Filter> filters,
-            EndpointDescription endpoint) {
+    private static List<Filter> getMatchingFilters(List<Filter> filters, EndpointDescription endpoint) {
         List<Filter> matchingFilters = new ArrayList<Filter>();
-        Dictionary<String, Object> d = getEndpointProperties(endpoint);
+        Dictionary<String, Object> dict = Utils.getEndpointProperties(endpoint);
 
         for (Filter filter : filters) {
-            if (filter.match(d)) {
-                LOG.debug("Filter {} matches endpoint {}", filter, d);
+            if (filter.match(dict)) {
+                LOG.debug("Filter {} matches endpoint {}", filter, dict);
                 matchingFilters.add(filter);
             } else {
-                LOG.debug("Filter {} does not match endpoint {}", filter, d);
+                LOG.debug("Filter {} does not match endpoint {}", filter, dict);
             }
         }
         return matchingFilters;
     }
-
-    /**
-     * Retrieves an endpoint's properties as a Dictionary.
-     *
-     * @param ep an endpoint description
-     * @return endpoint properties (will never return null)
-     */
-    private Dictionary<String, Object> getEndpointProperties(EndpointDescription ep) {
-        if (ep == null || ep.getProperties() == null) {
-            return new Hashtable<String, Object>();
-        } else {
-            return new Hashtable<String, Object>(ep.getProperties());
-        }
-    }
 }

Modified: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/ListenerHookImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/ListenerHookImpl.java?rev=1491995&r1=1491994&r2=1491995&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/ListenerHookImpl.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/ListenerHookImpl.java Tue Jun 11 22:29:27 2013
@@ -21,12 +21,9 @@ package org.apache.cxf.dosgi.topologyman
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Set;
-import java.util.UUID;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 
+import org.apache.cxf.dosgi.topologymanager.util.Utils;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
 import org.osgi.framework.hooks.service.ListenerHook;
 import org.osgi.service.remoteserviceadmin.RemoteConstants;
 import org.slf4j.Logger;
@@ -40,10 +37,6 @@ public class ListenerHookImpl implements
 
     private static final Logger LOG = LoggerFactory.getLogger(ListenerHookImpl.class);
 
-    private static final String CLASS_NAME_EXPRESSION = ".*\\(" + Constants.OBJECTCLASS
-                                                        + "=([a-zA-Z_0-9.]+)\\).*";
-    private static final Pattern CLASS_NAME_PATTERN = Pattern.compile(CLASS_NAME_EXPRESSION);
-
     // From the old impl.
     private static final Set<String> SYSTEM_PACKAGES;
     static {
@@ -72,7 +65,7 @@ public class ListenerHookImpl implements
             ListenerInfo listenerInfo = (ListenerInfo)li;
             LOG.debug("Filter {}", listenerInfo.getFilter());
 
-            String className = getClassNameFromFilter(listenerInfo.getFilter());
+            String className = Utils.getObjectClass(listenerInfo.getFilter());
 
             if (listenerInfo.getBundleContext().getBundle().equals(bctx.getBundle())) {
                 LOG.debug("ListenerHookImpl: skipping request from myself");
@@ -107,16 +100,6 @@ public class ListenerHookImpl implements
         }
     }
 
-    private static String getClassNameFromFilter(String filter) {
-        if (filter != null) {
-            Matcher matcher = CLASS_NAME_PATTERN.matcher(filter);
-            if (matcher.matches() && matcher.groupCount() >= 1) {
-                return matcher.group(1);
-            }
-        }
-        return null;
-    }
-
     private static boolean isClassExcluded(String className) {
         if (className == null) {
             return true;
@@ -130,18 +113,7 @@ public class ListenerHookImpl implements
         return false;
     }
 
-    static String getUUID(BundleContext bctx) {
-        synchronized ("org.osgi.framework.uuid") {
-            String uuid = bctx.getProperty("org.osgi.framework.uuid");
-            if (uuid == null) {
-                uuid = UUID.randomUUID().toString();
-                System.setProperty("org.osgi.framework.uuid", uuid);
-            }
-            return uuid;
-        }
-    }
-
     static String extendFilter(String filter, BundleContext bctx) {
-        return "(&" + filter + "(!(" + RemoteConstants.ENDPOINT_FRAMEWORK_UUID + "=" + getUUID(bctx) + ")))";
+        return "(&" + filter + "(!(" + RemoteConstants.ENDPOINT_FRAMEWORK_UUID + "=" + Utils.getUUID(bctx) + ")))";
     }
 }

Modified: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/TopologyManagerImport.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/TopologyManagerImport.java?rev=1491995&r1=1491994&r2=1491995&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/TopologyManagerImport.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/TopologyManagerImport.java Tue Jun 11 22:29:27 2013
@@ -30,6 +30,7 @@ import java.util.concurrent.LinkedBlocki
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.cxf.dosgi.topologymanager.util.ReferenceCounter;
 import org.apache.cxf.dosgi.topologymanager.util.SimpleServiceTracker;
 import org.apache.cxf.dosgi.topologymanager.util.SimpleServiceTrackerListener;
 import org.osgi.framework.BundleContext;

Copied: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/util/ReferenceCounter.java (from r1491250, cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/ReferenceCounter.java)
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/util/ReferenceCounter.java?p2=cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/util/ReferenceCounter.java&p1=cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/ReferenceCounter.java&r1=1491250&r2=1491995&rev=1491995&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/ReferenceCounter.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/util/ReferenceCounter.java Tue Jun 11 22:29:27 2013
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.cxf.dosgi.topologymanager.importer;
+package org.apache.cxf.dosgi.topologymanager.util;
 
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;

Added: 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=1491995&view=auto
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/util/Utils.java (added)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/util/Utils.java Tue Jun 11 22:29:27 2013
@@ -0,0 +1,74 @@
+/**
+ * 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.topologymanager.util;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.UUID;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.service.remoteserviceadmin.EndpointDescription;
+
+public final class Utils {
+
+    private static final String OBJECTCLASS_EXPRESSION = ".*\\(" + Constants.OBJECTCLASS + "=([a-zA-Z_0-9.]+)\\).*";
+    private static final Pattern OBJECTCLASS_PATTERN = Pattern.compile(OBJECTCLASS_EXPRESSION);
+
+    private Utils() {
+        // prevent instantiation
+    }
+
+    /**
+     * Retrieves an endpoint's properties as a Dictionary.
+     *
+     * @param ep an endpoint description
+     * @return endpoint properties (will never return null)
+     */
+    public static Dictionary<String, Object> getEndpointProperties(EndpointDescription ep) {
+        if (ep == null || ep.getProperties() == null) {
+            return new Hashtable<String, Object>();
+        } else {
+            return new Hashtable<String, Object>(ep.getProperties());
+        }
+    }
+
+    public static String getObjectClass(String filter) {
+        if (filter != null) {
+            Matcher matcher = OBJECTCLASS_PATTERN.matcher(filter);
+            if (matcher.matches() && matcher.groupCount() >= 1) {
+                return matcher.group(1);
+            }
+        }
+        return null;
+    }
+
+    public static String getUUID(BundleContext bctx) {
+        synchronized ("org.osgi.framework.uuid") {
+            String uuid = bctx.getProperty("org.osgi.framework.uuid");
+            if (uuid == null) {
+                uuid = UUID.randomUUID().toString();
+                System.setProperty("org.osgi.framework.uuid", uuid);
+            }
+            return uuid;
+        }
+    }
+}

Modified: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/importer/ListenerHookImplTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/importer/ListenerHookImplTest.java?rev=1491995&r1=1491994&r2=1491995&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/importer/ListenerHookImplTest.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/importer/ListenerHookImplTest.java Tue Jun 11 22:29:27 2013
@@ -29,39 +29,12 @@ import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.service.remoteserviceadmin.RemoteConstants;
 
-import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 public class ListenerHookImplTest {
 
     @Test
-    public void testGetNewUUID() {
-        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
-        EasyMock.expect(bc.getProperty(EasyMock.eq("org.osgi.framework.uuid"))).andReturn(null).atLeastOnce();
-        EasyMock.replay(bc);
-        String uuid = ListenerHookImpl.getUUID(bc);
-        assertNotNull(uuid);
-
-        assertEquals(System.getProperty("org.osgi.framework.uuid"), uuid);
-
-        EasyMock.verify(bc);
-    }
-
-    @Test
-    public void testGetExistingUUID() {
-        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
-        EasyMock.expect(bc.getProperty(EasyMock.eq("org.osgi.framework.uuid"))).andReturn("MyUUID").atLeastOnce();
-        EasyMock.replay(bc);
-        String uuid = ListenerHookImpl.getUUID(bc);
-
-        assertEquals("MyUUID", uuid);
-
-        EasyMock.verify(bc);
-    }
-
-    @Test
     public void testUUIDFilterExtension() throws InvalidSyntaxException {
         String filter = "(a=b)";
 

Copied: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/util/ReferenceCounterTest.java (from r1491250, cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/importer/ReferenceCounterTest.java)
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/util/ReferenceCounterTest.java?p2=cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/util/ReferenceCounterTest.java&p1=cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/importer/ReferenceCounterTest.java&r1=1491250&r2=1491995&rev=1491995&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/importer/ReferenceCounterTest.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/util/ReferenceCounterTest.java Tue Jun 11 22:29:27 2013
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.cxf.dosgi.topologymanager.importer;
+package org.apache.cxf.dosgi.topologymanager.util;
 
 import org.junit.Test;
 

Copied: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/util/UtilsTest.java (from r1491250, cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/importer/ListenerHookImplTest.java)
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/util/UtilsTest.java?p2=cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/util/UtilsTest.java&p1=cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/importer/ListenerHookImplTest.java&r1=1491250&r2=1491995&rev=1491995&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/importer/ListenerHookImplTest.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/util/UtilsTest.java Tue Jun 11 22:29:27 2013
@@ -16,32 +16,23 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.cxf.dosgi.topologymanager.importer;
-
-import java.util.Dictionary;
-import java.util.Hashtable;
+package org.apache.cxf.dosgi.topologymanager.util;
 
 import org.easymock.classextension.EasyMock;
 import org.junit.Test;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.Filter;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.service.remoteserviceadmin.RemoteConstants;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
 
-public class ListenerHookImplTest {
+public class UtilsTest {
 
     @Test
     public void testGetNewUUID() {
         BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
         EasyMock.expect(bc.getProperty(EasyMock.eq("org.osgi.framework.uuid"))).andReturn(null).atLeastOnce();
         EasyMock.replay(bc);
-        String uuid = ListenerHookImpl.getUUID(bc);
+        String uuid = Utils.getUUID(bc);
         assertNotNull(uuid);
 
         assertEquals(System.getProperty("org.osgi.framework.uuid"), uuid);
@@ -54,30 +45,10 @@ public class ListenerHookImplTest {
         BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
         EasyMock.expect(bc.getProperty(EasyMock.eq("org.osgi.framework.uuid"))).andReturn("MyUUID").atLeastOnce();
         EasyMock.replay(bc);
-        String uuid = ListenerHookImpl.getUUID(bc);
+        String uuid = Utils.getUUID(bc);
 
         assertEquals("MyUUID", uuid);
 
         EasyMock.verify(bc);
     }
-
-    @Test
-    public void testUUIDFilterExtension() throws InvalidSyntaxException {
-        String filter = "(a=b)";
-
-        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
-        EasyMock.expect(bc.getProperty(EasyMock.eq("org.osgi.framework.uuid"))).andReturn("MyUUID").atLeastOnce();
-        EasyMock.replay(bc);
-
-        filter = ListenerHookImpl.extendFilter(filter, bc);
-
-        Filter f = FrameworkUtil.createFilter(filter);
-
-        Dictionary<String, String> m = new Hashtable<String, String>();
-        m.put("a", "b");
-
-        assertTrue(filter + " filter must match as uuid is missing", f.match(m));
-        m.put(RemoteConstants.ENDPOINT_FRAMEWORK_UUID, "MyUUID");
-        assertFalse(filter + " filter must NOT match as uuid is the local one", f.match(m));
-    }
 }