harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r426662 - in /incubator/harmony/enhanced/classlib/trunk/modules/logging/src: main/java/java/util/logging/ test/java/org/apache/harmony/logging/tests/java/util/logging/
Date Fri, 28 Jul 2006 20:34:51 GMT
Author: ndbeyer
Date: Fri Jul 28 13:34:50 2006
New Revision: 426662

URL: http://svn.apache.org/viewvc?rev=426662&view=rev
Log:
Code cleanup and simplification.

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ConsoleHandler.java
    incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ErrorManager.java
    incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Filter.java
    incubator/harmony/enhanced/classlib/trunk/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/ErrorManagerTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ConsoleHandler.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ConsoleHandler.java?rev=426662&r1=426661&r2=426662&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ConsoleHandler.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ConsoleHandler.java
Fri Jul 28 13:34:50 2006
@@ -13,7 +13,6 @@
  * limitations under the License.
  */
 
-
 package java.util.logging;
 
 /**
@@ -45,12 +44,6 @@
  */
 public class ConsoleHandler extends StreamHandler {
 
-    /*
-     * -------------------------------------------------------------------
-     * Constructors
-     * -------------------------------------------------------------------
-     */
-
     /**
      * Constructs a <code>ConsoleHandler</code> object.
      */
@@ -58,12 +51,6 @@
         super(System.err);
     }
 
-    /*
-     * -------------------------------------------------------------------
-     * Methods
-     * -------------------------------------------------------------------
-     */
-
     /**
      * Closes this handler. The <code>System.err</code> is flushed but not
      * closed.
@@ -75,15 +62,11 @@
     /**
      * Logs a record if necessary. A flush operation will be done.
      * 
-     * @param record
-     *            the log record to be logged
+     * @param record the log record to be logged
      */
     public void publish(LogRecord record) {
         super.publish(record);
         super.flush();
 
     }
-
 }
-
-

Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ErrorManager.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ErrorManager.java?rev=426662&r1=426661&r2=426662&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ErrorManager.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ErrorManager.java
Fri Jul 28 13:34:50 2006
@@ -13,28 +13,18 @@
  * limitations under the License.
  */
 
-
 package java.util.logging;
 
 /**
- * <code>Handler</code> objects can report errors to the
- * <code>ErrorManager</code> instance attached to them when they encounter any
- * exceptions or errors.
  * <p>
- * Callers of a logger are unlikely to be interested in the exceptions occurred
- * during logging. Use an <code>ErrorManager</code> object to report these
- * exceptions.
+ * An error reporting facility for {@link Handler} implementations to record any
+ * error that may happen during logging. <code>Handlers</code> should report
+ * errors to an <code>ErrorManager</code>, instead of throwing exceptions,
+ * which would interfere with the log issuer's execution.
  * </p>
- * 
  */
 public class ErrorManager {
 
-    /*
-     * -------------------------------------------------------------------
-     * Constants
-     * -------------------------------------------------------------------
-     */
-
     /**
      * The error code indicating a failure that does not fit in any of the
      * specific types of failures that follow.
@@ -66,82 +56,54 @@
      */
     public static final int FORMAT_FAILURE = 5;
 
-    /*
-     * -------------------------------------------------------------------
-     * Instance variables
-     * -------------------------------------------------------------------
-     */
-
-    // Used to synchronize calls to the error method.
-    private Object lock;
-
-    // Indicating whether the current call is the first call.
-    private boolean firstCall;
-
-    /*
-     * -------------------------------------------------------------------
-     * Constructors
-     * -------------------------------------------------------------------
+    /**
+     * An indicator for determining if the error manager has been called at
+     * least once before.
      */
+    private boolean called;
 
     /**
      * Constructs an instance of <code>ErrorManager</code>.
      */
     public ErrorManager() {
-        lock = new Object();
-        firstCall = true;
+        super();
     }
 
-    /*
-     * -------------------------------------------------------------------
-     * Methods
-     * -------------------------------------------------------------------
-     */
-
     /**
-     * Reports an error.
      * <p>
-     * This method can be called by a <code>Handler</code> object when it
-     * encounters an exception or error. The first call to this method will do
-     * the exact error-reporting as desired. Subsequent calls are ignored.
+     * Reports an error using the given message, exception and error code. This
+     * implementation will write out the message to {@link System#err} on the
+     * first call and all subsequent calls are ignored. A subclass of this class
+     * should override this method.
+     * </p>
      * 
-     * @param msg
-     *            the error message which may be <code>null</code>
-     * @param ex
-     *            the exception which may be <code>null</code>
-     * @param errorCode
-     *            the error code indicating the type of the failure
-     */
-    public void error(String msg, Exception ex, int errorCode) {
-        if (firstCall) {
-            // Synchronize concurrent "first" calls
-            synchronized (lock) {
-                if (firstCall) {
-                    outputError(msg, ex, errorCode);
+     * @param message The error message, which may be <code>null</code>.
+     * @param exception The exception associated with the error, which may be
+     *        <code>null</code>.
+     * @param errorCode The error code that identifies the type of error; see
+     *        the constant fields on this class.
+     */
+    public void error(String message, Exception exception, int errorCode) {
+        synchronized (this) {
+            if (called) {
+                return;
+            }
+            synchronized (System.err) {
+                System.err.print(getClass().getName());
+                System.err.print(": Error Code - ");
+                System.err.print(errorCode);
+                if (message != null) {
+                    System.err.print(", Message - ");
+                    System.err.print(message);
+                }
+                if (exception != null) {
+                    System.err.print(", Exception - ");
+                    exception.printStackTrace(System.err);
+                } else {
+                    System.err.println();
                 }
             }
+            called = true;
         }
     }
-
-    //if it is the first time to call error, output it
-    private void outputError(String msg, Exception ex, int errorCode) {
-        StringBuffer sb = new StringBuffer();
-        sb.append(this.getClass().getName());
-        sb.append(": the error code is "); //$NON-NLS-1$
-        sb.append(errorCode);
-        sb.append("."); //$NON-NLS-1$
-        sb.append(LogManager.getSystemLineSeparator());
-        if (null != msg) {
-            sb.append("The error message is: "); //$NON-NLS-1$
-            sb.append(msg);
-            sb.append(LogManager.getSystemLineSeparator());
-        }
-        if (null != ex) {
-            sb.append(ex.toString());
-        }
-        System.err.println(sb);
-        firstCall = false;
-    }
-
 }
-

Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Filter.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Filter.java?rev=426662&r1=426661&r2=426662&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Filter.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Filter.java
Fri Jul 28 13:34:50 2006
@@ -13,31 +13,20 @@
  * limitations under the License.
  */
 
-
 package java.util.logging;
 
 /**
- * <code>Filter</code> objects are used to filter log records that are not
- * desired. <code>Handler</code> or <code>Logger</code> objects can
be
- * attached with a filter to get finer grain control over what should be logged.
- * 
+ * <p>A Filter provides a mechanism for exercising fine-grained control over
+ * what records get logged.</p> 
  */
 public interface Filter {
 
-    /*
-     * -------------------------------------------------------------------
-     * Methods
-     * -------------------------------------------------------------------
-     */
-
     /**
-     * Checks whether the supplied log record needs to be logged.
+     * <p>Checks the {@link LogRecord} to determine if it should be logged.</p>
      * 
-     * @param record
-     *            the log record to be checked
+     * @param record The {@link LogRecord} to be checked.
      * @return <code>true</code> if the supplied log record needs to be
      *         logged, otherwise <code>false</code>
      */
     boolean isLoggable(LogRecord record);
 }
-

Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/ErrorManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/ErrorManagerTest.java?rev=426662&r1=426661&r2=426662&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/ErrorManagerTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/ErrorManagerTest.java
Fri Jul 28 13:34:50 2006
@@ -20,30 +20,21 @@
 import junit.framework.TestCase;
 
 public class ErrorManagerTest extends TestCase {
-	ErrorManager em;
 
-	protected void setUp() throws Exception {
-		super.setUp();
-		em = new ErrorManager();
-	}
+    public void test_errorStringStringint() {
+        ErrorManager em = new ErrorManager();
+        em.error(null, new NullPointerException(), ErrorManager.GENERIC_FAILURE);
+        em.error("An error message.", null, ErrorManager.GENERIC_FAILURE);
+        em.error(null, null, ErrorManager.GENERIC_FAILURE);
+    }
 
-	public void testErrorWithNullParameter() {
-		em.error(null, null, -1);
-		em.error(null, null, -2);
-	}
-
-	public void testError() {
-		em.error("test message, pls ignore it", new RuntimeException(
-				"test exception, pls ignore it"), ErrorManager.CLOSE_FAILURE);
-	}
-
-	public void testConstValue() {
-		assertEquals(3, ErrorManager.CLOSE_FAILURE);
-		assertEquals(2, ErrorManager.FLUSH_FAILURE);
-		assertEquals(5, ErrorManager.FORMAT_FAILURE);
-		assertEquals(0, ErrorManager.GENERIC_FAILURE);
-		assertEquals(4, ErrorManager.OPEN_FAILURE);
-		assertEquals(1, ErrorManager.WRITE_FAILURE);
-	}
+    public void test_constants() {
+        assertEquals(3, ErrorManager.CLOSE_FAILURE);
+        assertEquals(2, ErrorManager.FLUSH_FAILURE);
+        assertEquals(5, ErrorManager.FORMAT_FAILURE);
+        assertEquals(0, ErrorManager.GENERIC_FAILURE);
+        assertEquals(4, ErrorManager.OPEN_FAILURE);
+        assertEquals(1, ErrorManager.WRITE_FAILURE);
+    }
 
 }



Mime
View raw message