1 package org.sapia.validator; 2 3 import java.io.PrintWriter ; 4 import java.io.StringWriter ; 5 6 16 public class ValidationErr { 17 private String _id; 18 private Object _msg; 19 20 23 ValidationErr(String id, Throwable message) { 24 _id = id; 25 _msg = message; 26 } 27 28 31 ValidationErr(String id, String message) { 32 _id = id; 33 _msg = message; 34 } 35 36 41 public String getId() { 42 return _id; 43 } 44 45 51 public String getMsg() { 52 if(_msg != null){ 53 if(_msg instanceof Throwable ){ 54 return ((Throwable )_msg).getMessage(); 55 } 56 return (String )_msg; 57 } 58 else{ 59 return null; 60 } 61 } 62 63 69 public Throwable getThrowable() { 70 return (Throwable ) _msg; 71 } 72 73 80 public boolean isThrowable() { 81 return _msg instanceof Throwable ; 82 } 83 84 95 public String getStackTrace(){ 96 if(!isThrowable()){ 97 throw new IllegalStateException ("Internal error is not an instance of " + Throwable .class.getName()); 98 99 } 100 StringWriter sw = new StringWriter (); 101 PrintWriter pw = new PrintWriter (sw, true); 102 Throwable t = (Throwable )_msg; 103 t.printStackTrace(pw); 104 pw.close(); 105 return sw.toString(); 106 } 107 } 108 | Popular Tags |