FELIX-3364 Apply patch by Jeremias Märki (thanks)

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1399648 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/metatype/src/main/java/org/apache/felix/metatype/MetaDataReader.java b/metatype/src/main/java/org/apache/felix/metatype/MetaDataReader.java
index d96ffc3..33c3271 100644
--- a/metatype/src/main/java/org/apache/felix/metatype/MetaDataReader.java
+++ b/metatype/src/main/java/org/apache/felix/metatype/MetaDataReader.java
@@ -105,11 +105,10 @@
      * @return A {@link MetaData} providing access to the
      *      raw contents of the XML document.
      *
-     * @throws IOException If an I/O error occurs accessing the stream.
-     * @throws XmlPullParserException If an error occurs parsing the XML
-     *      document.
+     * @throws IOException If an I/O error occurs accessing the stream or
+     *      parsing the XML document.
      */
-    public MetaData parse( URL url ) throws IOException, XmlPullParserException
+    public MetaData parse( URL url ) throws IOException
     {
         InputStream ins = null;
         try
@@ -123,6 +122,10 @@
             }
             return md;
         }
+        catch ( XmlPullParserException e )
+        {
+            throw new IOException( "XML parsing exception while reading metadata: " + e.getMessage() );
+        }
         finally
         {
             if ( ins != null )
@@ -143,15 +146,15 @@
     /**
      * Checks if this document has a meta type name space.
      *
-     * @throws XmlPullParserException when there the meta type name space is not valid
+     * @throws IOException when there the meta type name space is not valid
      */
-    private void checkMetatypeNamespace() throws XmlPullParserException
+    private void checkMetatypeNamespace() throws IOException
     {
         final String namespace = this.parser.getNamespace();
         if ( namespace != null && namespace.length() > 0 && !NAMESPACE_1_0.equals( namespace )
             && !NAMESPACE_1_1.equals( namespace ) && !NAMESPACE_1_2.equals( namespace ) )
         {
-            throw new XmlPullParserException( "Unsupported Namespace " + namespace );
+            throw new IOException( "Unsupported Namespace " + namespace );
         }
     }
 
@@ -168,35 +171,40 @@
      * @return A {@link MetaData} providing access to the
      *      raw contents of the XML document.
      *
-     * @throws IOException If an I/O error occurrs accessing the stream.
-     * @throws XmlPullParserException If an error occurrs parsing the XML
-     *      document.
+     * @throws IOException If an I/O error occurs accessing the stream or
+     *      parsing the XML document.
      */
-    public MetaData parse( InputStream ins ) throws IOException, XmlPullParserException
+    public MetaData parse( InputStream ins ) throws IOException
     {
-        this.parser.setFeature( KXmlParser.FEATURE_PROCESS_NAMESPACES, true );
-
-        // set the parser input, use null encoding to force detection with <?xml?>
-        this.parser.setInput( ins, null );
-
         MetaData mti = null;
-
-        int eventType = this.parser.getEventType();
-        while ( eventType != XmlPullParser.END_DOCUMENT )
+        try
         {
-            if ( eventType == XmlPullParser.START_TAG )
+            this.parser.setFeature( KXmlParser.FEATURE_PROCESS_NAMESPACES, true );
+
+            // set the parser input, use null encoding to force detection with <?xml?>
+            this.parser.setInput( ins, null );
+
+            int eventType = this.parser.getEventType();
+            while ( eventType != XmlPullParser.END_DOCUMENT )
             {
-                if ( "MetaData".equals( this.parser.getName() ) )
+                if ( eventType == XmlPullParser.START_TAG )
                 {
-                    checkMetatypeNamespace();
-                    mti = this.readMetaData();
+                    if ( "MetaData".equals( this.parser.getName() ) )
+                    {
+                        checkMetatypeNamespace();
+                        mti = this.readMetaData();
+                    }
+                    else
+                    {
+                        this.ignoreElement();
+                    }
                 }
-                else
-                {
-                    this.ignoreElement();
-                }
+                eventType = this.parser.next();
             }
-            eventType = this.parser.next();
+        }
+        catch ( XmlPullParserException e )
+        {
+            throw new IOException( "XML parsing exception while reading metadata: " + e.getMessage() );
         }
 
         return mti;
diff --git a/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeServiceImpl.java b/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeServiceImpl.java
index d659f56..43f50ec 100644
--- a/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeServiceImpl.java
+++ b/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeServiceImpl.java
@@ -30,7 +30,6 @@
 import org.osgi.service.log.LogService;
 import org.osgi.service.metatype.MetaTypeInformation;
 import org.osgi.service.metatype.MetaTypeService;
-import org.xmlpull.v1.XmlPullParserException;
 
 
 /**
@@ -105,10 +104,6 @@
                     cmti.addMetaData( metaData );
                 }
             }
-            catch ( XmlPullParserException xppe )
-            {
-                Activator.log( LogService.LOG_ERROR, "fromDocuments: Error parsing document " + doc, xppe );
-            }
             catch ( IOException ioe )
             {
                 Activator.log( LogService.LOG_ERROR, "fromDocuments: Error accessing document " + doc, ioe );
diff --git a/metatype/src/test/java/org/apache/felix/metatype/MetaDataReaderTest.java b/metatype/src/test/java/org/apache/felix/metatype/MetaDataReaderTest.java
index 8f10a10..a894178 100644
--- a/metatype/src/test/java/org/apache/felix/metatype/MetaDataReaderTest.java
+++ b/metatype/src/test/java/org/apache/felix/metatype/MetaDataReaderTest.java
@@ -119,7 +119,7 @@
     }
 
 
-    public void testWithInvalidNamespaceUri() throws IOException
+    public void testWithInvalidNamespaceUri()
     {
         String empty = "<metatype:MetaData xmlns:metatype=\"http://www.osgi.org/xmlns/datatype/v1.0.0\" "
             + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ></metatype:MetaData>";
@@ -129,14 +129,14 @@
             read( empty );
             fail( "Parse failure expected for unsupported namespace URI" );
         }
-        catch ( XmlPullParserException e )
+        catch ( IOException e )
         {
             // expected due to unsupported namespace URI
         }
     }
 
 
-    public void testWithInvalidNamespaceName() throws IOException
+    public void testWithInvalidNamespaceName()
     {
         String empty = "<datatype:MetaData xmlns:metatype=\"http://www.osgi.org/xmlns/metatype/v1.0.0\" "
             + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ></datatype:MetaData>";
@@ -146,7 +146,7 @@
             read( empty );
             fail( "Parse failure expected for undefined namespace prefix" );
         }
-        catch ( XmlPullParserException e )
+        catch ( IOException e )
         {
             // expected due to undefined namespace prefix used
         }
@@ -230,7 +230,7 @@
     }
 
 
-    private MetaData read( String data ) throws IOException, XmlPullParserException
+    private MetaData read( String data ) throws IOException
     {
         InputStream input = new ByteArrayInputStream( data.getBytes( "UTF-8" ) );
         return reader.parse( input );
diff --git a/metatype/src/test/java/org/apache/felix/metatype/MockBundle.java b/metatype/src/test/java/org/apache/felix/metatype/MockBundle.java
index cf6fc71..153298e 100644
--- a/metatype/src/test/java/org/apache/felix/metatype/MockBundle.java
+++ b/metatype/src/test/java/org/apache/felix/metatype/MockBundle.java
@@ -1,4 +1,4 @@
-/* 
+/*
  * 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
@@ -168,11 +168,21 @@
     }
 
 
+    public void start( int options )
+    {
+    }
+
+
     public void stop()
     {
     }
 
 
+    public void stop( int options )
+    {
+    }
+
+
     public void uninstall()
     {
     }
diff --git a/metatype/src/test/java/org/apache/felix/metatype/MockBundleContext.java b/metatype/src/test/java/org/apache/felix/metatype/MockBundleContext.java
index 527fae3..eaedad2 100644
--- a/metatype/src/test/java/org/apache/felix/metatype/MockBundleContext.java
+++ b/metatype/src/test/java/org/apache/felix/metatype/MockBundleContext.java
@@ -1,4 +1,4 @@
-/* 
+/*
  * 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
@@ -427,5 +427,11 @@
             return false;
         }
 
+
+        public int compareTo( Object reference )
+        {
+            return -1;
+        }
+
     }
 }