1 12 13 package com.openedit; 14 15 import java.io.PrintWriter ; 16 import java.io.Serializable ; 17 import java.io.StringWriter ; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 22 23 24 29 public class OpenEditException extends Exception implements Serializable 30 { 31 private static final long serialVersionUID = 1630227379714618008L; 32 33 private static final Log log = LogFactory.getLog(OpenEditException.class); 34 protected String fieldPathWithError; 35 36 public OpenEditException() 37 { 38 this("No Error Entered"); 39 } 40 public OpenEditException(String inMsg) 41 { 42 this(inMsg, (Throwable ) null); 43 } 44 45 public OpenEditException(String inMsg, String inPath) 46 { 47 this(inMsg, null, inPath); 48 } 49 50 public OpenEditException(String inMsg, Throwable inRootCause, String inPath) 51 { 52 super(inMsg, inRootCause); 53 54 if (inRootCause instanceof OpenEditException) 55 { 56 log.error("Should not wrap an exception of type OpenEditException "); 57 } 58 setPathWithError(inPath); 59 } 60 61 public OpenEditException(String inMsg, Throwable inRootCause) 62 { 63 this(inMsg, inRootCause, null); 64 } 65 66 public OpenEditException(Throwable inRootCause, String inPath) 67 { 68 this(null, inRootCause, inPath); 69 } 70 71 public OpenEditException(Throwable inRootCause) 72 { 73 this(inRootCause.getMessage(), inRootCause); 74 } 75 76 81 public String getMessage() 82 { 83 String message = super.getMessage(); 84 85 if ((message == null) || (message.length() == 0)) 86 { 87 if (getCause() != null) 88 { 89 return getCause().getMessage(); 90 } 91 else 92 { 93 return "No error message"; 94 } 95 } 96 else 97 { 98 return message; 99 } 100 } 101 102 107 public void setPathWithError(String fieldPathWithError) 108 { 109 this.fieldPathWithError = fieldPathWithError; 110 } 111 112 117 public String getPathWithError() 118 { 119 return fieldPathWithError; 120 } 121 122 127 public String toStackTrace() 128 { 129 StringWriter out = new StringWriter (); 130 131 if (getCause() != null) 132 { 133 getCause().printStackTrace(new PrintWriter (out)); 134 } 135 else 136 { 137 printStackTrace(new PrintWriter (out)); 138 } 139 140 return out.toString(); 141 } 142 } 143 | Popular Tags |