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

Tue, 06 Mar 2012 16:09:35 -0800

author
ohair
date
Tue, 06 Mar 2012 16:09:35 -0800
changeset 286
f50545b5e2f1
child 368
0989ad8c0860
permissions
-rw-r--r--

7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom

ohair@286 1 /*
ohair@286 2 * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 */
ohair@286 25
ohair@286 26 package javax.xml.soap;
ohair@286 27
ohair@286 28 /**
ohair@286 29 * An exception that signals that a SOAP exception has occurred. A
ohair@286 30 * <code>SOAPException</code> object may contain a <code>String</code>
ohair@286 31 * that gives the reason for the exception, an embedded
ohair@286 32 * <code>Throwable</code> object, or both. This class provides methods
ohair@286 33 * for retrieving reason messages and for retrieving the embedded
ohair@286 34 * <code>Throwable</code> object.
ohair@286 35 *
ohair@286 36 * <P> Typical reasons for throwing a <code>SOAPException</code>
ohair@286 37 * object are problems such as difficulty setting a header, not being
ohair@286 38 * able to send a message, and not being able to get a connection with
ohair@286 39 * the provider. Reasons for embedding a <code>Throwable</code>
ohair@286 40 * object include problems such as input/output errors or a parsing
ohair@286 41 * problem, such as an error in parsing a header.
ohair@286 42 */
ohair@286 43 public class SOAPException extends Exception {
ohair@286 44 private Throwable cause;
ohair@286 45
ohair@286 46 /**
ohair@286 47 * Constructs a <code>SOAPException</code> object with no
ohair@286 48 * reason or embedded <code>Throwable</code> object.
ohair@286 49 */
ohair@286 50 public SOAPException() {
ohair@286 51 super();
ohair@286 52 this.cause = null;
ohair@286 53 }
ohair@286 54
ohair@286 55 /**
ohair@286 56 * Constructs a <code>SOAPException</code> object with the given
ohair@286 57 * <code>String</code> as the reason for the exception being thrown.
ohair@286 58 *
ohair@286 59 * @param reason a description of what caused the exception
ohair@286 60 */
ohair@286 61 public SOAPException(String reason) {
ohair@286 62 super(reason);
ohair@286 63 this.cause = null;
ohair@286 64 }
ohair@286 65
ohair@286 66 /**
ohair@286 67 * Constructs a <code>SOAPException</code> object with the given
ohair@286 68 * <code>String</code> as the reason for the exception being thrown
ohair@286 69 * and the given <code>Throwable</code> object as an embedded
ohair@286 70 * exception.
ohair@286 71 *
ohair@286 72 * @param reason a description of what caused the exception
ohair@286 73 * @param cause a <code>Throwable</code> object that is to
ohair@286 74 * be embedded in this <code>SOAPException</code> object
ohair@286 75 */
ohair@286 76 public SOAPException(String reason, Throwable cause) {
ohair@286 77 super(reason);
ohair@286 78 initCause(cause);
ohair@286 79 }
ohair@286 80
ohair@286 81 /**
ohair@286 82 * Constructs a <code>SOAPException</code> object initialized
ohair@286 83 * with the given <code>Throwable</code> object.
ohair@286 84 */
ohair@286 85 public SOAPException(Throwable cause) {
ohair@286 86 super(cause.toString());
ohair@286 87 initCause(cause);
ohair@286 88 }
ohair@286 89
ohair@286 90 /**
ohair@286 91 * Returns the detail message for this <code>SOAPException</code>
ohair@286 92 * object.
ohair@286 93 * <P>
ohair@286 94 * If there is an embedded <code>Throwable</code> object, and if the
ohair@286 95 * <code>SOAPException</code> object has no detail message of its
ohair@286 96 * own, this method will return the detail message from the embedded
ohair@286 97 * <code>Throwable</code> object.
ohair@286 98 *
ohair@286 99 * @return the error or warning message for this
ohair@286 100 * <code>SOAPException</code> or, if it has none, the
ohair@286 101 * message of the embedded <code>Throwable</code> object,
ohair@286 102 * if there is one
ohair@286 103 */
ohair@286 104 public String getMessage() {
ohair@286 105 String message = super.getMessage();
ohair@286 106 if (message == null && cause != null) {
ohair@286 107 return cause.getMessage();
ohair@286 108 } else {
ohair@286 109 return message;
ohair@286 110 }
ohair@286 111 }
ohair@286 112
ohair@286 113 /**
ohair@286 114 * Returns the <code>Throwable</code> object embedded in this
ohair@286 115 * <code>SOAPException</code> if there is one. Otherwise, this method
ohair@286 116 * returns <code>null</code>.
ohair@286 117 *
ohair@286 118 * @return the embedded <code>Throwable</code> object or <code>null</code>
ohair@286 119 * if there is none
ohair@286 120 */
ohair@286 121
ohair@286 122 public Throwable getCause() {
ohair@286 123 return cause;
ohair@286 124 }
ohair@286 125
ohair@286 126 /**
ohair@286 127 * Initializes the <code>cause</code> field of this <code>SOAPException</code>
ohair@286 128 * object with the given <code>Throwable</code> object.
ohair@286 129 * <P>
ohair@286 130 * This method can be called at most once. It is generally called from
ohair@286 131 * within the constructor or immediately after the constructor has
ohair@286 132 * returned a new <code>SOAPException</code> object.
ohair@286 133 * If this <code>SOAPException</code> object was created with the
ohair@286 134 * constructor {@link #SOAPException(Throwable)} or
ohair@286 135 * {@link #SOAPException(String,Throwable)}, meaning that its
ohair@286 136 * <code>cause</code> field already has a value, this method cannot be
ohair@286 137 * called even once.
ohair@286 138 *
ohair@286 139 * @param cause the <code>Throwable</code> object that caused this
ohair@286 140 * <code>SOAPException</code> object to be thrown. The value of this
ohair@286 141 * parameter is saved for later retrieval by the
ohair@286 142 * {@link #getCause()} method. A <tt>null</tt> value is
ohair@286 143 * permitted and indicates that the cause is nonexistent or
ohair@286 144 * unknown.
ohair@286 145 * @return a reference to this <code>SOAPException</code> instance
ohair@286 146 * @throws IllegalArgumentException if <code>cause</code> is this
ohair@286 147 * <code>Throwable</code> object. (A <code>Throwable</code> object
ohair@286 148 * cannot be its own cause.)
ohair@286 149 * @throws IllegalStateException if the cause for this <code>SOAPException</code> object
ohair@286 150 * has already been initialized
ohair@286 151 */
ohair@286 152 public synchronized Throwable initCause(Throwable cause) {
ohair@286 153 if (this.cause != null) {
ohair@286 154 throw new IllegalStateException("Can't override cause");
ohair@286 155 }
ohair@286 156 if (cause == this) {
ohair@286 157 throw new IllegalArgumentException("Self-causation not permitted");
ohair@286 158 }
ohair@286 159 this.cause = cause;
ohair@286 160
ohair@286 161 return this;
ohair@286 162 }
ohair@286 163 }

mercurial