[patch] Logkit cleanups

Peter Donald <[email protected]>
Newsgroups gmane.comp.jakarta.avalon.apps.devel,gmane.comp.jakarta.avalon.devel
Message-ID <[email protected]>
Makes sure target arrays contain no nulls and a few other cleanups
-- 
Cheers,

Peter Donald
----------------------------------------------------------------
Fools ignore complexity.  Pragmatists suffer it.
Some can avoid it.  Geniuses remove it.
-- Perlis's Programming Proverb #58, SIGPLAN Notices, Sept. 1982
----------------------------------------------------------------

--
To unsubscribe, e-mail:   <mailto:[email protected]>
For additional commands, e-mail: <mailto:[email protected]>
logkit.txt (text/plain, 7.9 KB)
? logkit.txt
? lib/activation.jar
? lib/jms.jar
? lib/mail_1_2.jar
Index: src/java/org/apache/log/Logger.java
===================================================================
RCS file: /home/cvspublic/jakarta-avalon-logkit/src/java/org/apache/log/Logger.java,v
retrieving revision 1.31
diff -u -r1.31 Logger.java
--- src/java/org/apache/log/Logger.java	7 Oct 2002 16:39:02 -0000	1.31
+++ src/java/org/apache/log/Logger.java	11 Dec 2002 22:36:05 -0000
@@ -14,6 +14,8 @@
  */
 public class Logger
 {
+    private static final Logger[] EMPTY_SET = new Logger[ 0 ];
+
     ///Separator character use to separate different categories
     public static final char CATEGORY_SEPARATOR = '.';
 
@@ -360,7 +362,22 @@
      */
     public synchronized void setLogTargets( final LogTarget[] logTargets )
     {
+        if( null != logTargets )
+        {
+            //Make sure that the array passed in does not have any
+            //nulls in it before we actually do the assignment
+            for( int i = 0; i < logTargets.length; i++ )
+            {
+                if( null == logTargets[ i ] )
+                {
+                    final String message = "logTargets[ " + i + " ]";
+                    throw new NullPointerException( message );
+                }
+            }
+        }
+
         m_logTargets = logTargets;
+
         setupErrorHandlers();
         m_logTargetsForceSet = true;
         resetChildLogTargets( false );
@@ -384,9 +401,13 @@
     public synchronized void unsetLogTargets( final boolean recursive )
     {
         if( null != m_parent )
+        {
             m_logTargets = m_parent.safeGetLogTargets();
+        }
         else
+        {
             m_logTargets = null;
+        }
 
         m_logTargetsForceSet = false;
         resetChildLogTargets( recursive );
@@ -400,7 +421,9 @@
     public synchronized Logger[] getChildren()
     {
         if( null == m_children )
-            return new Logger[ 0 ];
+        {
+            return EMPTY_SET;
+        }
 
         final Logger[] children = new Logger[ m_children.length ];
 
@@ -679,7 +702,6 @@
         else
         {
             final LogTarget[] logTargets = new LogTarget[ m_logTargets.length ];
-
             for( int i = 0; i < logTargets.length; i++ )
             {
                 logTargets[ i ] = m_logTargets[ i ];
Index: src/java/org/apache/log/Priority.java
===================================================================
RCS file: /home/cvspublic/jakarta-avalon-logkit/src/java/org/apache/log/Priority.java,v
retrieving revision 1.13
diff -u -r1.13 Priority.java
--- src/java/org/apache/log/Priority.java	27 Nov 2002 07:54:37 -0000	1.13
+++ src/java/org/apache/log/Priority.java	11 Dec 2002 22:36:05 -0000
@@ -7,7 +7,6 @@
  */
 package org.apache.log;
 
-import java.io.ObjectStreamException;
 import java.io.Serializable;
 
 /**
@@ -49,7 +48,7 @@
      * Do not log anything.
      */
     public static final Priority NONE = new Priority( "NONE", Integer.MAX_VALUE );
-    
+
     private final String m_name;
     private final int m_priority;
 
@@ -62,19 +61,33 @@
     public static Priority getPriorityForName( final String priority )
     {
         if( Priority.DEBUG.getName().equals( priority ) )
+        {
             return Priority.DEBUG;
+        }
         else if( Priority.INFO.getName().equals( priority ) )
+        {
             return Priority.INFO;
+        }
         else if( Priority.WARN.getName().equals( priority ) )
+        {
             return Priority.WARN;
+        }
         else if( Priority.ERROR.getName().equals( priority ) )
+        {
             return Priority.ERROR;
+        }
         else if( Priority.FATAL_ERROR.getName().equals( priority ) )
+        {
             return Priority.FATAL_ERROR;
+        }
         else if( Priority.NONE.getName().equals( priority ) )
+        {
             return Priority.NONE;
+        }
         else
+        {
             return Priority.DEBUG;
+        }
     }
 
     /**
@@ -85,6 +98,11 @@
      */
     private Priority( final String name, final int priority )
     {
+        if( null == name )
+        {
+            throw new NullPointerException( "name" );
+        }
+
         m_name = name;
         m_priority = priority;
     }
@@ -153,10 +171,8 @@
      * Helper method that replaces deserialized object with correct singleton.
      *
      * @return the singleton version of object
-     * @exception ObjectStreamException if an error occurs
      */
     private Object readResolve()
-        throws ObjectStreamException
     {
         return getPriorityForName( m_name );
     }
Index: src/java/org/apache/log/output/db/ColumnType.java
===================================================================
RCS file: /home/cvspublic/jakarta-avalon-logkit/src/java/org/apache/log/output/db/ColumnType.java,v
retrieving revision 1.4
diff -u -r1.4 ColumnType.java
--- src/java/org/apache/log/output/db/ColumnType.java	20 May 2002 10:12:50 -0000	1.4
+++ src/java/org/apache/log/output/db/ColumnType.java	11 Dec 2002 22:36:05 -0000
@@ -14,9 +14,6 @@
  */
 public class ColumnType
 {
-    //x-db sequencer...
-    public static final int SEQUENCE = 0;
-
     public static final int STATIC = 1;
     public static final int CATEGORY = 2;
     public static final int CONTEXT = 3;
@@ -34,7 +31,6 @@
      */
     //public static final int     MAX_TYPE        = IPADDRESS;
 
-    public static final String SEQUENCE_STR = "sequence";
     public static final String STATIC_STR = "static";
     public static final String CATEGORY_STR = "category";
     public static final String CONTEXT_STR = "context";
@@ -50,22 +46,38 @@
     public static int getTypeIdFor( final String type )
     {
         if( type.equalsIgnoreCase( CATEGORY_STR ) )
+        {
             return CATEGORY;
+        }
         else if( type.equalsIgnoreCase( STATIC_STR ) )
+        {
             return STATIC;
+        }
         else if( type.equalsIgnoreCase( CONTEXT_STR ) )
+        {
             return CONTEXT;
+        }
         else if( type.equalsIgnoreCase( MESSAGE_STR ) )
+        {
             return MESSAGE;
+        }
         else if( type.equalsIgnoreCase( PRIORITY_STR ) )
+        {
             return PRIORITY;
+        }
         else if( type.equalsIgnoreCase( TIME_STR ) )
+        {
             return TIME;
+        }
         else if( type.equalsIgnoreCase( RELATIVE_TIME_STR ) )
+        {
             return RELATIVE_TIME;
+        }
         //else if( type.equalsIgnoreCase( IPADDRESS_STR ) ) return IPADDRESS;
         else if( type.equalsIgnoreCase( HOSTNAME_STR ) )
+        {
             return HOSTNAME;
+        }
         else if( type.equalsIgnoreCase( THROWABLE_STR ) )
         {
             return THROWABLE;
Index: src/java/org/apache/log/output/db/DefaultJDBCTarget.java
===================================================================
RCS file: /home/cvspublic/jakarta-avalon-logkit/src/java/org/apache/log/output/db/DefaultJDBCTarget.java,v
retrieving revision 1.4
diff -u -r1.4 DefaultJDBCTarget.java
--- src/java/org/apache/log/output/db/DefaultJDBCTarget.java	27 Mar 2002 22:07:57 -0000	1.4
+++ src/java/org/apache/log/output/db/DefaultJDBCTarget.java	11 Dec 2002 22:36:06 -0000
@@ -229,30 +229,13 @@
 
     private String getContextMap( final ContextMap map, final String aux )
     {
-        if( null == map ) return "";
-        return map.get( aux, "" ).toString();
+        if( null == map )
+        {
+            return "";
+        }
+        else
+        {
+            return map.get( aux, "" ).toString();
+        }
     }
-    /*
-      protected String getHostName( final LogEvent event, final String aux )
-      {
-      String result = null;
-
-      final ContextMap map = event.getContextMap();
-      if( null != map )
-      {
-      final Object object = map.get( "hostname" );
-      if( null != object )
-      {
-      result = object.toString();
-      }
-      }
-
-      if( null == result )
-      {
-      result = "Unknown hostname";
-      }
-
-      return result;
-      }
-    */
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.