KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > schema2beans > Schema2BeansRuntimeException


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * Schema2BeansRuntimeException
22  * I'd rather this class didn't exist. I wanted to change the API to throw
23  * proper exceptions, but this is difficult to do with so many users of
24  * this library. This class exists to fill in where I found it
25  * difficult to throw a normal Schema2BeansException, since anything
26  * that inherits from RuntimeException doesn't have to be caught.
27  *
28  * With that being said, there are a few times when a RuntimeException
29  * would be approbate enough, but I used Schema2BeansRuntimeException
30  * as it has more features.
31  */

32
33 package org.netbeans.modules.schema2beans;
34
35 import java.util.*;
36 import java.io.*;
37
38 public class Schema2BeansRuntimeException extends RuntimeException JavaDoc implements Serializable {
39     protected Throwable JavaDoc childThrowable;
40     protected String JavaDoc message;
41     protected String JavaDoc stackTrace;
42
43     public Schema2BeansRuntimeException(Throwable JavaDoc e) {
44         super("");
45         //System.out.println("Created Schema2BeansRuntimeException1: e="+e);
46
//e.printStackTrace();
47
childThrowable = e;
48         message = childThrowable.getMessage();
49         genStackTrace();
50     }
51     
52     public Schema2BeansRuntimeException(String JavaDoc mesg) {
53         super(mesg);
54         //System.out.println("Created Schema2BeansRuntimeException3: mesg="+mesg);
55
childThrowable = null;
56         message = mesg;
57         genStackTrace();
58     }
59
60     public Schema2BeansRuntimeException(String JavaDoc mesg, Throwable JavaDoc e) {
61         super(mesg);
62         //System.out.println("Created Schema2BeansRuntimeException2: e="+e+" mesg="+mesg);
63
//e.printStackTrace();
64
childThrowable = e;
65         message = mesg+"\n"+childThrowable.getMessage();
66         genStackTrace();
67     }
68
69     public Throwable JavaDoc getCause() {
70         return childThrowable;
71     }
72     
73     public String JavaDoc getMessage() {
74         return message;
75     }
76
77     protected void genStackTrace() {
78         StringWriter strWriter = new StringWriter();
79         PrintWriter s = new PrintWriter(strWriter);
80         if (childThrowable == null) {
81             super.printStackTrace(s);
82         } else {
83             s.println(super.getMessage());
84             childThrowable.printStackTrace(s);
85         }
86         stackTrace = strWriter.toString();
87    }
88
89     public void printStackTrace(PrintStream s) {
90         s.println(stackTrace);
91     }
92
93     public void printStackTrace(PrintWriter s) {
94         s.println(stackTrace);
95     }
96
97     public void printStackTrace() {
98         System.out.println(stackTrace);
99     }
100 }
101
Popular Tags