001 /*
002 * Copyright 1999-2003 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.security.sasl;
027
028 import java.io.IOException;
029
030 /**
031 * This class represents an error that has occurred when using SASL.
032 *
033 * @since 1.5
034 *
035 * @author Rosanna Lee
036 * @author Rob Weltman
037 */
038
039 public class SaslException extends IOException {
040 /**
041 * The possibly null root cause exception.
042 * @serial
043 */
044 // Required for serialization interoperability with JSR 28
045 private Throwable _exception;
046
047 /**
048 * Constructs a new instance of <tt>SaslException</tt>.
049 * The root exception and the detailed message are null.
050 */
051 public SaslException() {
052 super ();
053 }
054
055 /**
056 * Constructs a new instance of <tt>SaslException</tt> with a detailed message.
057 * The root exception is null.
058 * @param detail A possibly null string containing details of the exception.
059 *
060 * @see java.lang.Throwable#getMessage
061 */
062 public SaslException(String detail) {
063 super (detail);
064 }
065
066 /**
067 * Constructs a new instance of <tt>SaslException</tt> with a detailed message
068 * and a root exception.
069 * For example, a SaslException might result from a problem with
070 * the callback handler, which might throw a NoSuchCallbackException if
071 * it does not support the requested callback, or throw an IOException
072 * if it had problems obtaining data for the callback. The
073 * SaslException's root exception would be then be the exception thrown
074 * by the callback handler.
075 *
076 * @param detail A possibly null string containing details of the exception.
077 * @param ex A possibly null root exception that caused this exception.
078 *
079 * @see java.lang.Throwable#getMessage
080 * @see #getCause
081 */
082 public SaslException(String detail, Throwable ex) {
083 super (detail);
084 if (ex != null) {
085 initCause(ex);
086 }
087 }
088
089 /*
090 * Override Throwable.getCause() to ensure deserialized object from
091 * JSR 28 would return same value for getCause() (i.e., _exception).
092 */
093 public Throwable getCause() {
094 return _exception;
095 }
096
097 /*
098 * Override Throwable.initCause() to match getCause() by updating
099 * _exception as well.
100 */
101 public Throwable initCause(Throwable cause) {
102 super .initCause(cause);
103 _exception = cause;
104 return this ;
105 }
106
107 /**
108 * Returns the string representation of this exception.
109 * The string representation contains
110 * this exception's class name, its detailed messsage, and if
111 * it has a root exception, the string representation of the root
112 * exception. This string representation
113 * is meant for debugging and not meant to be interpreted
114 * programmatically.
115 * @return The non-null string representation of this exception.
116 * @see java.lang.Throwable#getMessage
117 */
118 // Override Throwable.toString() to conform to JSR 28
119 public String toString() {
120 String answer = super .toString();
121 if (_exception != null && _exception != this ) {
122 answer += " [Caused by " + _exception.toString() + "]";
123 }
124 return answer;
125 }
126
127 /** Use serialVersionUID from JSR 28 RI for interoperability */
128 private static final long serialVersionUID = 4579784287983423626L;
129 }
|