felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1693433 - in /felix/trunk/metatype/src: main/java/org/apache/felix/metatype/MetaDataReader.java main/java/org/apache/felix/metatype/internal/Activator.java test/java/org/apache/felix/metatype/MetaDataReaderTest.java
Date Thu, 30 Jul 2015 14:34:05 GMT
Author: cziegeler
Date: Thu Jul 30 14:34:04 2015
New Revision: 1693433

URL: http://svn.apache.org/r1693433
Log:
FELIX-4973 : Relax exception handling when reading metatype XML

Modified:
    felix/trunk/metatype/src/main/java/org/apache/felix/metatype/MetaDataReader.java
    felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/Activator.java
    felix/trunk/metatype/src/test/java/org/apache/felix/metatype/MetaDataReaderTest.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=1693433&r1=1693432&r2=1693433&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 Jul
30 14:34:04 2015
@@ -316,7 +316,8 @@ public class MetaDataReader
                     if (getNamespaceVersion() < 13 && ocd.getAttributeDefinitions()
== null)
                     {
                         // Need at least one AD in versions 1.0, 1.1 & 1.2...
-                        throw missingElement("AD");
+                        logMissingElement("AD");
+                        ocd = null;
                     }
                     break;
                 }
@@ -377,7 +378,8 @@ public class MetaDataReader
                     if (designate.getObject() == null)
                     {
                         // Exactly 1 Object is allowed...
-                        throw missingElement("Object");
+                        logMissingElement("Object");
+                        designate = null;
                     }
                     break;
                 }
@@ -405,7 +407,7 @@ public class MetaDataReader
 
         readOptionalAttributes(ad, AD_ATTRIBUTES);
 
-        Map options = new LinkedHashMap();
+        Map<String, String> options = new LinkedHashMap<String, String>();
         int eventType = this.parser.next();
         while (eventType != XmlPullParser.END_DOCUMENT)
         {
@@ -439,7 +441,7 @@ public class MetaDataReader
 
         ad.setOptions(options);
 
-        // set value as late as possible to force an options check (FELIX-3884, FELIX-4665)...

+        // set value as late as possible to force an options check (FELIX-3884, FELIX-4665)...
         if (dfltValue != null)
         {
             ad.setDefaultValue(dfltValue);
@@ -635,10 +637,10 @@ public class MetaDataReader
         return new XmlPullParserException(message, this.parser, null);
     }
 
-    private XmlPullParserException missingElement(String elementName)
+    private void logMissingElement(String elementName)
     {
         String message = "Missing element " + elementName + " in element " + this.parser.getName();
-        return new XmlPullParserException(message, this.parser, null);
+        Activator.log(LogService.LOG_ERROR, message);
     }
 
     private XmlPullParserException unexpectedElement(String elementName)

Modified: felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/Activator.java?rev=1693433&r1=1693432&r2=1693433&view=diff
==============================================================================
--- felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/Activator.java (original)
+++ felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/Activator.java Thu
Jul 30 14:34:04 2015
@@ -21,10 +21,16 @@ package org.apache.felix.metatype.intern
 
 import java.io.PrintStream;
 import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.Date;
+import java.util.Dictionary;
+import java.util.Hashtable;
 
 import org.apache.felix.metatype.internal.l10n.BundleResources;
-import org.osgi.framework.*;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceReference;
 import org.osgi.service.log.LogService;
 import org.osgi.service.metatype.MetaTypeService;
 import org.osgi.util.tracker.ServiceTracker;
@@ -126,7 +132,7 @@ public class Activator implements Bundle
 
     public static void log( int level, String message )
     {
-        LogService log = ( LogService ) INSTANCE.logService.getService();
+        final LogService log = (INSTANCE == null ? null : ( LogService ) INSTANCE.logService.getService());
         if ( log == null )
         {
             _log( null, level, message, null );
@@ -140,7 +146,7 @@ public class Activator implements Bundle
 
     public static void log( int level, String message, Throwable exception )
     {
-        LogService log = ( LogService ) INSTANCE.logService.getService();
+        final LogService log = (INSTANCE == null ? null : ( LogService ) INSTANCE.logService.getService());
         if ( log == null )
         {
             _log( null, level, message, exception );
@@ -154,7 +160,7 @@ public class Activator implements Bundle
 
     public static void log( ServiceReference sr, int level, String message )
     {
-        LogService log = ( LogService ) INSTANCE.logService.getService();
+        final LogService log = (INSTANCE == null ? null : ( LogService ) INSTANCE.logService.getService());
         if ( log == null )
         {
             _log( sr, level, message, null );
@@ -168,7 +174,7 @@ public class Activator implements Bundle
 
     public static void log( ServiceReference sr, int level, String message, Throwable exception
)
     {
-        LogService log = ( LogService ) INSTANCE.logService.getService();
+        final LogService log = (INSTANCE == null ? null : ( LogService ) INSTANCE.logService.getService());
         if ( log == null )
         {
             _log( sr, level, message, exception );

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=1693433&r1=1693432&r2=1693433&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
Jul 30 14:34:04 2015
@@ -24,11 +24,11 @@ import java.io.InputStream;
 import java.util.Arrays;
 import java.util.List;
 
-import junit.framework.TestCase;
-
 import org.osgi.service.metatype.AttributeDefinition;
 import org.xmlpull.v1.XmlPullParserException;
 
+import junit.framework.TestCase;
+
 /**
  * The <code>MetaDataReaderTest</code> class tests the
  * <code>MetaDataReader</code> class.
@@ -39,6 +39,7 @@ public class MetaDataReaderTest extends
 {
     private MetaDataReader reader;
 
+    @Override
     protected void setUp() throws Exception
     {
         super.setUp();
@@ -46,6 +47,7 @@ public class MetaDataReaderTest extends
         reader = new MetaDataReader();
     }
 
+    @Override
     protected void tearDown() throws Exception
     {
         reader = null;
@@ -184,7 +186,7 @@ public class MetaDataReaderTest extends
     }
 
     /**
-     * FELIX-4665 - Default values can be empty. 
+     * FELIX-4665 - Default values can be empty.
      */
     public void testAttributeWithDefaultValueOk() throws IOException, XmlPullParserException
     {
@@ -221,7 +223,7 @@ public class MetaDataReaderTest extends
     }
 
     /**
-     * FELIX-4644 - Enforce that we can only have one Object in a Designate element. 
+     * FELIX-4644 - Enforce that we can only have one Object in a Designate element.
      */
     public void testOCDWithoutADFail() throws IOException, XmlPullParserException
     {
@@ -231,15 +233,8 @@ public class MetaDataReaderTest extends
 
         String xml = "<MetaData><OCD id=\"" + ocdId + "\" name=\"" + ocdName + "\"
description=\"" + ocdDescription + "\" /></MetaData>";
 
-        try
-        {
-            read(xml); // should fail!
-            fail("IOException expected!");
-        }
-        catch (IOException e)
-        {
-            assertTrue(e.getMessage().contains("Missing element AD"));
-        }
+        final MetaData md = read(xml);
+        assertNull(md.getObjectClassDefinitions());
     }
 
     /**
@@ -269,7 +264,7 @@ public class MetaDataReaderTest extends
     }
 
     /**
-     * FELIX-4644 - Enforce that we can only have one Object in a Designate element. 
+     * FELIX-4644 - Enforce that we can only have one Object in a Designate element.
      */
     public void testDesignateWithoutObjectFail() throws IOException, XmlPullParserException
     {
@@ -281,19 +276,13 @@ public class MetaDataReaderTest extends
         String xml = "<MetaData><OCD id=\"" + ocdId + "\" name=\"" + ocdName + "\"
description=\"" + ocdDescription + "\"><AD id=\"attr\" type=\"String\" required=\"false\"
/></OCD><Designate pid=\""
             + pid + "\" bundle=\"*\"></Designate></MetaData>";
 
-        try
-        {
-            read(xml); // should fail!
-            fail("IOException expected!");
-        }
-        catch (IOException e)
-        {
-            assertTrue(e.getMessage().contains("Missing element Object"));
-        }
+        final MetaData md = read(xml);
+        assertNull(md.getDesignates());
+        assertEquals(1, md.getObjectClassDefinitions().size());
     }
 
     /**
-     * FELIX-4644 - Enforce that we can only have one Object in a Designate element. 
+     * FELIX-4644 - Enforce that we can only have one Object in a Designate element.
      */
     public void testDesignateWithObjectOk() throws IOException, XmlPullParserException
     {
@@ -326,7 +315,7 @@ public class MetaDataReaderTest extends
     }
 
     /**
-     * FELIX-4644 - Enforce that we can only have one Object in a Designate element. 
+     * FELIX-4644 - Enforce that we can only have one Object in a Designate element.
      */
     public void testDesignateWithTwoObjectsFail() throws IOException, XmlPullParserException
     {
@@ -350,7 +339,7 @@ public class MetaDataReaderTest extends
     }
 
     /**
-     * FELIX-4799 - tests that we can have multiple designates for the same factory PID in
one MetaData configuration. 
+     * FELIX-4799 - tests that we can have multiple designates for the same factory PID in
one MetaData configuration.
      */
     public void testMultipleFactoryDesignatesWithSamePidOk() throws IOException, XmlPullParserException
     {
@@ -366,7 +355,7 @@ public class MetaDataReaderTest extends
     }
 
     /**
-     * FELIX-4799 - tests that we can have multiple designates for the same factory PID in
one MetaData configuration. 
+     * FELIX-4799 - tests that we can have multiple designates for the same factory PID in
one MetaData configuration.
      */
     public void testMultipleFactoryDesignatesWithDifferentPidsOk() throws IOException, XmlPullParserException
     {



Mime
View raw message