KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > xml > bind > JAXBException


1 /*
2  * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
3  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
4  */

5
6 package javax.xml.bind;
7
8 import java.io.PrintWriter JavaDoc;
9
10 /**
11  * This is the root exception class for all JAXB exceptions.
12  *
13  * @author <ul><li>Ryan Shoemaker, Sun Microsystems, Inc.</li></ul>
14  * @version $Revision: 1.3 $ $Date: 2004/10/22 15:46:02 $
15  * @see JAXBContext
16  * @see Marshaller
17  * @see Unmarshaller
18  * @since JAXB1.0
19  */

20 public class JAXBException extends Exception JavaDoc {
21   
22     /**
23      * Vendor specific error code
24      *
25      */

26     private String JavaDoc errorCode;
27
28     /**
29      * Exception reference
30      *
31      */

32     private Throwable JavaDoc linkedException;
33
34     static final long serialVersionUID = -5621384651494307979L;
35
36     /**
37      * Construct a JAXBException with the specified detail message. The
38      * errorCode and linkedException will default to null.
39      *
40      * @param message a description of the exception
41      */

42     public JAXBException(String JavaDoc message) {
43         this( message, null, null );
44     }
45
46     /**
47      * Construct a JAXBException with the specified detail message and vendor
48      * specific errorCode. The linkedException will default to null.
49      *
50      * @param message a description of the exception
51      * @param errorCode a string specifying the vendor specific error code
52      */

53     public JAXBException(String JavaDoc message, String JavaDoc errorCode) {
54         this( message, errorCode, null );
55     }
56
57     /**
58      * Construct a JAXBException with a linkedException. The detail message and
59      * vendor specific errorCode will default to null.
60      *
61      * @param exception the linked exception
62      */

63     public JAXBException(Throwable JavaDoc exception) {
64         this( null, null, exception );
65     }
66     
67     /**
68      * Construct a JAXBException with the specified detail message and
69      * linkedException. The errorCode will default to null.
70      *
71      * @param message a description of the exception
72      * @param exception the linked exception
73      */

74     public JAXBException(String JavaDoc message, Throwable JavaDoc exception) {
75         this( message, null, exception );
76     }
77     
78     /**
79      * Construct a JAXBException with the specified detail message, vendor
80      * specific errorCode, and linkedException.
81      *
82      * @param message a description of the exception
83      * @param errorCode a string specifying the vendor specific error code
84      * @param exception the linked exception
85      */

86     public JAXBException(String JavaDoc message, String JavaDoc errorCode, Throwable JavaDoc exception) {
87         super( message );
88         this.errorCode = errorCode;
89         this.linkedException = exception;
90     }
91     
92     /**
93      * Get the vendor specific error code
94      *
95      * @return a string specifying the vendor specific error code
96      */

97     public String JavaDoc getErrorCode() {
98         return this.errorCode;
99     }
100
101     /**
102      * Get the linked exception
103      *
104      * @return the linked Exception, null if none exists
105      */

106     public Throwable JavaDoc getLinkedException() {
107         return linkedException;
108     }
109
110     /**
111      * Add a linked Exception.
112      *
113      * @param exception the linked Exception (A null value is permitted and
114      * indicates that the linked exception does not exist or
115      * is unknown).
116      */

117     public synchronized void setLinkedException( Throwable JavaDoc exception ) {
118         this.linkedException = exception;
119     }
120     
121     /**
122      * Returns a short description of this JAXBException.
123      *
124      */

125     public String JavaDoc toString() {
126         return linkedException == null ?
127             super.toString() :
128             super.toString() + "\n - with linked exception:\n[" +
129                                 linkedException.toString()+ "]";
130     }
131
132     /**
133      * Prints this JAXBException and its stack trace (including the stack trace
134      * of the linkedException if it is non-null) to the PrintStream.
135      *
136      * @param s PrintStream to use for output
137      */

138     public void printStackTrace( java.io.PrintStream JavaDoc s ) {
139         super.printStackTrace(s);
140     }
141
142     /**
143      * Prints this JAXBException and its stack trace (including the stack trace
144      * of the linkedException if it is non-null) to <tt>System.err</tt>.
145      *
146      */

147     public void printStackTrace() {
148         super.printStackTrace();
149     }
150
151     /**
152      * Prints this JAXBException and its stack trace (including the stack trace
153      * of the linkedException if it is non-null) to the PrintWriter.
154      *
155      * @param s PrintWriter to use for output
156      */

157     public void printStackTrace(PrintWriter JavaDoc s) {
158         super.printStackTrace(s);
159     }
160
161     @Override JavaDoc
162     public Throwable JavaDoc getCause() {
163         return linkedException;
164     }
165 }
166
Popular Tags