KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > security > sasl > SaslException


1 /*
2  * @(#)SaslException.java 1.12 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.security.sasl;
9
10 import java.io.IOException JavaDoc;
11
12 /**
13  * This class represents an error that has occurred when using SASL.
14  *
15  * @since 1.5
16  *
17  * @author Rosanna Lee
18  * @author Rob Weltman
19  */

20
21 public class SaslException extends IOException JavaDoc {
22     /**
23      * The possibly null root cause exception.
24      * @serial
25      */

26     // Required for serialization interoperability with JSR 28
27
private Throwable JavaDoc _exception;
28
29     /**
30      * Constructs a new instance of <tt>SaslException</tt>.
31      * The root exception and the detailed message are null.
32      */

33     public SaslException () {
34     super();
35     }
36
37     /**
38      * Constructs a new instance of <tt>SaslException</tt> with a detailed message.
39      * The root exception is null.
40      * @param detail A possibly null string containing details of the exception.
41      *
42      * @see java.lang.Throwable#getMessage
43      */

44     public SaslException (String JavaDoc detail) {
45     super(detail);
46     }
47
48     /**
49      * Constructs a new instance of <tt>SaslException</tt> with a detailed message
50      * and a root exception.
51      * For example, a SaslException might result from a problem with
52      * the callback handler, which might throw a NoSuchCallbackException if
53      * it does not support the requested callback, or throw an IOException
54      * if it had problems obtaining data for the callback. The
55      * SaslException's root exception would be then be the exception thrown
56      * by the callback handler.
57      *
58      * @param detail A possibly null string containing details of the exception.
59      * @param ex A possibly null root exception that caused this exception.
60      *
61      * @see java.lang.Throwable#getMessage
62      * @see #getCause
63      */

64     public SaslException (String JavaDoc detail, Throwable JavaDoc ex) {
65     super(detail);
66     if (ex != null) {
67         initCause(ex);
68     }
69     }
70
71     /*
72      * Override Throwable.getCause() to ensure deserialized object from
73      * JSR 28 would return same value for getCause() (i.e., _exception).
74      */

75     public Throwable JavaDoc getCause() {
76     return _exception;
77     }
78
79     /*
80      * Override Throwable.initCause() to match getCause() by updating
81      * _exception as well.
82      */

83     public Throwable JavaDoc initCause(Throwable JavaDoc cause) {
84     super.initCause(cause);
85     _exception = cause;
86     return this;
87     }
88
89     /**
90      * Returns the string representation of this exception.
91      * The string representation contains
92      * this exception's class name, its detailed messsage, and if
93      * it has a root exception, the string representation of the root
94      * exception. This string representation
95      * is meant for debugging and not meant to be interpreted
96      * programmatically.
97      * @return The non-null string representation of this exception.
98      * @see java.lang.Throwable#getMessage
99      */

100     // Override Throwable.toString() to conform to JSR 28
101
public String JavaDoc toString() {
102     String JavaDoc answer = super.toString();
103     if (_exception != null && _exception != this) {
104         answer += " [Caused by " + _exception.toString() + "]";
105     }
106     return answer;
107     }
108
109     /** Use serialVersionUID from JSR 28 RI for interoperability */
110     private static final long serialVersionUID = 4579784287983423626L;
111 }
112
Popular Tags