KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > database > resource > DRuntimeException


1 package com.daffodilwoods.database.resource;
2
3 import java.util.*;
4 import java.text.*;
5
6
7 public class DRuntimeException extends RuntimeException JavaDoc {
8
9     protected DException prevException;
10     String JavaDoc dseCode;
11     Object JavaDoc[] objarray;
12
13     public DRuntimeException(String JavaDoc dsecode,Object JavaDoc[] objarray) {
14       this.dseCode = dsecode;
15       this.objarray = objarray;
16     }
17
18     public DRuntimeException(String JavaDoc dsecode,Object JavaDoc[] 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 JavaDoc getMessage(Locale locale) {
29       String JavaDoc 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 JavaDoc 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 JavaDoc getDseCode() {
50         return dseCode;
51     }
52
53     public Object JavaDoc[] getParameters() {
54         return objarray;
55     }
56
57     public String JavaDoc getMessage() {
58       return getMessage(null);
59     }
60
61     public void printStackTrace() {
62       super.printStackTrace();
63     }
64
65     private String JavaDoc[] getParametersAsString(){
66        if(objarray == null)
67           return null;
68        int length = objarray.length;
69        String JavaDoc[] str = new String JavaDoc[length];
70        for (int i = 0; i < length; i++) {
71           String JavaDoc temp = ""+objarray[i];
72           temp = temp.trim();
73           if(temp.startsWith("the keyword")){
74              String JavaDoc 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 JavaDoc toString(){
85        return getMessage().trim();
86     }
87 }
88
Popular Tags