001: /*
002: * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
003: * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
004: */
005:
006: package javax.xml.bind;
007:
008: import java.io.PrintWriter;
009:
010: /**
011: * This is the root exception class for all JAXB exceptions.
012: *
013: * @author <ul><li>Ryan Shoemaker, Sun Microsystems, Inc.</li></ul>
014: * @version $Revision: 1.1 $ $Date: 2004/12/14 21:50:39 $
015: * @see JAXBContext
016: * @see Marshaller
017: * @see Unmarshaller
018: * @since JAXB1.0
019: */
020: public class JAXBException extends Exception {
021:
022: /**
023: * Vendor specific error code
024: *
025: */
026: private String errorCode;
027:
028: /**
029: * Exception reference
030: *
031: */
032: private Throwable linkedException;
033:
034: static final long serialVersionUID = -5621384651494307979L;
035:
036: /**
037: * Construct a JAXBException with the specified detail message. The
038: * errorCode and linkedException will default to null.
039: *
040: * @param message a description of the exception
041: */
042: public JAXBException(String message) {
043: this (message, null, null);
044: }
045:
046: /**
047: * Construct a JAXBException with the specified detail message and vendor
048: * specific errorCode. The linkedException will default to null.
049: *
050: * @param message a description of the exception
051: * @param errorCode a string specifying the vendor specific error code
052: */
053: public JAXBException(String message, String errorCode) {
054: this (message, errorCode, null);
055: }
056:
057: /**
058: * Construct a JAXBException with a linkedException. The detail message and
059: * vendor specific errorCode will default to null.
060: *
061: * @param exception the linked exception
062: */
063: public JAXBException(Throwable exception) {
064: this (null, null, exception);
065: }
066:
067: /**
068: * Construct a JAXBException with the specified detail message and
069: * linkedException. The errorCode will default to null.
070: *
071: * @param message a description of the exception
072: * @param exception the linked exception
073: */
074: public JAXBException(String message, Throwable exception) {
075: this (message, null, exception);
076: }
077:
078: /**
079: * Construct a JAXBException with the specified detail message, vendor
080: * specific errorCode, and linkedException.
081: *
082: * @param message a description of the exception
083: * @param errorCode a string specifying the vendor specific error code
084: * @param exception the linked exception
085: */
086: public JAXBException(String message, String errorCode,
087: Throwable exception) {
088: super (message);
089: this .errorCode = errorCode;
090: this .linkedException = exception;
091: }
092:
093: /**
094: * Get the vendor specific error code
095: *
096: * @return a string specifying the vendor specific error code
097: */
098: public String getErrorCode() {
099: return this .errorCode;
100: }
101:
102: /**
103: * Get the linked exception
104: *
105: * @return the linked Exception, null if none exists
106: */
107: public Throwable getLinkedException() {
108: return linkedException;
109: }
110:
111: /**
112: * Add a linked Exception.
113: *
114: * @param exception the linked Exception (A null value is permitted and
115: * indicates that the linked exception does not exist or
116: * is unknown).
117: */
118: public synchronized void setLinkedException(Throwable exception) {
119: this .linkedException = exception;
120: }
121:
122: /**
123: * Returns a short description of this JAXBException.
124: *
125: */
126: public String toString() {
127: return linkedException == null ? super .toString() : super
128: .toString()
129: + "\n - with linked exception:\n["
130: + linkedException.toString() + "]";
131: }
132:
133: /**
134: * Prints this JAXBException and its stack trace (including the stack trace
135: * of the linkedException if it is non-null) to the PrintStream.
136: *
137: * @param s PrintStream to use for output
138: */
139: public void printStackTrace(java.io.PrintStream s) {
140: super .printStackTrace(s);
141: }
142:
143: /**
144: * Prints this JAXBException and its stack trace (including the stack trace
145: * of the linkedException if it is non-null) to <tt>System.err</tt>.
146: *
147: */
148: public void printStackTrace() {
149: super .printStackTrace();
150: }
151:
152: /**
153: * Prints this JAXBException and its stack trace (including the stack trace
154: * of the linkedException if it is non-null) to the PrintWriter.
155: *
156: * @param s PrintWriter to use for output
157: */
158: public void printStackTrace(PrintWriter s) {
159: super .printStackTrace(s);
160: }
161:
162: @Override
163: public Throwable getCause() {
164: return linkedException;
165: }
166: }
|