aoqi@0: /* aoqi@0: * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package javax.xml.bind; aoqi@0: aoqi@0: import java.io.PrintWriter; aoqi@0: aoqi@0: /** aoqi@0: * This is the root exception class for all JAXB exceptions. aoqi@0: * aoqi@0: * @author aoqi@0: * @see JAXBContext aoqi@0: * @see Marshaller aoqi@0: * @see Unmarshaller aoqi@0: * @since JAXB1.0 aoqi@0: */ aoqi@0: public class JAXBException extends Exception { aoqi@0: aoqi@0: /** aoqi@0: * Vendor specific error code aoqi@0: * aoqi@0: */ aoqi@0: private String errorCode; aoqi@0: aoqi@0: /** aoqi@0: * Exception reference aoqi@0: * aoqi@0: */ aoqi@0: private volatile Throwable linkedException; aoqi@0: aoqi@0: static final long serialVersionUID = -5621384651494307979L; aoqi@0: aoqi@0: /** aoqi@0: * Construct a JAXBException with the specified detail message. The aoqi@0: * errorCode and linkedException will default to null. aoqi@0: * aoqi@0: * @param message a description of the exception aoqi@0: */ aoqi@0: public JAXBException(String message) { aoqi@0: this( message, null, null ); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Construct a JAXBException with the specified detail message and vendor aoqi@0: * specific errorCode. The linkedException will default to null. aoqi@0: * aoqi@0: * @param message a description of the exception aoqi@0: * @param errorCode a string specifying the vendor specific error code aoqi@0: */ aoqi@0: public JAXBException(String message, String errorCode) { aoqi@0: this( message, errorCode, null ); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Construct a JAXBException with a linkedException. The detail message and aoqi@0: * vendor specific errorCode will default to null. aoqi@0: * aoqi@0: * @param exception the linked exception aoqi@0: */ aoqi@0: public JAXBException(Throwable exception) { aoqi@0: this( null, null, exception ); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Construct a JAXBException with the specified detail message and aoqi@0: * linkedException. The errorCode will default to null. aoqi@0: * aoqi@0: * @param message a description of the exception aoqi@0: * @param exception the linked exception aoqi@0: */ aoqi@0: public JAXBException(String message, Throwable exception) { aoqi@0: this( message, null, exception ); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Construct a JAXBException with the specified detail message, vendor aoqi@0: * specific errorCode, and linkedException. aoqi@0: * aoqi@0: * @param message a description of the exception aoqi@0: * @param errorCode a string specifying the vendor specific error code aoqi@0: * @param exception the linked exception aoqi@0: */ aoqi@0: public JAXBException(String message, String errorCode, Throwable exception) { aoqi@0: super( message ); aoqi@0: this.errorCode = errorCode; aoqi@0: this.linkedException = exception; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Get the vendor specific error code aoqi@0: * aoqi@0: * @return a string specifying the vendor specific error code aoqi@0: */ aoqi@0: public String getErrorCode() { aoqi@0: return this.errorCode; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Get the linked exception aoqi@0: * aoqi@0: * @return the linked Exception, null if none exists aoqi@0: */ aoqi@0: public Throwable getLinkedException() { aoqi@0: return linkedException; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Add a linked Exception. aoqi@0: * aoqi@0: * @param exception the linked Exception (A null value is permitted and aoqi@0: * indicates that the linked exception does not exist or aoqi@0: * is unknown). aoqi@0: */ aoqi@0: public void setLinkedException( Throwable exception ) { aoqi@0: this.linkedException = exception; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Returns a short description of this JAXBException. aoqi@0: * aoqi@0: */ aoqi@0: public String toString() { aoqi@0: return linkedException == null ? aoqi@0: super.toString() : aoqi@0: super.toString() + "\n - with linked exception:\n[" + aoqi@0: linkedException.toString()+ "]"; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Prints this JAXBException and its stack trace (including the stack trace aoqi@0: * of the linkedException if it is non-null) to the PrintStream. aoqi@0: * aoqi@0: * @param s PrintStream to use for output aoqi@0: */ aoqi@0: public void printStackTrace( java.io.PrintStream s ) { aoqi@0: super.printStackTrace(s); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Prints this JAXBException and its stack trace (including the stack trace aoqi@0: * of the linkedException if it is non-null) to System.err. aoqi@0: * aoqi@0: */ aoqi@0: public void printStackTrace() { aoqi@0: super.printStackTrace(); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Prints this JAXBException and its stack trace (including the stack trace aoqi@0: * of the linkedException if it is non-null) to the PrintWriter. aoqi@0: * aoqi@0: * @param s PrintWriter to use for output aoqi@0: */ aoqi@0: public void printStackTrace(PrintWriter s) { aoqi@0: super.printStackTrace(s); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public Throwable getCause() { aoqi@0: return linkedException; aoqi@0: } aoqi@0: }