org.springframework.richclient.exceptionhandling.delegation
Class DelegatingExceptionHandler

java.lang.Object
  extended by org.springframework.richclient.exceptionhandling.AbstractRegisterableExceptionHandler
      extended by org.springframework.richclient.exceptionhandling.delegation.DelegatingExceptionHandler
All Implemented Interfaces:
Thread.UncaughtExceptionHandler, InitializingBean, RegisterableExceptionHandler

public class DelegatingExceptionHandler
extends AbstractRegisterableExceptionHandler
implements InitializingBean

An exception handler that selects an appropriate exception handler from a list based on the thrown exception and delegates the handling of the exception to it.

This class works very similar to catch statements: the first delegate which can handle the exception will handle it. For example, consider 3 simple delegates for the following classes in this order: NullPointerException (1), RuntimeException (2), IllegalArgumentException (3). A thrown IllegalArgumentException will be handled by the (2) handler. The (3) handler is useless.

Since:
0.3.0
Author:
Geoffrey De Smet
See Also:
ExceptionHandlerDelegate, SimpleExceptionHandlerDelegate

Field Summary
protected  List<ExceptionHandlerDelegate> delegateList
           
protected  ExceptionPurger exceptionPurger
           
protected  org.apache.commons.logging.Log logger
           
 
Constructor Summary
DelegatingExceptionHandler()
           
 
Method Summary
 void afterPropertiesSet()
           
 void setDelegateList(List<ExceptionHandlerDelegate> delegateList)
          Sets the list of delegates.
 void setExceptionPurger(ExceptionPurger exceptionPurger)
          If set the throwable will first be purged before handling it.
 void uncaughtException(Thread thread, Throwable throwable)
          Delegates the throwable to the appropriate delegate exception handler.
 
Methods inherited from class org.springframework.richclient.exceptionhandling.AbstractRegisterableExceptionHandler
registerExceptionHandler
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final transient org.apache.commons.logging.Log logger

delegateList

protected List<ExceptionHandlerDelegate> delegateList

exceptionPurger

protected ExceptionPurger exceptionPurger
Constructor Detail

DelegatingExceptionHandler

public DelegatingExceptionHandler()
Method Detail

setDelegateList

public void setDelegateList(List<ExceptionHandlerDelegate> delegateList)
Sets the list of delegates. This is not a map because the order is important and delegate selection is not a simple key based selector.

Parameters:
delegateList - a list of DelegatingExceptionHandlerDelegate

setExceptionPurger

public void setExceptionPurger(ExceptionPurger exceptionPurger)
If set the throwable will first be purged before handling it.

Parameters:
exceptionPurger -

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
Exception

uncaughtException

public void uncaughtException(Thread thread,
                              Throwable throwable)
Delegates the throwable to the appropriate delegate exception handler.

Specified by:
uncaughtException in interface Thread.UncaughtExceptionHandler
Specified by:
uncaughtException in interface RegisterableExceptionHandler
Parameters:
thread - the thread in which the throwable occurred
throwable - the thrown throwable


Copyright © 2004-2008 The Spring Framework. All Rights Reserved.