1 25 26 package com.j2biz.blogunity.exception; 27 28 import java.io.PrintStream ; 29 import java.io.PrintWriter ; 30 import java.text.MessageFormat ; 31 32 import org.apache.commons.lang.StringUtils; 33 34 import com.j2biz.blogunity.i18n.I18N; 35 import com.j2biz.blogunity.i18n.I18NMessageManager; 36 import com.j2biz.blogunity.i18n.I18NStatus; 37 38 45 public class BlogunityException extends Exception { 46 47 50 private static final long serialVersionUID = 3617008659184824880L; 51 private I18NStatus status; 52 53 public BlogunityException(I18NStatus status) { 54 55 super((StringUtils.isNotEmpty(status.getKey())) ? status.getKey() : I18N.ERRORS.UNKNOWN); 56 this.status = status; 57 } 58 59 public final I18NStatus getStatus() { 60 return status; 61 } 62 63 67 public void printStackTrace() { 68 printStackTrace(System.err); 69 } 70 71 78 public void printStackTrace(PrintStream output) { 79 PrintWriter writer = new PrintWriter (output); 80 printStackTrace(writer); 81 } 82 83 90 public void printStackTrace(PrintWriter output) { 91 synchronized (output) { 92 if (status.getCause() != null) { 93 output.println(getClass().getName() + "[ErrorKey=" + status.getKey() + "]: "); 94 status.getCause().printStackTrace(output); 95 } else 96 super.printStackTrace(output); 97 } 98 output.flush(); 99 } 100 101 106 public String getMessage() { 107 108 String msg = I18NMessageManager.getInstance().getError(status.getKey()); 109 String [] params = status.getParameters(); 110 111 if (params != null && params.length > 0) { 112 msg = MessageFormat.format(msg, params); 113 } 114 115 return msg; 116 } 117 118 } | Popular Tags |