001 package org.springframework.richclient.exceptionhandling.delegation; 002 003 import java.util.Collections; 004 import java.util.List; 005 006 /** 007 * Handles the thrownTrowable by the exception handler if it is an instance of one of the throwableClassList. 008 * Note: Also subclasses of the classes in the throwableClassList will be handled by the exception handler. 009 * 010 * @author Geoffrey De Smet 011 * @since 0.3.0 012 */ 013 public class SimpleExceptionHandlerDelegate extends AbstractExceptionHandlerDelegate { 014 015 private List<Class> throwableClassList; 016 017 public SimpleExceptionHandlerDelegate() { 018 } 019 020 public SimpleExceptionHandlerDelegate(Class throwableClass, 021 Thread.UncaughtExceptionHandler exceptionHandler) { 022 this(Collections.singletonList(throwableClass), exceptionHandler); 023 } 024 025 public SimpleExceptionHandlerDelegate(List<Class> throwableClassList, 026 Thread.UncaughtExceptionHandler exceptionHandler) { 027 super(exceptionHandler); 028 this.throwableClassList = throwableClassList; 029 } 030 031 public void setThrowableClass(Class throwableClass) { 032 setThrowableClassList(Collections.singletonList(throwableClass)); 033 } 034 035 public void setThrowableClassList(List<Class> throwableClassList) { 036 this.throwableClassList = throwableClassList; 037 } 038 039 040 public boolean hasAppropriateHandlerPurged(Throwable throwable) { 041 for (Class throwableClass : throwableClassList) { 042 if (throwableClass.isInstance(throwable)) { 043 return true; 044 } 045 } 046 return false; 047 } 048 049 }