src/share/jaxws_classes/javax/xml/soap/SOAPException.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 368
0989ad8c0860
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2004, 2012, 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.soap;
aoqi@0 27
aoqi@0 28 /**
aoqi@0 29 * An exception that signals that a SOAP exception has occurred. A
aoqi@0 30 * <code>SOAPException</code> object may contain a <code>String</code>
aoqi@0 31 * that gives the reason for the exception, an embedded
aoqi@0 32 * <code>Throwable</code> object, or both. This class provides methods
aoqi@0 33 * for retrieving reason messages and for retrieving the embedded
aoqi@0 34 * <code>Throwable</code> object.
aoqi@0 35 *
aoqi@0 36 * <P> Typical reasons for throwing a <code>SOAPException</code>
aoqi@0 37 * object are problems such as difficulty setting a header, not being
aoqi@0 38 * able to send a message, and not being able to get a connection with
aoqi@0 39 * the provider. Reasons for embedding a <code>Throwable</code>
aoqi@0 40 * object include problems such as input/output errors or a parsing
aoqi@0 41 * problem, such as an error in parsing a header.
aoqi@0 42 */
aoqi@0 43 public class SOAPException extends Exception {
aoqi@0 44 private Throwable cause;
aoqi@0 45
aoqi@0 46 /**
aoqi@0 47 * Constructs a <code>SOAPException</code> object with no
aoqi@0 48 * reason or embedded <code>Throwable</code> object.
aoqi@0 49 */
aoqi@0 50 public SOAPException() {
aoqi@0 51 super();
aoqi@0 52 this.cause = null;
aoqi@0 53 }
aoqi@0 54
aoqi@0 55 /**
aoqi@0 56 * Constructs a <code>SOAPException</code> object with the given
aoqi@0 57 * <code>String</code> as the reason for the exception being thrown.
aoqi@0 58 *
aoqi@0 59 * @param reason a description of what caused the exception
aoqi@0 60 */
aoqi@0 61 public SOAPException(String reason) {
aoqi@0 62 super(reason);
aoqi@0 63 this.cause = null;
aoqi@0 64 }
aoqi@0 65
aoqi@0 66 /**
aoqi@0 67 * Constructs a <code>SOAPException</code> object with the given
aoqi@0 68 * <code>String</code> as the reason for the exception being thrown
aoqi@0 69 * and the given <code>Throwable</code> object as an embedded
aoqi@0 70 * exception.
aoqi@0 71 *
aoqi@0 72 * @param reason a description of what caused the exception
aoqi@0 73 * @param cause a <code>Throwable</code> object that is to
aoqi@0 74 * be embedded in this <code>SOAPException</code> object
aoqi@0 75 */
aoqi@0 76 public SOAPException(String reason, Throwable cause) {
aoqi@0 77 super(reason);
aoqi@0 78 initCause(cause);
aoqi@0 79 }
aoqi@0 80
aoqi@0 81 /**
aoqi@0 82 * Constructs a <code>SOAPException</code> object initialized
aoqi@0 83 * with the given <code>Throwable</code> object.
aoqi@0 84 */
aoqi@0 85 public SOAPException(Throwable cause) {
aoqi@0 86 super(cause.toString());
aoqi@0 87 initCause(cause);
aoqi@0 88 }
aoqi@0 89
aoqi@0 90 /**
aoqi@0 91 * Returns the detail message for this <code>SOAPException</code>
aoqi@0 92 * object.
aoqi@0 93 * <P>
aoqi@0 94 * If there is an embedded <code>Throwable</code> object, and if the
aoqi@0 95 * <code>SOAPException</code> object has no detail message of its
aoqi@0 96 * own, this method will return the detail message from the embedded
aoqi@0 97 * <code>Throwable</code> object.
aoqi@0 98 *
aoqi@0 99 * @return the error or warning message for this
aoqi@0 100 * <code>SOAPException</code> or, if it has none, the
aoqi@0 101 * message of the embedded <code>Throwable</code> object,
aoqi@0 102 * if there is one
aoqi@0 103 */
aoqi@0 104 public String getMessage() {
aoqi@0 105 String message = super.getMessage();
aoqi@0 106 if (message == null && cause != null) {
aoqi@0 107 return cause.getMessage();
aoqi@0 108 } else {
aoqi@0 109 return message;
aoqi@0 110 }
aoqi@0 111 }
aoqi@0 112
aoqi@0 113 /**
aoqi@0 114 * Returns the <code>Throwable</code> object embedded in this
aoqi@0 115 * <code>SOAPException</code> if there is one. Otherwise, this method
aoqi@0 116 * returns <code>null</code>.
aoqi@0 117 *
aoqi@0 118 * @return the embedded <code>Throwable</code> object or <code>null</code>
aoqi@0 119 * if there is none
aoqi@0 120 */
aoqi@0 121
aoqi@0 122 public Throwable getCause() {
aoqi@0 123 return cause;
aoqi@0 124 }
aoqi@0 125
aoqi@0 126 /**
aoqi@0 127 * Initializes the <code>cause</code> field of this <code>SOAPException</code>
aoqi@0 128 * object with the given <code>Throwable</code> object.
aoqi@0 129 * <P>
aoqi@0 130 * This method can be called at most once. It is generally called from
aoqi@0 131 * within the constructor or immediately after the constructor has
aoqi@0 132 * returned a new <code>SOAPException</code> object.
aoqi@0 133 * If this <code>SOAPException</code> object was created with the
aoqi@0 134 * constructor {@link #SOAPException(Throwable)} or
aoqi@0 135 * {@link #SOAPException(String,Throwable)}, meaning that its
aoqi@0 136 * <code>cause</code> field already has a value, this method cannot be
aoqi@0 137 * called even once.
aoqi@0 138 *
aoqi@0 139 * @param cause the <code>Throwable</code> object that caused this
aoqi@0 140 * <code>SOAPException</code> object to be thrown. The value of this
aoqi@0 141 * parameter is saved for later retrieval by the
aoqi@0 142 * {@link #getCause()} method. A <tt>null</tt> value is
aoqi@0 143 * permitted and indicates that the cause is nonexistent or
aoqi@0 144 * unknown.
aoqi@0 145 * @return a reference to this <code>SOAPException</code> instance
aoqi@0 146 * @throws IllegalArgumentException if <code>cause</code> is this
aoqi@0 147 * <code>Throwable</code> object. (A <code>Throwable</code> object
aoqi@0 148 * cannot be its own cause.)
aoqi@0 149 * @throws IllegalStateException if the cause for this <code>SOAPException</code> object
aoqi@0 150 * has already been initialized
aoqi@0 151 */
aoqi@0 152 public synchronized Throwable initCause(Throwable cause) {
aoqi@0 153 if (this.cause != null) {
aoqi@0 154 throw new IllegalStateException("Can't override cause");
aoqi@0 155 }
aoqi@0 156 if (cause == this) {
aoqi@0 157 throw new IllegalArgumentException("Self-causation not permitted");
aoqi@0 158 }
aoqi@0 159 this.cause = cause;
aoqi@0 160
aoqi@0 161 return this;
aoqi@0 162 }
aoqi@0 163 }

mercurial