Revision: 1191
Author:   ge0ffrey
Date:     2006-05-28 06:10:29 -0700 (Sun, 28 May 2006)
ViewCVS:  http://svn.sourceforge.net/spring-rich-c/?rev=1191&view=rev

Log Message:
-----------
silent exception handler (exception handler unfinished)

Modified Paths:
--------------
    
trunk/spring-richclient/tiger/src/main/java/org/springframework/richclient/exceptionhandling/DelegatingExceptionHandler.java

Added Paths:
-----------
    
trunk/spring-richclient/tiger/src/main/java/org/springframework/richclient/exceptionhandling/LogLevel.java
    
trunk/spring-richclient/tiger/src/main/java/org/springframework/richclient/exceptionhandling/LoggingExceptionHandler.java
    
trunk/spring-richclient/tiger/src/main/java/org/springframework/richclient/exceptionhandling/SilentExceptionHandler.java
Modified: 
trunk/spring-richclient/tiger/src/main/java/org/springframework/richclient/exceptionhandling/DelegatingExceptionHandler.java
===================================================================
--- 
trunk/spring-richclient/tiger/src/main/java/org/springframework/richclient/exceptionhandling/DelegatingExceptionHandler.java
        2006-05-28 12:44:34 UTC (rev 1190)
+++ 
trunk/spring-richclient/tiger/src/main/java/org/springframework/richclient/exceptionhandling/DelegatingExceptionHandler.java
        2006-05-28 13:10:29 UTC (rev 1191)
@@ -20,9 +20,9 @@
  */
 public class DelegatingExceptionHandler implements 
Thread.UncaughtExceptionHandler, InitializingBean {
 
-    private final transient Log logger = LogFactory.getLog(getClass());
+    protected final transient Log logger = LogFactory.getLog(getClass());
 
-    private List<DelegatingExceptionHandlerDelegate> delegateList;
+    protected List<DelegatingExceptionHandlerDelegate> delegateList;
 
     /**
      * Sets the list of delegates.

Added: 
trunk/spring-richclient/tiger/src/main/java/org/springframework/richclient/exceptionhandling/LogLevel.java
===================================================================
--- 
trunk/spring-richclient/tiger/src/main/java/org/springframework/richclient/exceptionhandling/LogLevel.java
                          (rev 0)
+++ 
trunk/spring-richclient/tiger/src/main/java/org/springframework/richclient/exceptionhandling/LogLevel.java
  2006-05-28 13:10:29 UTC (rev 1191)
@@ -0,0 +1,14 @@
+package org.springframework.richclient.exceptionhandling;
+
+/**
+ * This enum is not available in Logging commons, but it should be.
+ * @author Geoffrey De Smet
+ */
+public enum LogLevel {
+    TRACE,
+    DEBUG,
+    INFO,
+    WARN,
+    ERROR,
+    FATAL
+}

Added: 
trunk/spring-richclient/tiger/src/main/java/org/springframework/richclient/exceptionhandling/LoggingExceptionHandler.java
===================================================================
--- 
trunk/spring-richclient/tiger/src/main/java/org/springframework/richclient/exceptionhandling/LoggingExceptionHandler.java
                           (rev 0)
+++ 
trunk/spring-richclient/tiger/src/main/java/org/springframework/richclient/exceptionhandling/LoggingExceptionHandler.java
   2006-05-28 13:10:29 UTC (rev 1191)
@@ -0,0 +1,61 @@
+package org.springframework.richclient.exceptionhandling;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.util.Assert;
+
+/**
+ * Superclass of logging exception handlers.
+ *
+ * @author Geoffrey De Smet
+ */
+public abstract class LoggingExceptionHandler implements 
Thread.UncaughtExceptionHandler, InitializingBean {
+
+    protected static final String LOG_MESSAGE = "Uncaught throwable handled";
+
+    protected final transient Log logger = LogFactory.getLog(getClass());
+
+    protected LogLevel logLevel;
+
+    public void setLogLevel(LogLevel logLevel) {
+        this.logLevel = logLevel;
+    }
+
+    public void afterPropertiesSet() throws Exception {
+        Assert.notNull(logLevel);
+    }
+
+    public final void uncaughtException(Thread thread, Throwable throwable) {
+        logException(thread, throwable);
+        showExceptionToUser(thread, throwable);
+    }
+
+    public void logException(Thread thread, Throwable throwable) {
+        switch (logLevel) {
+            case TRACE:
+                logger.trace(LOG_MESSAGE, throwable);
+                break;
+            case DEBUG:
+                logger.debug(LOG_MESSAGE, throwable);
+                break;
+            case INFO:
+                logger.info(LOG_MESSAGE, throwable);
+                break;
+            case WARN:
+                logger.warn(LOG_MESSAGE, throwable);
+                break;
+            case ERROR:
+                logger.error(LOG_MESSAGE, throwable);
+                break;
+            case FATAL:
+                logger.fatal(LOG_MESSAGE, throwable);
+                break;
+            default:
+                logger.error("Unrecognized log level (" + logLevel + ") for 
throwable", throwable);
+        }
+    }
+
+    public abstract void showExceptionToUser(Thread thread, Throwable 
throwable);
+
+}

Added: 
trunk/spring-richclient/tiger/src/main/java/org/springframework/richclient/exceptionhandling/SilentExceptionHandler.java
===================================================================
--- 
trunk/spring-richclient/tiger/src/main/java/org/springframework/richclient/exceptionhandling/SilentExceptionHandler.java
                            (rev 0)
+++ 
trunk/spring-richclient/tiger/src/main/java/org/springframework/richclient/exceptionhandling/SilentExceptionHandler.java
    2006-05-28 13:10:29 UTC (rev 1191)
@@ -0,0 +1,17 @@
+package org.springframework.richclient.exceptionhandling;
+
+/**
+ * Logs an exception but does not notify the user in any way.
+ * Normally it's a bad practice not to notify the user if something goes wrong.
+ *
+ * @author Geoffrey De Smet
+ */
+public class SilentExceptionHandler extends LoggingExceptionHandler {
+
+    /**
+     * Does nothing.
+     */
+    public void showExceptionToUser(Thread thread, Throwable throwable) {
+    }
+
+}


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
spring-rich-c-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs

Reply via email to