1 17 18 package org.sape.carbon.core.exception; 19 20 21 import org.sape.carbon.core.util.classify.SeverityEnum; 22 23 import org.apache.commons.logging.Log; 24 import org.apache.commons.logging.LogFactory; 25 26 27 28 38 public class DefaultExceptionDelegateImpl implements ExceptionDelegate { 39 40 43 private Throwable delegatee; 44 45 48 private String message; 49 50 53 private Throwable cause; 54 55 59 private Class exceptionSource; 60 61 64 private SeverityEnum severity; 65 66 67 68 71 public DefaultExceptionDelegateImpl() { 72 73 } 74 75 76 80 public void handleException() { 81 82 Log log = LogFactory.getLog(getExceptionSource()); 84 85 if (this.severity == SeverityEnum.FATAL) { 86 if (log.isFatalEnabled()) { 87 log.fatal( 88 ExceptionUtility.printStackTracesToString(this.delegatee)); 89 } 90 } else if (this.severity == SeverityEnum.ERROR) { 91 if (log.isErrorEnabled()) { 92 log.error( 93 ExceptionUtility.printStackTracesToString(this.delegatee)); 94 } 95 } else if (this.severity == SeverityEnum.WARN) { 96 if (log.isWarnEnabled()) { 97 log.warn( 98 ExceptionUtility.printStackTracesToString(this.delegatee)); 99 } 100 } else if (this.severity == SeverityEnum.INFO) { 101 if (log.isInfoEnabled()) { 102 log.info( 103 ExceptionUtility.printStackTracesToString(this.delegatee)); 104 } 105 } else if (this.severity == SeverityEnum.DEBUG) { 106 if (log.isDebugEnabled()) { 107 log.debug( 108 ExceptionUtility.printStackTracesToString(this.delegatee)); 109 } 110 } else { 111 if (log.isTraceEnabled()) { 113 log.trace( 114 ExceptionUtility.printStackTracesToString(this.delegatee)); 115 } 116 } 117 } 118 119 123 public Throwable getCause() { 124 return this.cause; 125 } 126 127 128 129 133 public SeverityEnum getSeverity() { 134 return this.severity; 135 } 136 137 141 public Class getExceptionSource() { 142 return this.exceptionSource; 143 } 144 145 149 public String getClassName() { 150 return this.delegatee.getClass().getName(); 151 } 152 153 154 155 159 public String getMessage() { 160 return this.message; 161 } 162 163 167 public Throwable getDelegatee() { 168 return this.delegatee; 169 } 170 171 181 public void setCause(Throwable cause) { 182 this.cause = cause; 183 } 184 185 189 public void setDelegatee(Throwable delegatee) { 190 this.delegatee = delegatee; 191 } 192 193 197 public void setMessage(String message) { 198 this.message = message; 199 } 200 201 208 public void setSeverity(SeverityEnum severity) { 209 this.severity = severity; 210 } 211 212 222 public void setExceptionSource(Class exceptionSource) { 223 this.exceptionSource = exceptionSource; 224 } 225 226 227 233 public String toString() { 234 235 StringBuffer buf = 236 new StringBuffer ("EXCEPTION: "); 237 238 buf.append(this.delegatee.getClass().getName()); 239 buf.append(",\n MESSAGE: " + this.message); 240 241 if (this.cause != null) { 243 buf.append(";\n CAUSE: ("); 244 buf.append(this.cause.toString() + ")"); 245 } 246 249 return buf.toString(); 250 } 251 } | Popular Tags |