You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by cs...@apache.org on 2013/08/15 22:40:30 UTC

svn commit: r1514476 [1/2] - in /cxf/dosgi/trunk: discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/publish/ discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/subscribe/ ...

Author: cschneider
Date: Thu Aug 15 20:40:29 2013
New Revision: 1514476

URL: http://svn.apache.org/r1514476
Log:
DOSGI-202 Make DOSGi independent of jdom

Added:
    cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/endpointdesc/
    cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionBundleParser.java
      - copied, changed from r1512459, cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/util/EndpointUtils.java
    cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionParser.java   (with props)
    cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/endpointdesc/PropertiesMapper.java   (with props)
    cxf/dosgi/trunk/discovery/local/src/main/resources/
    cxf/dosgi/trunk/discovery/local/src/main/resources/endpoint-description.xsd   (with props)
    cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/endpointdesc/
      - copied from r1514466, cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/util/
    cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionBundleParserTest.java
      - copied, changed from r1514466, cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/util/EndpointUtilsTest.java
    cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionParserTest.java   (with props)
    cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/endpointdesc/PropertiesMapperTest.java   (with props)
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/DecorationParser.java   (with props)
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/resources/service-decoration.xsd   (with props)
    cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/DecorationParserTest.java   (with props)
Removed:
    cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/util/EndpointUtils.java
    cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/util/
    cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/endpointdesc/EndpointUtilsTest.java
    cxf/dosgi/trunk/distribution/multi-bundle/src/main/resources/META-INF/
Modified:
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/publish/PublishingEndpointListener.java
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/subscribe/InterfaceMonitor.java
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/publish/PublishingEndpointListenerTest.java
    cxf/dosgi/trunk/discovery/local/pom.xml
    cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java
    cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/util/Utils.java
    cxf/dosgi/trunk/discovery/local/src/test/resources/ed2-generated.xml
    cxf/dosgi/trunk/distribution/features/src/main/resources/features.xml
    cxf/dosgi/trunk/distribution/multi-bundle/pom.xml
    cxf/dosgi/trunk/distribution/multi-bundle/src/main/appended-resources/META-INF/NOTICE
    cxf/dosgi/trunk/distribution/multi-bundle/src/main/assembly/assembly.xml
    cxf/dosgi/trunk/distribution/multi-bundle/src/main/resources/distro_bundles.xml
    cxf/dosgi/trunk/distribution/multi-bundle2/src/main/assembly/assembly.xml
    cxf/dosgi/trunk/dsw/cxf-dsw/pom.xml
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/InterfaceRule.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorImpl.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorImplTest.java
    cxf/dosgi/trunk/parent/pom.xml

Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/publish/PublishingEndpointListener.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/publish/PublishingEndpointListener.java?rev=1514476&r1=1514475&r2=1514476&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/publish/PublishingEndpointListener.java (original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/publish/PublishingEndpointListener.java Thu Aug 15 20:40:29 2013
@@ -28,22 +28,24 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.cxf.dosgi.discovery.local.util.EndpointUtils;
 import org.apache.cxf.dosgi.discovery.zookeeper.util.Utils;
+import org.apache.cxf.dosgi.endpointdesc.EndpointDescriptionParser;
+import org.apache.cxf.dosgi.endpointdesc.PropertiesMapper;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.KeeperException.NoNodeException;
+import org.apache.zookeeper.KeeperException.NodeExistsException;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooKeeper;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.remoteserviceadmin.EndpointDescription;
 import org.osgi.service.remoteserviceadmin.EndpointListener;
 import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.xmlns.rsa.v1_0.EndpointDescriptionType;
+import org.osgi.xmlns.rsa.v1_0.PropertyType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.apache.zookeeper.KeeperException.NoNodeException;
-import static org.apache.zookeeper.KeeperException.NodeExistsException;
-
 /**
  * Listens for local Endpoints and publishes them to ZooKeeper.
  */
@@ -56,10 +58,13 @@ public class PublishingEndpointListener 
     private final List<EndpointDescription> endpoints = new ArrayList<EndpointDescription>();
     private boolean closed;
 
+    private final EndpointDescriptionParser endpointDescriptionParser;
+
     public PublishingEndpointListener(ZooKeeper zk, BundleContext bctx) {
         this.zk = zk;
         discoveryPluginTracker = new ServiceTracker(bctx, DiscoveryPlugin.class.getName(), null);
         discoveryPluginTracker.open();
+        endpointDescriptionParser = new EndpointDescriptionParser();
     }
 
     public void endpointAdded(EndpointDescription endpoint, String matchedFilter) {
@@ -104,7 +109,11 @@ public class PublishingEndpointListener 
             String fullPath = path + '/' + endpointKey;
             LOG.debug("Creating ZooKeeper node: {}", fullPath);
             ensurePath(path, zk);
-            createEphemeralNode(fullPath, getData(props));
+            List<PropertyType> propsOut = new PropertiesMapper().fromProps(props);
+            EndpointDescriptionType epd = new EndpointDescriptionType();
+            epd.getProperty().addAll(propsOut);
+            byte[] epData = endpointDescriptionParser.getData(epd);
+            createEphemeralNode(fullPath, epData);
         }
     }
 
@@ -176,10 +185,6 @@ public class PublishingEndpointListener 
         }
     }
 
-    static byte[] getData(Map<String, Object> props) {
-        return EndpointUtils.getEndpointDescriptionXML(props).getBytes();
-    }
-
     static String getKey(String endpoint) throws URISyntaxException {
         URI uri = new URI(endpoint);
 

Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/subscribe/InterfaceMonitor.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/subscribe/InterfaceMonitor.java?rev=1514476&r1=1514475&r2=1514476&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/subscribe/InterfaceMonitor.java (original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/subscribe/InterfaceMonitor.java Thu Aug 15 20:40:29 2013
@@ -18,13 +18,15 @@
  */
 package org.apache.cxf.dosgi.discovery.zookeeper.subscribe;
 
+import java.io.ByteArrayInputStream;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.cxf.dosgi.discovery.local.util.EndpointUtils;
 import org.apache.cxf.dosgi.discovery.zookeeper.util.Utils;
+import org.apache.cxf.dosgi.endpointdesc.EndpointDescriptionParser;
+import org.apache.cxf.dosgi.endpointdesc.PropertiesMapper;
 import org.apache.zookeeper.AsyncCallback.StatCallback;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.KeeperException.Code;
@@ -34,6 +36,7 @@ import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.data.Stat;
 import org.osgi.service.remoteserviceadmin.EndpointDescription;
 import org.osgi.service.remoteserviceadmin.EndpointListener;
+import org.osgi.xmlns.rsa.v1_0.EndpointDescriptionType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -61,11 +64,14 @@ public class InterfaceMonitor implements
     // This map reference changes, so don't synchronize on it
     private Map<String, EndpointDescription> nodes = new HashMap<String, EndpointDescription>();
 
+    private EndpointDescriptionParser parser;
+
     public InterfaceMonitor(ZooKeeper zk, String objClass, EndpointListener endpointListener, String scope) {
         this.zk = zk;
         this.znode = Utils.getZooKeeperPath(objClass);
         this.recursive = objClass == null || objClass.isEmpty();
         this.endpointListener = endpointListener;
+        this.parser = new EndpointDescriptionParser();
         LOG.debug("Creating new InterfaceMonitor {} for scope [{}] and objectClass [{}]",
                 new Object[] {recursive ? "(recursive)" : "", scope, objClass});
     }
@@ -230,7 +236,7 @@ public class InterfaceMonitor implements
             byte[] data = zk.getData(node, false, null);
             LOG.debug("Got data for node: {}", node);
 
-            EndpointDescription endpoint = EndpointUtils.getFirstEnpointDescription(data);
+            EndpointDescription endpoint = getFirstEnpointDescription(data);
             if (endpoint != null) {
                 return endpoint;
             }
@@ -240,4 +246,13 @@ public class InterfaceMonitor implements
         }
         return null;
     }
+
+    public EndpointDescription getFirstEnpointDescription(byte[] data) {
+        List<EndpointDescriptionType> elements = parser.getEndpointDescriptions(new ByteArrayInputStream(data));
+        if (elements.isEmpty()) {
+            return null;
+        }
+        Map<String, Object> props = new PropertiesMapper().toProps(elements.get(0).getProperty());
+        return new EndpointDescription(props);
+    }
 }

Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/publish/PublishingEndpointListenerTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/publish/PublishingEndpointListenerTest.java?rev=1514476&r1=1514475&r2=1514476&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/publish/PublishingEndpointListenerTest.java (original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/publish/PublishingEndpointListenerTest.java Thu Aug 15 20:40:29 2013
@@ -25,6 +25,8 @@ import java.util.Map;
 
 import junit.framework.TestCase;
 
+import org.apache.cxf.dosgi.endpointdesc.EndpointDescriptionParser;
+import org.apache.cxf.dosgi.endpointdesc.PropertiesMapper;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooDefs.Ids;
@@ -40,6 +42,8 @@ import org.osgi.framework.ServiceListene
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.remoteserviceadmin.EndpointDescription;
 import org.osgi.service.remoteserviceadmin.RemoteConstants;
+import org.osgi.xmlns.rsa.v1_0.EndpointDescriptionType;
+import org.osgi.xmlns.rsa.v1_0.PropertyType;
 
 public class PublishingEndpointListenerTest extends TestCase {
 
@@ -124,9 +128,14 @@ public class PublishingEndpointListenerT
 
         final ZooKeeper zk = EasyMock.createNiceMock(ZooKeeper.class);
         String expectedFullPath = "/osgi/service_registry/org/foo/myClass/some.machine#9876##test";
+        
+        List<PropertyType> props2 = new PropertiesMapper().fromProps(expectedProps);
+        EndpointDescriptionType epd = new EndpointDescriptionType();
+        epd.getProperty().addAll(props2);
+        byte[] data = new EndpointDescriptionParser().getData(epd);
         EasyMock.expect(zk.create(
                 EasyMock.eq(expectedFullPath),
-                EasyMock.aryEq(PublishingEndpointListener.getData(expectedProps)),
+                EasyMock.aryEq(data),
                 EasyMock.eq(Ids.OPEN_ACL_UNSAFE),
                 EasyMock.eq(CreateMode.EPHEMERAL))).andReturn("");
         EasyMock.replay(zk);

Modified: cxf/dosgi/trunk/discovery/local/pom.xml
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/pom.xml?rev=1514476&r1=1514475&r2=1514476&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/local/pom.xml (original)
+++ cxf/dosgi/trunk/discovery/local/pom.xml Thu Aug 15 20:40:29 2013
@@ -54,11 +54,6 @@
         </dependency>
 
         <dependency>
-            <groupId>org.apache.servicemix.bundles</groupId>
-            <artifactId>org.apache.servicemix.bundles.jdom</artifactId>
-            <version>${jdom.version}</version>
-        </dependency>
-        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>
@@ -78,6 +73,17 @@
     <build>
         <plugins>
             <plugin>
+                <groupId>org.jvnet.jaxb2.maven2</groupId>
+                <artifactId>maven-jaxb2-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>generate</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
                 <configuration>
@@ -90,10 +96,6 @@
                             org.osgi.service.remoteserviceadmin;version="[${remote.service.admin.interfaces.version},2.0)",
                             *
                         </Import-Package>
-                        <Private-Package>org.apache.cxf.dosgi.discovery.local.internal</Private-Package>
-                        <Export-Package>
-                            org.apache.cxf.dosgi.discovery.local.util
-                        </Export-Package>
                     </instructions>
                 </configuration>
             </plugin>

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=1514476&r1=1514475&r2=1514476&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 Aug 15 20:40:29 2013
@@ -27,8 +27,8 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.concurrent.ConcurrentHashMap;
 
-import org.apache.cxf.dosgi.discovery.local.util.EndpointUtils;
 import org.apache.cxf.dosgi.discovery.local.util.Utils;
+import org.apache.cxf.dosgi.endpointdesc.EndpointDescriptionBundleParser;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
@@ -50,9 +50,11 @@ public class LocalDiscovery implements B
         new HashMap<String, Collection<EndpointListener>>();
     final BundleContext bundleContext;
 
+    EndpointDescriptionBundleParser bundleParser;
     ServiceTracker listenerTracker;
 
     public LocalDiscovery(BundleContext bc) {
+        this.bundleParser = new EndpointDescriptionBundleParser();
         bundleContext = bc;
 
         listenerTracker = new ServiceTracker(bundleContext, EndpointListener.class.getName(), null) {
@@ -173,7 +175,7 @@ public class LocalDiscovery implements B
     }
 
     private void findDeclaredRemoteServices(Bundle bundle) {
-        List<EndpointDescription> endpoints = EndpointUtils.getAllEndpointDescriptions(bundle);
+        List<EndpointDescription> endpoints = bundleParser.getAllEndpointDescriptions(bundle);
         for (EndpointDescription endpoint : endpoints) {
             endpointDescriptions.put(endpoint, bundle);
             addedEndpointDescription(endpoint);

Modified: 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=1514476&r1=1514475&r2=1514476&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/util/Utils.java (original)
+++ cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/util/Utils.java Thu Aug 15 20:40:29 2013
@@ -18,12 +18,21 @@
  */
 package org.apache.cxf.dosgi.discovery.local.util;
 
+import java.io.StringReader;
+import java.io.StringWriter;
 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 java.util.regex.Pattern;
+
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
 
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Filter;
@@ -89,4 +98,28 @@ public final class Utils {
             return false;
         }
     }
+    
+    public static String normXML(String s) {
+        String s2 = stripComment(s);
+        String s3 = stripProlog(s2);
+        try {
+            TransformerFactory transFactory = TransformerFactory.newInstance();
+            Transformer transformer = transFactory.newTransformer();
+            StringWriter buffer = new StringWriter();
+            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+            transformer.transform(new StreamSource(new StringReader(s3)), new StreamResult(buffer));
+            return buffer.toString();
+        } catch (Exception e) {
+            return "";
+        }
+    }
+
+    private static String stripComment(String s) {
+        return Pattern.compile("<!--(.*?)-->", Pattern.DOTALL).matcher(s).replaceAll("");
+    }
+
+    private static String stripProlog(String s) {
+        return s.replaceAll("<\\?(.*?)\\?>", "");
+    }
 }

Copied: cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionBundleParser.java (from r1512459, cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/util/EndpointUtils.java)
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionBundleParser.java?p2=cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionBundleParser.java&p1=cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/util/EndpointUtils.java&r1=1512459&r2=1514476&rev=1514476&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/util/EndpointUtils.java (original)
+++ cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionBundleParser.java Thu Aug 15 20:40:29 2013
@@ -16,530 +16,90 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.cxf.dosgi.discovery.local.util;
+package org.apache.cxf.dosgi.endpointdesc;
 
-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.osgi.xmlns.rsa.v1_0.EndpointDescriptionType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public final class EndpointUtils {
-
-    private static final Logger LOG = LoggerFactory.getLogger(EndpointUtils.class);
+public final class EndpointDescriptionBundleParser {
+    private static final Logger LOG = LoggerFactory.getLogger(EndpointDescriptionBundleParser.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 EndpointDescriptionParser parser;
 
-    private static final String INTERFACE_SEPARATOR = ":";
-
-    private EndpointUtils() {
+    public EndpointDescriptionBundleParser() {
+        parser = new EndpointDescriptionParser();
     }
 
-    public static List<EndpointDescription> getAllEndpointDescriptions(Bundle b) {
-        List<Element> elements = getAllDescriptionElements(b);
+    public List<EndpointDescription> getAllEndpointDescriptions(Bundle b) {
+        List<EndpointDescriptionType> elements = getAllDescriptionElements(b);
 
         List<EndpointDescription> endpoints = new ArrayList<EndpointDescription>(elements.size());
-        for (Element el : elements) {
-            if (ENDPOINT_DESCRIPTION_ELEMENT.equals(el.getName())) {
-                endpoints.add(getEndpointDescription(el));
-            } else if (SERVICE_DESCRIPTION_ELEMENT.equals(el.getName())) {
-                endpoints.add(getLegacyEndpointDescription(el));
-            }
+        for (EndpointDescriptionType epd : elements) {
+            Map<String, Object> props = new PropertiesMapper().toProps(epd.getProperty());
+            endpoints.add(new EndpointDescription(props));
         }
         return endpoints;
     }
 
-    @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>();
+    List<EndpointDescriptionType> getAllDescriptionElements(Bundle b) {
+        Enumeration<URL> urls = getEndpointDescriptionURLs(b);
+        List<EndpointDescriptionType> elements = new ArrayList<EndpointDescriptionType>();
         while (urls.hasMoreElements()) {
             URL resourceURL = (URL) urls.nextElement();
             try {
-                elements.addAll(getElements(resourceURL.openStream()));
+                elements.addAll(parser.getEndpointDescriptions(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());
+    
+    Enumeration<URL> getEndpointDescriptionURLs(Bundle b) {
+        String origDir = getRemoteServicesDir(b);
+        
+        // Split origDir into dir and file pattern
+        String filePattern = "*.xml";
+        String dir;
+        if (origDir.endsWith("/")) {
+            dir = origDir.substring(0, origDir.length() - 1);
+        } else {
+            int idx = origDir.lastIndexOf('/');
+            if (idx >= 0 & origDir.length() > idx) {
+                filePattern = origDir.substring(idx + 1);
+                dir = origDir.substring(0, idx);
             } 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);
+                filePattern = origDir;
+                dir = "";
             }
-        } 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")
+        Enumeration<URL> urls = b.findEntries(dir, filePattern, false);
+        return (urls == null) ? Collections.enumeration(new ArrayList<URL>()) : urls;
     }
 
-    @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)));
+    private static String getRemoteServicesDir(Bundle b) {
+        Dictionary<?, ?> headers = b.getHeaders();
+        Object header = null;
+        if (headers != null) {
+            header = headers.get(REMOTE_SERVICES_HEADER_NAME);
         }
-
-        Namespace nsOld = Namespace.getNamespace(REMOTE_SERVICES_NS);
-        elements.addAll(d.getRootElement().getChildren(SERVICE_DESCRIPTION_ELEMENT, nsOld));
-
-        return elements;
+        return (header == null) ? REMOTE_SERVICES_DIRECTORY : header.toString();
     }
 
-    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/endpointdesc/EndpointDescriptionParser.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionParser.java?rev=1514476&view=auto
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionParser.java (added)
+++ cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionParser.java Thu Aug 15 20:40:29 2013
@@ -0,0 +1,90 @@
+/**
+ * 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.endpointdesc;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+
+import org.osgi.xmlns.rsa.v1_0.EndpointDescriptionType;
+import org.osgi.xmlns.rsa.v1_0.EndpointDescriptionsType;
+
+public class EndpointDescriptionParser {
+    private JAXBContext jaxbContext;
+
+    public EndpointDescriptionParser() {
+        try {
+            jaxbContext = JAXBContext.newInstance(EndpointDescriptionsType.class.getPackage().getName(),
+                                                  this.getClass().getClassLoader());
+        } catch (JAXBException e) {
+            throw new RuntimeException(e.getMessage(), e);
+        }
+    }
+
+    public List<EndpointDescriptionType> getEndpointDescriptions(InputStream is) {
+        try {
+            Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+            Source source = new StreamSource(is);
+            JAXBElement<EndpointDescriptionsType> jaxb = unmarshaller.unmarshal(source, EndpointDescriptionsType.class);
+            EndpointDescriptionsType decorations = jaxb.getValue();
+            return decorations.getEndpointDescription();
+        } catch (Exception ex) {
+            throw new RuntimeException(ex.getMessage(), ex);
+        }
+    }
+
+    public void writeTo(EndpointDescriptionsType endpointDescriptions, OutputStream os) {
+        try {
+            Marshaller marshaller = jaxbContext.createMarshaller();
+            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+            QName name = new QName("http://www.osgi.org/xmlns/rsa/v1.0.0", "endpoint-descriptions");
+            JAXBElement<EndpointDescriptionsType> el = 
+                new JAXBElement<EndpointDescriptionsType>(name, EndpointDescriptionsType.class, 
+                    endpointDescriptions);
+            marshaller.marshal(el, os);
+        } catch (Exception ex) {
+            throw new RuntimeException(ex.getMessage(), ex);
+        } finally {
+            try {
+                os.close();
+            } catch (IOException e) {
+                // Ignore
+            }
+        }
+    }
+    
+    public byte[] getData(EndpointDescriptionType endpointDescription) {
+        EndpointDescriptionsType endpointDescriptions = new EndpointDescriptionsType();
+        endpointDescriptions.getEndpointDescription().add(endpointDescription);
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        writeTo(endpointDescriptions, bos);
+        return bos.toByteArray();
+    }
+}

Propchange: cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionParser.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/endpointdesc/PropertiesMapper.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/endpointdesc/PropertiesMapper.java?rev=1514476&view=auto
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/endpointdesc/PropertiesMapper.java (added)
+++ cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/endpointdesc/PropertiesMapper.java Thu Aug 15 20:40:29 2013
@@ -0,0 +1,345 @@
+/**
+ * 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.endpointdesc;
+
+import java.io.Serializable;
+import java.io.StringWriter;
+import java.lang.reflect.Array;
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.bind.JAXBElement;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Node;
+import org.osgi.xmlns.rsa.v1_0.ArrayType;
+import org.osgi.xmlns.rsa.v1_0.ObjectFactory;
+import org.osgi.xmlns.rsa.v1_0.PropertyType;
+import org.osgi.xmlns.rsa.v1_0.ValueType;
+import org.osgi.xmlns.rsa.v1_0.XmlType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PropertiesMapper {
+    private static final Logger LOG = LoggerFactory.getLogger(PropertiesMapper.class);
+
+    public Map<String, Object> toProps(List<PropertyType> properties) {
+        Map<String, Object> map = new HashMap<String, Object>();
+        for (PropertyType prop : properties) {
+            map.put(prop.getName(), getValue(prop));
+        }
+        return map;
+    }
+
+    private Object getValue(PropertyType prop) {
+        Object value = null;
+        String type = getTypeName(prop);
+        Object content = getFirstNonText(prop.getContent());
+        if (content instanceof JAXBElement<?>) {
+            JAXBElement<?> el = (JAXBElement<?>)content;
+            if (el.getDeclaredType() == ArrayType.class) {
+                String elName = el.getName().getLocalPart();
+                ArrayType inValue = (ArrayType)el.getValue();
+                if ("array".equals(elName)) {
+                    value = getArray(inValue, type);
+                } else if ("set".equals(elName)) {
+                    value = handleCollection(inValue, new HashSet<Object>(), type);
+                } else if ("list".equals(elName)) {
+                    value = handleCollection(inValue, new ArrayList<Object>(), type);
+                }
+            } else if (el.getDeclaredType() == XmlType.class) {
+                value = readXML((XmlType)el.getValue(), type);
+            }
+        } else {
+            if (prop.getValue() != null) {
+                value = instantiate(type, prop.getValue());
+            } else {
+                if (prop.getContent().size() > 0) {
+                    value = instantiate(type, prop.getContent().get(0).toString());
+                }
+            }
+        }
+        return value;
+    }
+
+    private Object getFirstNonText(List<Serializable> contentList) {
+        for (Object content : contentList) {
+            if (content instanceof JAXBElement<?>) {
+                return content;
+            }
+        }
+        return null;
+    }
+
+    private static String getTypeName(PropertyType prop) {
+        String type = prop.getValueType();
+        return type == null ? "String" : type;
+    }
+
+    private Object getArray(ArrayType arrayEl, String type) {
+        List<ValueType> values = arrayEl.getValue();
+        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++) {
+                Object val = getValue(values.get(i), type);
+                Array.set(array, i, val);
+            }
+
+            return array;
+        } catch (Exception e) {
+            LOG.warn("Could not create array for Endpoint Description", e);
+            return null;
+        }
+    }
+
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    private Collection handleCollection(ArrayType el, Collection value, String type) {
+        List<ValueType> values = el.getValue();
+        for (ValueType val : values) {
+            Object obj = getValue(val, type);
+            value.add(obj);
+        }
+        return value;
+    }
+    
+    private Object getValue(ValueType value, String type) {
+        if (value.getContent().size() == 1 && value.getContent().get(0) instanceof String) {
+            return handleValue((String)value.getContent().get(0), type);
+        }
+        JAXBElement<?> valueContent = (JAXBElement<?>)getFirstNonText(value.getContent());
+        if (valueContent.getDeclaredType() == XmlType.class) {
+            return readXML((XmlType)valueContent.getValue(), type);
+        }
+        return "";
+    }
+
+    private String readXML(XmlType el, String type) {
+        if (el == null) {
+            return null;
+        }
+        if (!"String".equals(type)) {
+            LOG.warn("Embedded XML must be of type String, found: " + type);
+            return null;
+        }
+        Node xmlContent = (Node)el.getAny();
+        xmlContent.normalize();
+        try {
+            TransformerFactory transFactory = TransformerFactory.newInstance();
+            Transformer transformer = transFactory.newTransformer();
+            StringWriter buffer = new StringWriter();
+            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+            transformer.transform(new DOMSource(xmlContent), new StreamResult(buffer));
+            return buffer.toString();
+        } catch (Exception e) {
+            return "";
+        }
+    }
+
+    private static Object handleValue(String val, String type) {
+        return instantiate(type, val);
+    }
+
+    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;
+        }
+    }
+    
+    public List<PropertyType> fromProps(Map<String, Object> m) {
+        List<PropertyType> props = new ArrayList<PropertyType>();
+        for (Map.Entry<String, Object> entry : m.entrySet()) {
+            String key = entry.getKey();
+            Object val = entry.getValue();
+
+            PropertyType propEl = new PropertyType();
+            propEl.setName(key);
+            ObjectFactory factory = new ObjectFactory();
+            if (val.getClass().isArray()) {
+                ArrayType arrayEl = new ArrayType();
+                propEl.getContent().add(factory.createArray(arrayEl));
+                for (Object o : normalizeArray(val)) {
+                    setValueType(propEl, o);
+                    ValueType valueType =  new ValueType();
+                    valueType.getContent().add(o.toString());
+                    arrayEl.getValue().add(valueType);
+                }
+            } else if (val instanceof List) {
+                ArrayType listEl = new ArrayType();
+                propEl.getContent().add(factory.createList(listEl));
+                handleCollectionValue((Collection<?>) val, propEl, listEl);
+            } else if (val instanceof Set) {
+                ArrayType setEl = new ArrayType();
+                propEl.getContent().add(factory.createSet(setEl));
+                handleCollectionValue((Collection<?>) val, propEl, setEl);
+            } else if (val instanceof String
+                    || val instanceof Character
+                    || val instanceof Boolean
+                    || val instanceof Byte) {
+                setValueType(propEl, val);
+                propEl.setValue(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.setValue(val.toString());
+            } else {
+                // Don't add this property as the value type is not supported
+                continue;
+            }
+            props.add(propEl);
+        }
+        return props;
+    }
+
+    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(Collection<?> val, PropertyType propEl, ArrayType listEl) {
+        for (Object o : val) {
+            setValueType(propEl, o);
+            ValueType valueType = new ValueType();
+            valueType.getContent().add(o.toString());
+            listEl.getValue().add(valueType);
+        }
+    }
+
+    private static void setValueType(PropertyType 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.setValueType(dataType);
+    }
+}

Propchange: cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/endpointdesc/PropertiesMapper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cxf/dosgi/trunk/discovery/local/src/main/resources/endpoint-description.xsd
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/main/resources/endpoint-description.xsd?rev=1514476&view=auto
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/main/resources/endpoint-description.xsd (added)
+++ cxf/dosgi/trunk/discovery/local/src/main/resources/endpoint-description.xsd Thu Aug 15 20:40:29 2013
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.osgi.org/xmlns/rsa/v1.0.0" targetNamespace="http://www.osgi.org/xmlns/rsa/v1.0.0">
+    <element name="endpoint-descriptions"
+        type="tns:EndpointDescriptionsType">
+    </element>
+    
+    <complexType name="EndpointDescriptionsType">
+        <sequence>
+            <element maxOccurs="unbounded" minOccurs="0"
+                ref="tns:endpoint-description">
+            </element>
+        </sequence>
+    </complexType>
+
+    <complexType name="EndpointDescriptionType">
+        <sequence>
+            <element ref="tns:property" maxOccurs="unbounded" minOccurs="0"></element>
+        </sequence>
+    </complexType>
+
+    <complexType name="PropertyType" mixed="true">
+        <choice>
+            <element ref="tns:array"></element>
+            <element ref="tns:list"></element>
+            <element ref="tns:set"></element>
+            <element ref="tns:xml"></element>
+        </choice>
+        <attribute name="name" type="string"></attribute>
+        <attribute name="value-type" type="string"></attribute>
+        <attribute name="value" type="string"></attribute>
+    </complexType>
+
+    <complexType name="ArrayType">
+        <sequence>
+            <element maxOccurs="unbounded" minOccurs="0"
+                ref="tns:value">
+            </element>
+        </sequence>
+    </complexType>
+    <element name="endpoint-description"
+        type="tns:EndpointDescriptionType">
+    </element>
+    <element name="property" type="tns:PropertyType"></element>
+    <element name="array" type="tns:ArrayType"></element>
+    <element name="list" type="tns:ArrayType"></element>
+    <element name="set" type="tns:ArrayType"></element>
+
+    <complexType name="XmlType">
+        <sequence>
+            <any></any>
+        </sequence>
+    </complexType>
+    <element name="value" type="tns:ValueType"></element>
+    <element name="xml" type="tns:XmlType"></element>
+
+    <complexType name="ValueType" mixed="true">
+        <sequence>
+            <element ref="tns:xml"></element>
+        </sequence>
+    </complexType>
+</schema>
\ No newline at end of file

Propchange: cxf/dosgi/trunk/discovery/local/src/main/resources/endpoint-description.xsd
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionBundleParserTest.java (from r1514466, cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/util/EndpointUtilsTest.java)
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionBundleParserTest.java?p2=cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionBundleParserTest.java&p1=cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/util/EndpointUtilsTest.java&r1=1514466&r2=1514476&rev=1514476&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/util/EndpointUtilsTest.java (original)
+++ cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionBundleParserTest.java Thu Aug 15 20:40:29 2013
@@ -16,75 +16,41 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.cxf.dosgi.discovery.local.util;
+package org.apache.cxf.dosgi.endpointdesc;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
 import java.net.URL;
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.regex.Pattern;
 
 import junit.framework.TestCase;
 
+import org.apache.cxf.dosgi.discovery.local.util.Utils;
 import org.easymock.EasyMock;
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.JDOMException;
-import org.jdom.input.SAXBuilder;
-import org.jdom.output.Format;
-import org.jdom.output.XMLOutputter;
 import org.osgi.framework.Bundle;
 import org.osgi.service.remoteserviceadmin.EndpointDescription;
-import org.osgi.service.remoteserviceadmin.RemoteConstants;
 
-public class EndpointUtilsTest extends TestCase {
-
-    private static final String LF = "\n";
-
-    public void testNoRemoteServicesXMLFiles() {
-        Bundle b = EasyMock.createNiceMock(Bundle.class);
-        EasyMock.replay(b);
-
-        List<Element> rsElements = EndpointUtils.getAllDescriptionElements(b);
-        assertEquals(0, rsElements.size());
-    }
-
-    public void testEndpointDescriptionXMLFiles() {
-        URL ed1URL = getClass().getResource("/ed1.xml");
+public class EndpointDescriptionBundleParserTest extends TestCase {
 
+    private Bundle createBundleContaining(URL ed1URL) {
         Bundle b = EasyMock.createNiceMock(Bundle.class);
         EasyMock.expect(b.findEntries(
             EasyMock.eq("OSGI-INF/remote-service"),
             EasyMock.eq("*.xml"), EasyMock.anyBoolean())).andReturn(
                 Collections.enumeration(Arrays.asList(ed1URL))).anyTimes();
         EasyMock.replay(b);
-
-        List<Element> edElements = EndpointUtils.getAllDescriptionElements(b);
-        assertEquals(4, edElements.size());
+        return b;
     }
 
     public void testAllEndpoints1() {
         URL ed1URL = getClass().getResource("/ed1.xml");
 
-        Bundle b = EasyMock.createNiceMock(Bundle.class);
-        EasyMock.expect(b.findEntries(
-            EasyMock.eq("OSGI-INF/remote-service"),
-            EasyMock.eq("*.xml"), EasyMock.anyBoolean())).andReturn(
-                Collections.enumeration(Arrays.asList(ed1URL))).anyTimes();
-        EasyMock.replay(b);
+        Bundle b = createBundleContaining(ed1URL);
 
-        List<EndpointDescription> endpoints = EndpointUtils.getAllEndpointDescriptions(b);
+        List<EndpointDescription> endpoints = new EndpointDescriptionBundleParser().getAllEndpointDescriptions(b);
         assertEquals(4, endpoints.size());
         EndpointDescription endpoint0 = endpoints.get(0);
         assertEquals("http://somewhere:12345", endpoint0.getId());
@@ -109,14 +75,9 @@ public class EndpointUtilsTest extends T
     public void testAllEndpoints2() throws Exception {
         URL ed2URL = getClass().getResource("/ed2.xml");
 
-        Bundle b = EasyMock.createNiceMock(Bundle.class);
-        EasyMock.expect(b.findEntries(
-            EasyMock.eq("OSGI-INF/remote-service"),
-            EasyMock.eq("*.xml"), EasyMock.anyBoolean())).andReturn(
-                Collections.enumeration(Arrays.asList(ed2URL))).anyTimes();
-        EasyMock.replay(b);
+        Bundle b = createBundleContaining(ed2URL);
 
-        List<EndpointDescription> endpoints = EndpointUtils.getAllEndpointDescriptions(b);
+        List<EndpointDescription> endpoints = new EndpointDescriptionBundleParser().getAllEndpointDescriptions(b);
         assertEquals(2, endpoints.size());
         EndpointDescription endpoint0 = endpoints.get(0);
         assertEquals("foo:bar", endpoint0.getId());
@@ -132,10 +93,10 @@ public class EndpointUtilsTest extends T
         // exports should have been removed
         assertNull(props.get("service.exported.configs"));
 
-        assertEquals(normXML("<other:t1 xmlns:other='http://www.acme.org/xmlns/other/v1.0.0' "
-                             + "xmlns='http://www.acme.org/xmlns/other/v1.0.0'><foo type='bar'>haha</foo></other:t1>"),
-            normXML((String) props.get("someXML")));
-
+        assertEquals(Utils.normXML("<other:t1 xmlns:other='http://www.acme.org/xmlns/other/v1.0.0' "
+            + "xmlns='http://www.acme.org/xmlns/other/v1.0.0'><foo type='bar'>haha</foo>\n"
+            + "        </other:t1>"),
+            Utils.normXML((String) props.get("someXML")));
         assertEquals(Long.MAX_VALUE, props.get("long"));
         assertEquals(-1L, props.get("long2"));
         assertEquals(Double.MAX_VALUE, props.get("double"));
@@ -169,149 +130,9 @@ public class EndpointUtilsTest extends T
 
         List<?> l = (List<?>) props.get("other2");
         assertEquals(1, l.size());
-        assertEquals(normXML("<other:t2 xmlns:other='http://www.acme.org/xmlns/other/v1.0.0'/>"),
-            normXML((String) l.get(0)));
-    }
-
-    public void testLegacyServiceDescriptionFormat() {
-        URL sdURL = getClass().getResource("/sd.xml");
-
-        Bundle b = EasyMock.createNiceMock(Bundle.class);
-        EasyMock.expect(b.findEntries(
-            EasyMock.eq("OSGI-INF/remote-service"),
-            EasyMock.eq("*.xml"), EasyMock.anyBoolean())).andReturn(
-                Collections.enumeration(Arrays.asList(sdURL))).anyTimes();
-        EasyMock.replay(b);
-
-        List<EndpointDescription> endpoints = EndpointUtils.getAllEndpointDescriptions(b);
-        assertEquals(1, endpoints.size());
-        EndpointDescription endpoint = endpoints.get(0);
-        assertEquals("http://localhost:9090/greeter", endpoint.getId());
-        assertEquals(Arrays.asList("org.apache.cxf.ws"), endpoint.getConfigurationTypes());
-        assertEquals(Arrays.asList("org.apache.cxf.dosgi.samples.greeter.GreeterService"), endpoint.getInterfaces());
-        assertNull("Should not contain service.exported.*",
-                endpoint.getProperties().get(RemoteConstants.SERVICE_EXPORTED_INTERFACES));
-        assertNull("Should not contain service.exported.*",
-                endpoint.getProperties().get(RemoteConstants.SERVICE_EXPORTED_CONFIGS));
-    }
-
-    public void testLegacyServiceDescriptionFormat2() {
-        URL sdURL = getClass().getResource("/sd2.xml");
-
-        Bundle b = EasyMock.createNiceMock(Bundle.class);
-        EasyMock.expect(b.findEntries(
-            EasyMock.eq("OSGI-INF/remote-service"),
-            EasyMock.eq("*.xml"), EasyMock.anyBoolean())).andReturn(
-                Collections.enumeration(Arrays.asList(sdURL))).anyTimes();
-        EasyMock.replay(b);
-
-        List<EndpointDescription> endpoints = EndpointUtils.getAllEndpointDescriptions(b);
-        assertEquals(2, endpoints.size());
-
-        EndpointDescription endpoint0 = endpoints.get(0);
-        assertEquals("http://localhost:9000/org/example/SomeService", endpoint0.getId());
-        assertEquals(Arrays.asList("org.apache.cxf.ws"), endpoint0.getConfigurationTypes());
-        assertEquals(Arrays.asList("org.example.SomeService"), endpoint0.getInterfaces());
-        assertEquals(Arrays.asList("confidentiality"), endpoint0.getIntents());
-
-        EndpointDescription endpoint1 = endpoints.get(1);
-        assertEquals(Arrays.asList("SomeOtherService", "WithSomeSecondInterface"), endpoint1.getInterfaces());
-        assertEquals("5", endpoint1.getProperties().get("blah"));
-    }
-
-    public void testCreateXML() throws Exception {
-        Map<String, Object> m = new LinkedHashMap<String, Object>();
-        m.put("service.imported.configs", "org.apache.cxf.ws");
-        m.put("endpoint.id", "foo:bar");
-        m.put("objectClass", new String[] {"com.acme.HelloService", "some.other.Service"});
-        m.put("SomeObject", new Object());
-        m.put("long", 9223372036854775807L);
-        m.put("Long2", -1L);
-        m.put("double", 1.7976931348623157E308);
-        m.put("Double2", 1.0d);
-        m.put("float", 42.24f);
-        m.put("Float2", 1.0f);
-        m.put("int", 17);
-        m.put("Integer2", 42);
-        m.put("byte", (byte) 127);
-        m.put("Byte2", (byte) -128);
-        m.put("boolean", true);
-        m.put("Boolean2", false);
-        m.put("short", (short) 99);
-        m.put("Short2", (short) -99);
-        m.put("char", '@');
-        m.put("Character2", 'X');
-
-        List<Boolean> boolList = new ArrayList<Boolean>();
-        boolList.add(true);
-        boolList.add(false);
-        m.put("bool-list", boolList);
-        m.put("empty-set", new HashSet<Object>());
-
-        Set<String> stringSet = new LinkedHashSet<String>();
-        stringSet.add("Hello there");
-        stringSet.add("How are you?");
-        m.put("string-set", stringSet);
-
-        int[] intArray = new int[] {1, 2};
-        m.put("int-array", intArray);
-
-        String xml = "<xml>" + LF
-            + "<t1 xmlns=\"http://www.acme.org/xmlns/other/v1.0.0\">" + LF
-            + "<foo type='bar'>haha</foo>" + LF
-            + "</t1>" + LF
-            + "</xml>";
-        m.put("someXML", xml);
-
-        String actual = EndpointUtils.getEndpointDescriptionXML(m);
-
-        URL edURL = getClass().getResource("/ed2-generated.xml");
-        String expected = new String(drainStream(edURL.openStream()));
-        assertEquals(normXML(expected), normXML(actual));
-    }
-
-    private static String normXML(String s) throws JDOMException, IOException {
-        String s2 = stripComment(s);
-        String s3 = stripProlog(s2);
-        Document d = new SAXBuilder().build(new ByteArrayInputStream(s3.getBytes()));
-        XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
-        return outputter.outputString(d);
-    }
-
-    private static String stripComment(String s) {
-        return Pattern.compile("<!--(.*?)-->", Pattern.DOTALL).matcher(s).replaceAll("");
+        assertEquals(Utils.normXML("<other:t2 xmlns:other='http://www.acme.org/xmlns/other/v1.0.0' " 
+                                   + "xmlns='http://www.osgi.org/xmlns/rsa/v1.0.0'/>"),
+                                   Utils.normXML((String) l.get(0)));
     }
 
-    private static String stripProlog(String s) {
-        return s.replaceAll("<\\?(.*?)\\?>", "");
-    }
-
-    public static void drainStream(InputStream is, OutputStream os) throws IOException {
-        byte[] bytes = new byte[8192];
-
-        int length;
-        int offset = 0;
-
-        while ((length = is.read(bytes, offset, bytes.length - offset)) != -1) {
-            offset += length;
-
-            if (offset == bytes.length) {
-                os.write(bytes, 0, bytes.length);
-                offset = 0;
-            }
-        }
-        if (offset != 0) {
-            os.write(bytes, 0, offset);
-        }
-    }
-
-    public static byte[] drainStream(InputStream is) throws IOException {
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        try {
-            drainStream(is, baos);
-            return baos.toByteArray();
-        } finally {
-            is.close();
-        }
-    }
 }

Added: cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionParserTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionParserTest.java?rev=1514476&view=auto
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionParserTest.java (added)
+++ cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionParserTest.java Thu Aug 15 20:40:29 2013
@@ -0,0 +1,49 @@
+/**
+ * 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.endpointdesc;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+
+import org.easymock.EasyMock;
+import org.junit.Assert;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.xmlns.rsa.v1_0.EndpointDescriptionType;
+
+public class EndpointDescriptionParserTest {
+
+    @Test
+    public void testNoRemoteServicesXMLFiles() {
+        Bundle b = EasyMock.createNiceMock(Bundle.class);
+        EasyMock.replay(b);
+
+        List<EndpointDescriptionType> rsElements = new EndpointDescriptionBundleParser().getAllDescriptionElements(b);
+        Assert.assertEquals(0, rsElements.size());
+    }
+
+    @Test
+    public void testEndpointDescriptionsFromURL() throws IOException {
+        URL ed1URL = getClass().getResource("/ed1.xml");
+        List<EndpointDescriptionType> edElements = new EndpointDescriptionParser().
+            getEndpointDescriptions(ed1URL.openStream());
+        Assert.assertEquals(4, edElements.size());
+    }
+}

Propchange: cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionParserTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/endpointdesc/PropertiesMapperTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/endpointdesc/PropertiesMapperTest.java?rev=1514476&view=auto
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/endpointdesc/PropertiesMapperTest.java (added)
+++ cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/endpointdesc/PropertiesMapperTest.java Thu Aug 15 20:40:29 2013
@@ -0,0 +1,130 @@
+/**
+ * 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.endpointdesc;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.cxf.dosgi.discovery.local.util.Utils;
+import org.junit.Assert;
+import org.junit.Test;
+import org.osgi.xmlns.rsa.v1_0.EndpointDescriptionType;
+import org.osgi.xmlns.rsa.v1_0.PropertyType;
+
+public class PropertiesMapperTest {
+    private static final String LF = "\n";
+
+    @Test
+    public void testCreateXML() throws Exception {
+        Map<String, Object> m = new LinkedHashMap<String, Object>();
+        m.put("service.imported.configs", "org.apache.cxf.ws");
+        m.put("endpoint.id", "foo:bar");
+        m.put("objectClass", new String[] {"com.acme.HelloService", "some.other.Service"});
+        m.put("SomeObject", new Object());
+        m.put("long", 9223372036854775807L);
+        m.put("Long2", -1L);
+        m.put("double", 1.7976931348623157E308);
+        m.put("Double2", 1.0d);
+        m.put("float", 42.24f);
+        m.put("Float2", 1.0f);
+        m.put("int", 17);
+        m.put("Integer2", 42);
+        m.put("byte", (byte) 127);
+        m.put("Byte2", (byte) -128);
+        m.put("boolean", true);
+        m.put("Boolean2", false);
+        m.put("short", (short) 99);
+        m.put("Short2", (short) -99);
+        m.put("char", '@');
+        m.put("Character2", 'X');
+
+        List<Boolean> boolList = new ArrayList<Boolean>();
+        boolList.add(true);
+        boolList.add(false);
+        m.put("bool-list", boolList);
+        m.put("empty-set", new HashSet<Object>());
+
+        Set<String> stringSet = new LinkedHashSet<String>();
+        stringSet.add("Hello there");
+        stringSet.add("How are you?");
+        m.put("string-set", stringSet);
+
+        int[] intArray = new int[] {1, 2};
+        m.put("int-array", intArray);
+
+        String xml = "<xml>" + LF
+            + "<t1 xmlns=\"http://www.acme.org/xmlns/other/v1.0.0\">" + LF
+            + "<foo type='bar'>haha</foo>" + LF
+            + "</t1>" + LF
+            + "</xml>";
+        m.put("someXML", xml);
+
+        List<PropertyType> props = new PropertiesMapper().fromProps(m);
+        EndpointDescriptionType epd = new EndpointDescriptionType();
+        epd.getProperty().addAll(props);
+        byte[] epData = new EndpointDescriptionParser().getData(epd);
+        String actual = new String(epData, Charset.defaultCharset());
+
+        URL edURL = getClass().getResource("/ed2-generated.xml");
+        String expected = new String(drainStream(edURL.openStream()));
+        Assert.assertEquals(Utils.normXML(expected), Utils.normXML(actual));
+    }
+
+
+
+    private static void drainStream(InputStream is, OutputStream os) throws IOException {
+        byte[] bytes = new byte[8192];
+
+        int length;
+        int offset = 0;
+
+        while ((length = is.read(bytes, offset, bytes.length - offset)) != -1) {
+            offset += length;
+
+            if (offset == bytes.length) {
+                os.write(bytes, 0, bytes.length);
+                offset = 0;
+            }
+        }
+        if (offset != 0) {
+            os.write(bytes, 0, offset);
+        }
+    }
+
+    private static byte[] drainStream(InputStream is) throws IOException {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        try {
+            drainStream(is, baos);
+            return baos.toByteArray();
+        } finally {
+            is.close();
+        }
+    }
+}

Propchange: cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/endpointdesc/PropertiesMapperTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain