1 12 package org.displaytag.exception; 13 14 import javax.servlet.jsp.JspTagException ; 15 16 import org.apache.commons.logging.Log; 17 import org.apache.commons.logging.LogFactory; 18 import org.displaytag.Messages; 19 20 21 26 public abstract class BaseNestableJspTagException extends JspTagException 27 { 28 29 32 private final Class sourceClass; 33 34 37 private Throwable nestedException; 38 39 44 public BaseNestableJspTagException(Class source, String message) 45 { 46 super(message); 47 this.sourceClass = source; 48 49 Log log = LogFactory.getLog(source); 51 52 if (getSeverity() == SeverityEnum.DEBUG) 54 { 55 log.debug(toString()); 56 } 57 else if (getSeverity() == SeverityEnum.INFO) 58 { 59 log.info(toString()); 60 } 61 else if (getSeverity() == SeverityEnum.WARN) 62 { 63 log.warn(toString()); 64 } 65 else 66 { 67 log.error(toString()); 69 } 70 71 } 72 73 79 public BaseNestableJspTagException(Class source, String message, Throwable cause) 80 { 81 super(message); 82 this.sourceClass = source; 83 this.nestedException = cause; 84 85 Log log = LogFactory.getLog(source); 87 88 if (getSeverity() == SeverityEnum.DEBUG) 90 { 91 log.debug(toString(), cause); 92 } 93 else if (getSeverity() == SeverityEnum.INFO) 94 { 95 log.info(toString(), cause); 96 } 97 else if (getSeverity() == SeverityEnum.WARN) 98 { 99 log.warn(toString(), cause); 100 } 101 else 102 { 103 log.error(toString(), cause); 105 } 106 107 } 108 109 113 public Throwable getCause() 114 { 115 return this.nestedException; 116 } 117 118 122 public String toString() 123 { 124 String className = this.sourceClass.getName(); 125 className = className.substring(className.lastIndexOf(".")); 127 if (this.nestedException == null) 128 { 129 return Messages.getString("NestableException.msg", new Object []{className, getMessage()}); 131 } 132 133 return Messages.getString("NestableException.msgcause", new Object []{className, getMessage(), this.nestedException.getMessage()}); 135 } 136 137 142 public abstract SeverityEnum getSeverity(); 143 144 } | Popular Tags |