Thu, 31 Aug 2017 15:18:52 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package javax.xml.bind; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import java.io.PrintWriter; |
aoqi@0 | 29 | |
aoqi@0 | 30 | /** |
aoqi@0 | 31 | * This is the root exception class for all JAXB exceptions. |
aoqi@0 | 32 | * |
aoqi@0 | 33 | * @author <ul><li>Ryan Shoemaker, Sun Microsystems, Inc.</li></ul> |
aoqi@0 | 34 | * @see JAXBContext |
aoqi@0 | 35 | * @see Marshaller |
aoqi@0 | 36 | * @see Unmarshaller |
aoqi@0 | 37 | * @since JAXB1.0 |
aoqi@0 | 38 | */ |
aoqi@0 | 39 | public class JAXBException extends Exception { |
aoqi@0 | 40 | |
aoqi@0 | 41 | /** |
aoqi@0 | 42 | * Vendor specific error code |
aoqi@0 | 43 | * |
aoqi@0 | 44 | */ |
aoqi@0 | 45 | private String errorCode; |
aoqi@0 | 46 | |
aoqi@0 | 47 | /** |
aoqi@0 | 48 | * Exception reference |
aoqi@0 | 49 | * |
aoqi@0 | 50 | */ |
aoqi@0 | 51 | private volatile Throwable linkedException; |
aoqi@0 | 52 | |
aoqi@0 | 53 | static final long serialVersionUID = -5621384651494307979L; |
aoqi@0 | 54 | |
aoqi@0 | 55 | /** |
aoqi@0 | 56 | * Construct a JAXBException with the specified detail message. The |
aoqi@0 | 57 | * errorCode and linkedException will default to null. |
aoqi@0 | 58 | * |
aoqi@0 | 59 | * @param message a description of the exception |
aoqi@0 | 60 | */ |
aoqi@0 | 61 | public JAXBException(String message) { |
aoqi@0 | 62 | this( message, null, null ); |
aoqi@0 | 63 | } |
aoqi@0 | 64 | |
aoqi@0 | 65 | /** |
aoqi@0 | 66 | * Construct a JAXBException with the specified detail message and vendor |
aoqi@0 | 67 | * specific errorCode. The linkedException will default to null. |
aoqi@0 | 68 | * |
aoqi@0 | 69 | * @param message a description of the exception |
aoqi@0 | 70 | * @param errorCode a string specifying the vendor specific error code |
aoqi@0 | 71 | */ |
aoqi@0 | 72 | public JAXBException(String message, String errorCode) { |
aoqi@0 | 73 | this( message, errorCode, null ); |
aoqi@0 | 74 | } |
aoqi@0 | 75 | |
aoqi@0 | 76 | /** |
aoqi@0 | 77 | * Construct a JAXBException with a linkedException. The detail message and |
aoqi@0 | 78 | * vendor specific errorCode will default to null. |
aoqi@0 | 79 | * |
aoqi@0 | 80 | * @param exception the linked exception |
aoqi@0 | 81 | */ |
aoqi@0 | 82 | public JAXBException(Throwable exception) { |
aoqi@0 | 83 | this( null, null, exception ); |
aoqi@0 | 84 | } |
aoqi@0 | 85 | |
aoqi@0 | 86 | /** |
aoqi@0 | 87 | * Construct a JAXBException with the specified detail message and |
aoqi@0 | 88 | * linkedException. The errorCode will default to null. |
aoqi@0 | 89 | * |
aoqi@0 | 90 | * @param message a description of the exception |
aoqi@0 | 91 | * @param exception the linked exception |
aoqi@0 | 92 | */ |
aoqi@0 | 93 | public JAXBException(String message, Throwable exception) { |
aoqi@0 | 94 | this( message, null, exception ); |
aoqi@0 | 95 | } |
aoqi@0 | 96 | |
aoqi@0 | 97 | /** |
aoqi@0 | 98 | * Construct a JAXBException with the specified detail message, vendor |
aoqi@0 | 99 | * specific errorCode, and linkedException. |
aoqi@0 | 100 | * |
aoqi@0 | 101 | * @param message a description of the exception |
aoqi@0 | 102 | * @param errorCode a string specifying the vendor specific error code |
aoqi@0 | 103 | * @param exception the linked exception |
aoqi@0 | 104 | */ |
aoqi@0 | 105 | public JAXBException(String message, String errorCode, Throwable exception) { |
aoqi@0 | 106 | super( message ); |
aoqi@0 | 107 | this.errorCode = errorCode; |
aoqi@0 | 108 | this.linkedException = exception; |
aoqi@0 | 109 | } |
aoqi@0 | 110 | |
aoqi@0 | 111 | /** |
aoqi@0 | 112 | * Get the vendor specific error code |
aoqi@0 | 113 | * |
aoqi@0 | 114 | * @return a string specifying the vendor specific error code |
aoqi@0 | 115 | */ |
aoqi@0 | 116 | public String getErrorCode() { |
aoqi@0 | 117 | return this.errorCode; |
aoqi@0 | 118 | } |
aoqi@0 | 119 | |
aoqi@0 | 120 | /** |
aoqi@0 | 121 | * Get the linked exception |
aoqi@0 | 122 | * |
aoqi@0 | 123 | * @return the linked Exception, null if none exists |
aoqi@0 | 124 | */ |
aoqi@0 | 125 | public Throwable getLinkedException() { |
aoqi@0 | 126 | return linkedException; |
aoqi@0 | 127 | } |
aoqi@0 | 128 | |
aoqi@0 | 129 | /** |
aoqi@0 | 130 | * Add a linked Exception. |
aoqi@0 | 131 | * |
aoqi@0 | 132 | * @param exception the linked Exception (A null value is permitted and |
aoqi@0 | 133 | * indicates that the linked exception does not exist or |
aoqi@0 | 134 | * is unknown). |
aoqi@0 | 135 | */ |
aoqi@0 | 136 | public void setLinkedException( Throwable exception ) { |
aoqi@0 | 137 | this.linkedException = exception; |
aoqi@0 | 138 | } |
aoqi@0 | 139 | |
aoqi@0 | 140 | /** |
aoqi@0 | 141 | * Returns a short description of this JAXBException. |
aoqi@0 | 142 | * |
aoqi@0 | 143 | */ |
aoqi@0 | 144 | public String toString() { |
aoqi@0 | 145 | return linkedException == null ? |
aoqi@0 | 146 | super.toString() : |
aoqi@0 | 147 | super.toString() + "\n - with linked exception:\n[" + |
aoqi@0 | 148 | linkedException.toString()+ "]"; |
aoqi@0 | 149 | } |
aoqi@0 | 150 | |
aoqi@0 | 151 | /** |
aoqi@0 | 152 | * Prints this JAXBException and its stack trace (including the stack trace |
aoqi@0 | 153 | * of the linkedException if it is non-null) to the PrintStream. |
aoqi@0 | 154 | * |
aoqi@0 | 155 | * @param s PrintStream to use for output |
aoqi@0 | 156 | */ |
aoqi@0 | 157 | public void printStackTrace( java.io.PrintStream s ) { |
aoqi@0 | 158 | super.printStackTrace(s); |
aoqi@0 | 159 | } |
aoqi@0 | 160 | |
aoqi@0 | 161 | /** |
aoqi@0 | 162 | * Prints this JAXBException and its stack trace (including the stack trace |
aoqi@0 | 163 | * of the linkedException if it is non-null) to <tt>System.err</tt>. |
aoqi@0 | 164 | * |
aoqi@0 | 165 | */ |
aoqi@0 | 166 | public void printStackTrace() { |
aoqi@0 | 167 | super.printStackTrace(); |
aoqi@0 | 168 | } |
aoqi@0 | 169 | |
aoqi@0 | 170 | /** |
aoqi@0 | 171 | * Prints this JAXBException and its stack trace (including the stack trace |
aoqi@0 | 172 | * of the linkedException if it is non-null) to the PrintWriter. |
aoqi@0 | 173 | * |
aoqi@0 | 174 | * @param s PrintWriter to use for output |
aoqi@0 | 175 | */ |
aoqi@0 | 176 | public void printStackTrace(PrintWriter s) { |
aoqi@0 | 177 | super.printStackTrace(s); |
aoqi@0 | 178 | } |
aoqi@0 | 179 | |
aoqi@0 | 180 | @Override |
aoqi@0 | 181 | public Throwable getCause() { |
aoqi@0 | 182 | return linkedException; |
aoqi@0 | 183 | } |
aoqi@0 | 184 | } |