1 12 package org.displaytag.exception; 13 14 import org.apache.commons.logging.Log; 15 import org.apache.commons.logging.LogFactory; 16 import org.displaytag.Messages; 17 18 19 24 public abstract class BaseNestableRuntimeException extends RuntimeException 25 { 26 27 30 private final Class sourceClass; 31 32 35 private Throwable nestedException; 36 37 42 public BaseNestableRuntimeException(Class source, String message) 43 { 44 super(message); 45 this.sourceClass = source; 46 47 Log log = LogFactory.getLog(source); 49 50 if (getSeverity() == SeverityEnum.DEBUG) 52 { 53 log.debug(toString()); 54 } 55 else if (getSeverity() == SeverityEnum.INFO) 56 { 57 log.info(toString()); 58 } 59 else if (getSeverity() == SeverityEnum.WARN) 60 { 61 log.warn(toString()); 62 } 63 else 64 { 65 log.error(toString()); 67 } 68 69 } 70 71 77 public BaseNestableRuntimeException(Class source, String message, Throwable cause) 78 { 79 super(message); 80 this.sourceClass = source; 81 this.nestedException = cause; 82 83 Log log = LogFactory.getLog(source); 85 86 if (getSeverity() == SeverityEnum.DEBUG) 88 { 89 log.debug(toString(), cause); 90 } 91 else if (getSeverity() == SeverityEnum.INFO) 92 { 93 log.info(toString(), cause); 94 } 95 else if (getSeverity() == SeverityEnum.WARN) 96 { 97 log.warn(toString(), cause); 98 } 99 else 100 { 101 log.error(toString(), cause); 103 } 104 105 } 106 107 111 public Throwable getCause() 112 { 113 return this.nestedException; 114 } 115 116 120 public String toString() 121 { 122 String className = this.sourceClass.getName(); 123 className = className.substring(className.lastIndexOf(".")); 125 if (this.nestedException == null) 126 { 127 return Messages.getString("NestableException.msg", new Object []{className, getMessage()}); 129 } 130 131 return Messages.getString("NestableException.msgcause", new Object []{className, getMessage(), this.nestedException.getMessage()}); 133 } 134 135 140 public abstract SeverityEnum getSeverity(); 141 142 } | Popular Tags |