Revision: 1570
          http://svn.sourceforge.net/spring-rich-c/?rev=1570&view=rev
Author:   kdonald
Date:     2006-11-21 19:08:02 -0800 (Tue, 21 Nov 2006)

Log Message:
-----------
removed restrictions on resetting the default exception handler -- 
previous code did not work on Mac OS.  Javadoced.

Modified Paths:
--------------
    
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/exceptionhandling/AwtExceptionHandlerAdapterHack.java

Modified: 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/exceptionhandling/AwtExceptionHandlerAdapterHack.java
===================================================================
--- 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/exceptionhandling/AwtExceptionHandlerAdapterHack.java
  2006-11-18 11:21:02 UTC (rev 1569)
+++ 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/exceptionhandling/AwtExceptionHandlerAdapterHack.java
  2006-11-22 03:08:02 UTC (rev 1570)
@@ -2,14 +2,16 @@
 
 import org.apache.commons.logging.LogFactory;
 
-import java.util.Properties;
-
 /**
+ * Uncaught exception handler designed to work with JDK 1.4 and 1.5's 
primitive API for registering 
+ * exception handlers for the event thread.
+ * 
  * It's impossible to set an exception handler for the event thread in jdk 1.4 
(and 1.5).
  * See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4714232
  * So this effectively only works in Sun's JDK.
  *
  * @author Geoffrey De Smet
+ * @author Keith Donald
  * @since 0.3
  */
 public class AwtExceptionHandlerAdapterHack {
@@ -20,35 +22,30 @@
      * Since Sun's JDK constructs the instance, its impossible to inject 
dependencies into it,
      * except by a static reference like this.
      */
-    private static RegisterableExceptionHandler 
registerableUncaughtExceptionHandler = null;
+    private static RegisterableExceptionHandler exceptionHandlerDelegate = 
null;
 
-    public static void registerExceptionHandler(RegisterableExceptionHandler 
registerableUncaughtExceptionHandler) {
-        if 
(AwtExceptionHandlerAdapterHack.registerableUncaughtExceptionHandler != null) {
-            throw new IllegalStateException("There is already an 
uncaughtExceptionHandler set.");
-        }
-        AwtExceptionHandlerAdapterHack.registerableUncaughtExceptionHandler = 
registerableUncaughtExceptionHandler;
-        // Registers this class with the system properties so Sun's JDK can 
pick it up.
-        Properties systemProperties = System.getProperties();
-        if (systemProperties.get(SUN_AWT_EXCEPTION_HANDLER_KEY) != null) {
-            throw new IllegalStateException(
-                    "The exception handler is already set with " + 
SUN_AWT_EXCEPTION_HANDLER_KEY);
-        }
-        systemProperties.put(SUN_AWT_EXCEPTION_HANDLER_KEY, 
AwtExceptionHandlerAdapterHack.class.getName());
+    /**
+     * Sets the [EMAIL PROTECTED] #SUN_AWT_EXCEPTION_HANDLER_KEY} system 
property to register this class as the event thread's 
+     * exception handler.  When called back, this class simply forwards to the 
delegate.
+     * @param exceptionHandlerDelegate the "real" exception handler to 
delegate to when an uncaught exception occurs.
+     */
+    public static void registerExceptionHandler(RegisterableExceptionHandler 
exceptionHandlerDelegate) {
+        AwtExceptionHandlerAdapterHack.exceptionHandlerDelegate = 
exceptionHandlerDelegate;
+        // Registers this class with the system properties so Sun's JDK can 
pick it up.  Always sets even if previously set.
+       System.getProperties().put(SUN_AWT_EXCEPTION_HANDLER_KEY, 
AwtExceptionHandlerAdapterHack.class.getName());
     }
 
-
     /**
      * No-arg constructor required so Sun's JDK can construct the instance.
      */
     public AwtExceptionHandlerAdapterHack() {
     }
 
-
     public void handle(Throwable throwable) {
-        if (registerableUncaughtExceptionHandler == null) {
+        if (exceptionHandlerDelegate == null) {
             LogFactory.getLog(getClass()).error("No uncaughtExceptionHandler 
set while handling throwable.", throwable);
         }
-        
registerableUncaughtExceptionHandler.uncaughtException(Thread.currentThread(), 
throwable);
+        exceptionHandlerDelegate.uncaughtException(Thread.currentThread(), 
throwable);
     }
 
 }


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

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
spring-rich-c-cvs mailing list
spring-rich-c-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs

Reply via email to