You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by fm...@apache.org on 2012/10/18 15:05:20 UTC

svn commit: r1399648 - in /felix/trunk/metatype/src: main/java/org/apache/felix/metatype/ main/java/org/apache/felix/metatype/internal/ test/java/org/apache/felix/metatype/

Author: fmeschbe
Date: Thu Oct 18 13:05:19 2012
New Revision: 1399648

URL: http://svn.apache.org/viewvc?rev=1399648&view=rev
Log:
FELIX-3364 Apply patch by Jeremias Märki (thanks)

Modified:
    felix/trunk/metatype/src/main/java/org/apache/felix/metatype/MetaDataReader.java
    felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeServiceImpl.java
    felix/trunk/metatype/src/test/java/org/apache/felix/metatype/MetaDataReaderTest.java
    felix/trunk/metatype/src/test/java/org/apache/felix/metatype/MockBundle.java
    felix/trunk/metatype/src/test/java/org/apache/felix/metatype/MockBundleContext.java

Modified: felix/trunk/metatype/src/main/java/org/apache/felix/metatype/MetaDataReader.java
URL: http://svn.apache.org/viewvc/felix/trunk/metatype/src/main/java/org/apache/felix/metatype/MetaDataReader.java?rev=1399648&r1=1399647&r2=1399648&view=diff
==============================================================================
--- felix/trunk/metatype/src/main/java/org/apache/felix/metatype/MetaDataReader.java (original)
+++ felix/trunk/metatype/src/main/java/org/apache/felix/metatype/MetaDataReader.java Thu Oct 18 13:05:19 2012
@@ -105,11 +105,10 @@ public class MetaDataReader
      * @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 @@ public class MetaDataReader
             }
             return md;
         }
+        catch ( XmlPullParserException e )
+        {
+            throw new IOException( "XML parsing exception while reading metadata: " + e.getMessage() );
+        }
         finally
         {
             if ( ins != null )
@@ -143,15 +146,15 @@ public class MetaDataReader
     /**
      * 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 @@ public class MetaDataReader
      * @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();
-                }
-                else
-                {
-                    this.ignoreElement();
+                    if ( "MetaData".equals( this.parser.getName() ) )
+                    {
+                        checkMetatypeNamespace();
+                        mti = this.readMetaData();
+                    }
+                    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;

Modified: felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeServiceImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeServiceImpl.java?rev=1399648&r1=1399647&r2=1399648&view=diff
==============================================================================
--- felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeServiceImpl.java (original)
+++ felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeServiceImpl.java Thu Oct 18 13:05:19 2012
@@ -30,7 +30,6 @@ import org.osgi.framework.BundleContext;
 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 @@ class MetaTypeServiceImpl implements Met
                     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 );

Modified: felix/trunk/metatype/src/test/java/org/apache/felix/metatype/MetaDataReaderTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/metatype/src/test/java/org/apache/felix/metatype/MetaDataReaderTest.java?rev=1399648&r1=1399647&r2=1399648&view=diff
==============================================================================
--- felix/trunk/metatype/src/test/java/org/apache/felix/metatype/MetaDataReaderTest.java (original)
+++ felix/trunk/metatype/src/test/java/org/apache/felix/metatype/MetaDataReaderTest.java Thu Oct 18 13:05:19 2012
@@ -119,7 +119,7 @@ public class MetaDataReaderTest extends 
     }
 
 
-    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 @@ public class MetaDataReaderTest extends 
             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 @@ public class MetaDataReaderTest extends 
             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 @@ public class MetaDataReaderTest extends 
     }
 
 
-    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 );

Modified: felix/trunk/metatype/src/test/java/org/apache/felix/metatype/MockBundle.java
URL: http://svn.apache.org/viewvc/felix/trunk/metatype/src/test/java/org/apache/felix/metatype/MockBundle.java?rev=1399648&r1=1399647&r2=1399648&view=diff
==============================================================================
--- felix/trunk/metatype/src/test/java/org/apache/felix/metatype/MockBundle.java (original)
+++ felix/trunk/metatype/src/test/java/org/apache/felix/metatype/MockBundle.java Thu Oct 18 13:05:19 2012
@@ -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 class MockBundle implements Bundl
     }
 
 
+    public void start( int options )
+    {
+    }
+
+
     public void stop()
     {
     }
 
 
+    public void stop( int options )
+    {
+    }
+
+
     public void uninstall()
     {
     }

Modified: felix/trunk/metatype/src/test/java/org/apache/felix/metatype/MockBundleContext.java
URL: http://svn.apache.org/viewvc/felix/trunk/metatype/src/test/java/org/apache/felix/metatype/MockBundleContext.java?rev=1399648&r1=1399647&r2=1399648&view=diff
==============================================================================
--- felix/trunk/metatype/src/test/java/org/apache/felix/metatype/MockBundleContext.java (original)
+++ felix/trunk/metatype/src/test/java/org/apache/felix/metatype/MockBundleContext.java Thu Oct 18 13:05:19 2012
@@ -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 @@ public class MockBundleContext implement
             return false;
         }
 
+
+        public int compareTo( Object reference )
+        {
+            return -1;
+        }
+
     }
 }