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

mercurial