src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/SOAPExceptionImpl.java

Tue, 09 Apr 2013 14:51:13 +0100

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
permissions
-rw-r--r--

8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com

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

mercurial