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