1 package com.daffodilwoods.database.resource; 2 3 import java.util.*; 4 import java.text.*; 5 import java.sql.SQLException ; 6 7 public class DException extends Exception { 8 9 String dseCode; 10 protected Object [] objarray; 11 12 protected DException prevException; 13 14 public DException getPreviousException() { 15 return (prevException == null) ? null : prevException; 16 } 17 18 public DException(String dsecode, Object [] objarray, DException temp) { 19 this.prevException = temp; 20 this.dseCode = dsecode; 21 this.objarray = objarray; 22 } 23 24 public DException(String dsecode, Object [] objarray) { 25 this.dseCode = dsecode; 26 this.objarray = objarray; 27 } 28 29 public String getMessage() { 30 return getMessage(null); 31 } 32 33 public String getMessage(Locale locale) { 34 String prevMessage = null; 35 if (prevException != null) 36 prevMessage = prevException.getMessage(locale); 37 if (dseCode == null) 38 return super.getMessage(); 39 ResourceBundle manager = null; 40 if (locale != null) 41 manager = ResourceBundle.getBundle("com.daffodilwoods.database.resource.daffodilwoodsLocale", locale); 42 else 43 manager = ResourceBundle.getBundle("com.daffodilwoods.database.resource.daffodilwoodsLocale"); 44 try { 45 MessageFormat mf = new MessageFormat(manager.getString(dseCode)); 46 return (prevMessage != null) ? "\n\t" + mf.format(getParametersAsString()) + "\t" + prevMessage : "\n\t" + mf.format(getParametersAsString()); 47 } catch (Exception ex) { 48 return (prevMessage != null) ? "\n\t" + "Code \"" + dseCode + "\" is not defined" + prevMessage 49 : "\n\t" + "Code \"" + dseCode + "\" is not defined"; 50 } 51 } 52 53 public String getDseCode() { 54 return dseCode; 55 } 56 57 public Object [] getParameters() { 58 return objarray; 59 } 60 61 public void printStackTrace() { 62 if (prevException != null) 63 prevException.printStackTrace(); 64 else 65 super.printStackTrace(); 66 } 67 68 public SQLException getSqlException(Locale locale) { 69 if (dseCode == null) 70 return new SQLException (); 71 try { 72 ResourceBundle manager = ResourceBundle.getBundle("com.daffodilwoods.database.resource.DseToSQL"); 73 int cose = 0; 74 try { 75 String as = dseCode.substring(3); 76 cose = Integer.parseInt(as); 77 } catch (NumberFormatException ex) { 78 } 79 return new SQLException (getMessage(locale), manager.getString(dseCode), cose); 80 } catch (java.util.MissingResourceException mre) { 81 return new SQLException (getMessage(locale)); 82 } 83 } 84 85 public void setParameters(Object [] parameters0) { 86 objarray = parameters0; 87 } 88 89 private String [] getParametersAsString() { 90 if (objarray == null) 91 return null; 92 int length = objarray.length; 93 String [] str = new String [length]; 94 for (int i = 0; i < length; i++) { 95 String temp = "" + objarray[i]; 96 temp = temp.trim(); 97 if (temp.startsWith("the keyword")) { 98 String asd = temp.substring(12); 99 asd = asd.trim(); 100 str[i] = "the keyword '" + asd + "'"; 101 } else 102 103 str[i] = "'" + temp + "'"; 104 } 105 return str; 106 } 107 108 public String getSQLCode() { 109 if (dseCode == null) 110 return ""; 111 try { 112 ResourceBundle manager = 113 ResourceBundle.getBundle("com.daffodilwoods.database.resource.DseToSQL"); 114 return manager.getString(dseCode); 115 } catch (java.util.MissingResourceException mre) { 116 return ""; 117 } 118 } 119 120 public String toString(){ 121 return getMessage().trim(); 122 } 123 } 124 | Popular Tags |