1 package com.daffodilwoods.database.resource; 2 3 import java.util.*; 4 import java.text.*; 5 6 7 public class DRuntimeException extends RuntimeException { 8 9 protected DException prevException; 10 String dseCode; 11 Object [] objarray; 12 13 public DRuntimeException(String dsecode,Object [] objarray) { 14 this.dseCode = dsecode; 15 this.objarray = objarray; 16 } 17 18 public DRuntimeException(String dsecode,Object [] objarray,DException prevEx) { 19 this.prevException = prevEx; 20 this.dseCode = dsecode; 21 this.objarray = objarray; 22 } 23 24 public DException getPreviousException(){ 25 return (prevException==null) ? null : prevException; 26 } 27 28 public String getMessage(Locale locale) { 29 String prevMessage = null; 30 if(prevException!=null) 31 prevMessage = prevException.getMessage(locale); 32 if(dseCode==null) 33 return super.getMessage(); 34 ResourceBundle manager = null; 35 if(locale != null ) 36 manager = ResourceBundle.getBundle("com.daffodilwoods.database.resource.daffodilwoodsLocale", locale); 37 else 38 manager = ResourceBundle.getBundle("com.daffodilwoods.database.resource.daffodilwoodsLocale"); 39 try { 40 MessageFormat mf = new MessageFormat(manager.getString(dseCode)); 41 return (prevMessage!=null) ? "\n\t"+mf.format(getParametersAsString())+prevMessage : "\n\t"+mf.format(getParametersAsString()); 42 } 43 catch (Exception ex) { 44 return (prevMessage!=null) ? "\n\t"+"Code \""+dseCode+"\" is not defined"+prevMessage 45 : "\n\t"+"Code \""+dseCode+"\" is not defined"; 46 } 47 } 48 49 public String getDseCode() { 50 return dseCode; 51 } 52 53 public Object [] getParameters() { 54 return objarray; 55 } 56 57 public String getMessage() { 58 return getMessage(null); 59 } 60 61 public void printStackTrace() { 62 super.printStackTrace(); 63 } 64 65 private String [] getParametersAsString(){ 66 if(objarray == null) 67 return null; 68 int length = objarray.length; 69 String [] str = new String [length]; 70 for (int i = 0; i < length; i++) { 71 String temp = ""+objarray[i]; 72 temp = temp.trim(); 73 if(temp.startsWith("the keyword")){ 74 String asd = temp.substring(12); 75 asd = asd.trim(); 76 str[i] = "the keyword '"+asd+"'"; 77 } 78 else 79 str[i] = "'"+temp+"'"; 80 } 81 return str; 82 } 83 84 public String toString(){ 85 return getMessage().trim(); 86 } 87 } 88 | Popular Tags |