poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r638815 - in /poi/trunk/src: documentation/content/xdocs/ java/org/apache/poi/util/ testcases/org/apache/poi/poifs/storage/
Date Wed, 19 Mar 2008 12:49:46 GMT
Author: nick
Date: Wed Mar 19 05:49:35 2008
New Revision: 638815

URL: http://svn.apache.org/viewvc?rev=638815&view=rev
Log:
Fix bug #44627 - improve the thread safety of POILogFactory

Modified:
    poi/trunk/src/documentation/content/xdocs/changes.xml
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/util/POILogFactory.java
    poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java
    poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java

Modified: poi/trunk/src/documentation/content/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/changes.xml?rev=638815&r1=638814&r2=638815&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/changes.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/changes.xml Wed Mar 19 05:49:35 2008
@@ -36,6 +36,7 @@
 
 		<!-- Don't forget to update status.xml too! -->
         <release version="3.1-beta1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">44627 - Improve the thread safety
of POILogFactory</action>
            <action dev="POI-DEVELOPERS" type="add">30311 - Initial support for Conditional
Formatting</action>
            <action dev="POI-DEVELOPERS" type="fix">44609 - Handle leading spaces in
formulas, such as '= 4'</action>
            <action dev="POI-DEVELOPERS" type="add">44608 - Support for PercentPtg in
the formula evaluator</action>

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=638815&r1=638814&r2=638815&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Wed Mar 19 05:49:35 2008
@@ -33,6 +33,7 @@
 	<!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.1-beta1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">44627 - Improve the thread safety
of POILogFactory</action>
            <action dev="POI-DEVELOPERS" type="add">30311 - Initial support for Conditional
Formatting</action>
            <action dev="POI-DEVELOPERS" type="fix">44609 - Handle leading spaces in
formulas, such as '= 4'</action>
            <action dev="POI-DEVELOPERS" type="add">44608 - Support for PercentPtg in
the formula evaluator</action>

Modified: poi/trunk/src/java/org/apache/poi/util/POILogFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/POILogFactory.java?rev=638815&r1=638814&r2=638815&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/POILogFactory.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/POILogFactory.java Wed Mar 19 05:49:35 2008
@@ -33,14 +33,25 @@
 public class POILogFactory
 {
 
-    // map of POILogger instances, with classes as keys
-    private static Map          _loggers = new HashMap();;
-
+    /**
+     * Map of POILogger instances, with classes as keys
+     */
+    private static Map _loggers = new HashMap();;
 
     /**
-     * construct a POILogFactory.
+     * A common instance of NullLogger, as it does nothing
+     *  we only need the one
+     */
+    private static POILogger _nullLogger = new NullLogger();
+    /**
+     * The name of the class to use. Initialised the
+     *  first time we need it
      */
+    private static String _loggerClassName = null;
 
+    /**
+     * Construct a POILogFactory.
+     */
     private POILogFactory()
     {
     }
@@ -69,28 +80,48 @@
     public static POILogger getLogger(final String cat)
     {
         POILogger logger = null;
+        
+        // If we haven't found out what logger to use yet,
+        //  then do so now
+        // Don't look it up until we're first asked, so
+        //  that our users can set the system property
+        //  between class loading and first use
+        if(_loggerClassName == null) {
+        	try {
+        		_loggerClassName = System.getProperty("org.apache.poi.util.POILogger");
+        	} catch(Exception e) {}
+        	
+        	// Use the default logger if none specified,
+        	//  or none could be fetched
+        	if(_loggerClassName == null) {
+        		_loggerClassName = _nullLogger.getClass().getName();
+        	}
+        }
+        
+        // Short circuit for the null logger, which
+        //  ignores all categories
+        if(_loggerClassName.equals(_nullLogger.getClass().getName())) {
+        	return _nullLogger;
+        }
 
-        if (_loggers.containsKey(cat))
-        {
+        
+        // Fetch the right logger for them, creating
+        //  it if that's required 
+        if (_loggers.containsKey(cat)) {
             logger = ( POILogger ) _loggers.get(cat);
-        }
-        else
-        {
-            try{
-              String loggerClassName = System.getProperty("org.apache.poi.util.POILogger");
-              Class loggerClass = Class.forName(loggerClassName);
+        } else {
+            try {
+              Class loggerClass = Class.forName(_loggerClassName);
               logger = ( POILogger ) loggerClass.newInstance();
+              logger.initialize(cat);
+            } catch(Exception e) {
+              // Give up and use the null logger
+              logger = _nullLogger;
             }
-            catch(Exception e){
-            
-              logger = new NullLogger();
-            }
-            
-            logger.initialize(cat);
             
+            // Save for next time
             _loggers.put(cat, logger);
         }
         return logger;
     }
-        
-}   // end public class POILogFactory
+}   // end public class POILogFactory
\ No newline at end of file

Modified: poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java?rev=638815&r1=638814&r2=638815&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java Wed Mar 19
05:49:35 2008
@@ -36,23 +36,23 @@
 public class TestRawDataBlock
     extends TestCase
 {
+	static {
+        // We always want to use our own
+        //  logger
+        System.setProperty(
+        		"org.apache.poi.util.POILogger",
+        		"org.apache.poi.util.DummyPOILogger"
+        );
+	}
 
     /**
      * Constructor TestRawDataBlock
      *
      * @param name
      */
-
     public TestRawDataBlock(String name)
     {
         super(name);
-        
-        // We always want to use our own
-        //  logger
-        System.setProperty(
-        		"org.apache.poi.util.POILogger",
-        		"org.apache.poi.util.DummyPOILogger"
-        );
     }
 
     /**

Modified: poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java?rev=638815&r1=638814&r2=638815&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java Wed Mar
19 05:49:35 2008
@@ -36,23 +36,23 @@
 public class TestRawDataBlockList
     extends TestCase
 {
+	static {
+        // We always want to use our own
+        //  logger
+        System.setProperty(
+        		"org.apache.poi.util.POILogger",
+        		"org.apache.poi.util.DummyPOILogger"
+        );
+	}
 
     /**
      * Constructor TestRawDataBlockList
      *
      * @param name
      */
-
     public TestRawDataBlockList(String name)
     {
         super(name);
-        
-        // We always want to use our own
-        //  logger
-        System.setProperty(
-        		"org.apache.poi.util.POILogger",
-        		"org.apache.poi.util.DummyPOILogger"
-        );
     }
 
     /**
@@ -60,7 +60,6 @@
      *
      * @exception IOException
      */
-
     public void testNormalConstructor()
         throws IOException
     {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message