1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/javax/xml/soap/SOAPException.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,163 @@ 1.4 +/* 1.5 + * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package javax.xml.soap; 1.30 + 1.31 +/** 1.32 + * An exception that signals that a SOAP exception has occurred. A 1.33 + * <code>SOAPException</code> object may contain a <code>String</code> 1.34 + * that gives the reason for the exception, an embedded 1.35 + * <code>Throwable</code> object, or both. This class provides methods 1.36 + * for retrieving reason messages and for retrieving the embedded 1.37 + * <code>Throwable</code> object. 1.38 + * 1.39 + * <P> Typical reasons for throwing a <code>SOAPException</code> 1.40 + * object are problems such as difficulty setting a header, not being 1.41 + * able to send a message, and not being able to get a connection with 1.42 + * the provider. Reasons for embedding a <code>Throwable</code> 1.43 + * object include problems such as input/output errors or a parsing 1.44 + * problem, such as an error in parsing a header. 1.45 + */ 1.46 +public class SOAPException extends Exception { 1.47 + private Throwable cause; 1.48 + 1.49 + /** 1.50 + * Constructs a <code>SOAPException</code> object with no 1.51 + * reason or embedded <code>Throwable</code> object. 1.52 + */ 1.53 + public SOAPException() { 1.54 + super(); 1.55 + this.cause = null; 1.56 + } 1.57 + 1.58 + /** 1.59 + * Constructs a <code>SOAPException</code> object with the given 1.60 + * <code>String</code> as the reason for the exception being thrown. 1.61 + * 1.62 + * @param reason a description of what caused the exception 1.63 + */ 1.64 + public SOAPException(String reason) { 1.65 + super(reason); 1.66 + this.cause = null; 1.67 + } 1.68 + 1.69 + /** 1.70 + * Constructs a <code>SOAPException</code> object with the given 1.71 + * <code>String</code> as the reason for the exception being thrown 1.72 + * and the given <code>Throwable</code> object as an embedded 1.73 + * exception. 1.74 + * 1.75 + * @param reason a description of what caused the exception 1.76 + * @param cause a <code>Throwable</code> object that is to 1.77 + * be embedded in this <code>SOAPException</code> object 1.78 + */ 1.79 + public SOAPException(String reason, Throwable cause) { 1.80 + super(reason); 1.81 + initCause(cause); 1.82 + } 1.83 + 1.84 + /** 1.85 + * Constructs a <code>SOAPException</code> object initialized 1.86 + * with the given <code>Throwable</code> object. 1.87 + */ 1.88 + public SOAPException(Throwable cause) { 1.89 + super(cause.toString()); 1.90 + initCause(cause); 1.91 + } 1.92 + 1.93 + /** 1.94 + * Returns the detail message for this <code>SOAPException</code> 1.95 + * object. 1.96 + * <P> 1.97 + * If there is an embedded <code>Throwable</code> object, and if the 1.98 + * <code>SOAPException</code> object has no detail message of its 1.99 + * own, this method will return the detail message from the embedded 1.100 + * <code>Throwable</code> object. 1.101 + * 1.102 + * @return the error or warning message for this 1.103 + * <code>SOAPException</code> or, if it has none, the 1.104 + * message of the embedded <code>Throwable</code> object, 1.105 + * if there is one 1.106 + */ 1.107 + public String getMessage() { 1.108 + String message = super.getMessage(); 1.109 + if (message == null && cause != null) { 1.110 + return cause.getMessage(); 1.111 + } else { 1.112 + return message; 1.113 + } 1.114 + } 1.115 + 1.116 + /** 1.117 + * Returns the <code>Throwable</code> object embedded in this 1.118 + * <code>SOAPException</code> if there is one. Otherwise, this method 1.119 + * returns <code>null</code>. 1.120 + * 1.121 + * @return the embedded <code>Throwable</code> object or <code>null</code> 1.122 + * if there is none 1.123 + */ 1.124 + 1.125 + public Throwable getCause() { 1.126 + return cause; 1.127 + } 1.128 + 1.129 + /** 1.130 + * Initializes the <code>cause</code> field of this <code>SOAPException</code> 1.131 + * object with the given <code>Throwable</code> object. 1.132 + * <P> 1.133 + * This method can be called at most once. It is generally called from 1.134 + * within the constructor or immediately after the constructor has 1.135 + * returned a new <code>SOAPException</code> object. 1.136 + * If this <code>SOAPException</code> object was created with the 1.137 + * constructor {@link #SOAPException(Throwable)} or 1.138 + * {@link #SOAPException(String,Throwable)}, meaning that its 1.139 + * <code>cause</code> field already has a value, this method cannot be 1.140 + * called even once. 1.141 + * 1.142 + * @param cause the <code>Throwable</code> object that caused this 1.143 + * <code>SOAPException</code> object to be thrown. The value of this 1.144 + * parameter is saved for later retrieval by the 1.145 + * {@link #getCause()} method. A <tt>null</tt> value is 1.146 + * permitted and indicates that the cause is nonexistent or 1.147 + * unknown. 1.148 + * @return a reference to this <code>SOAPException</code> instance 1.149 + * @throws IllegalArgumentException if <code>cause</code> is this 1.150 + * <code>Throwable</code> object. (A <code>Throwable</code> object 1.151 + * cannot be its own cause.) 1.152 + * @throws IllegalStateException if the cause for this <code>SOAPException</code> object 1.153 + * has already been initialized 1.154 + */ 1.155 + public synchronized Throwable initCause(Throwable cause) { 1.156 + if (this.cause != null) { 1.157 + throw new IllegalStateException("Can't override cause"); 1.158 + } 1.159 + if (cause == this) { 1.160 + throw new IllegalArgumentException("Self-causation not permitted"); 1.161 + } 1.162 + this.cause = cause; 1.163 + 1.164 + return this; 1.165 + } 1.166 +}