Source for javax.security.sasl.SaslException

   1: /* SaslException.java
   2:    Copyright (C) 2003, Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package javax.security.sasl;
  40: 
  41: import java.io.IOException;
  42: import java.io.PrintStream;
  43: import java.io.PrintWriter;
  44: import java.io.Serializable;
  45: 
  46: /**
  47:  * This class represents an error that has occurred when using SASL.
  48:  */
  49: public class SaslException extends IOException implements Serializable
  50: {
  51: 
  52:   // Constants and variables
  53:   // -------------------------------------------------------------------------
  54: 
  55:   /**
  56:    * @serial The possibly null root cause exception.
  57:    */
  58:   private Throwable _exception = null;
  59: 
  60:   // Constructor(s)
  61:   // -------------------------------------------------------------------------
  62: 
  63:   /**
  64:    * Constructs a new instance of <code>SaslException</code>. The root
  65:    * exception and the detailed message are null.
  66:    */
  67:   public SaslException()
  68:   {
  69:     super();
  70:   }
  71: 
  72:   /**
  73:    * Constructs a new instance of <code>SaslException</code> with a detailed
  74:    * message. The <code>root</code> exception is <code>null</code>.
  75:    *
  76:    * @param detail a possibly null string containing details of the exception.
  77:    * @see Throwable#getMessage()
  78:    */
  79:   public SaslException(String detail)
  80:   {
  81:     super(detail);
  82:   }
  83: 
  84:   /**
  85:    * Constructs a new instance of <code>SaslException</code> with a detailed
  86:    * message and a root exception. For example, a <code>SaslException</code>
  87:    * might result from a problem with the callback handler, which might throw a
  88:    * {@link javax.security.auth.callback.UnsupportedCallbackException} if it
  89:    * does not support the requested callback, or throw an {@link IOException}
  90:    * if it had problems obtaining data for the callback. The
  91:    * <code>SaslException</code>'s root exception would be then be the exception
  92:    * thrown by the callback handler.
  93:    *
  94:    * @param detail a possibly <code>null</code> string containing details of
  95:    * the exception.
  96:    * @param ex a possibly <code>null</code> root exception that caused this
  97:    * exception.
  98:    * @see Throwable#getMessage()
  99:    * @see #getCause()
 100:    */
 101:   public SaslException(String detail, Throwable ex)
 102:   {
 103:     super(detail);
 104:     _exception = ex;
 105:   }
 106: 
 107:   // Class methods
 108:   // -------------------------------------------------------------------------
 109: 
 110:   // Instance methods
 111:   // -------------------------------------------------------------------------
 112: 
 113:   /**
 114:    * Returns the cause of this throwable or <code>null</code> if the cause is
 115:    * nonexistent or unknown. The cause is the throwable that caused this
 116:    * exception to be thrown.
 117:    *
 118:    * @return the possibly <code>null</code> exception that caused this exception.
 119:    */
 120:   public Throwable getCause()
 121:   {
 122:     return _exception;
 123:   }
 124: 
 125:   /**
 126:    * Prints this exception's stack trace to <code>System.err</code>. If this
 127:    * exception has a root exception; the stack trace of the root exception is
 128:    * also printed to <code>System.err</code>.
 129:    */
 130:   public void printStackTrace()
 131:   {
 132:     super.printStackTrace();
 133:     if (_exception != null)
 134:       _exception.printStackTrace();
 135:   }
 136: 
 137:   /**
 138:    * Prints this exception's stack trace to a print stream. If this exception
 139:    * has a root exception; the stack trace of the root exception is also
 140:    * printed to the print stream.
 141:    *
 142:    * @param ps the non-null print stream to which to print.
 143:    */
 144:   public void printStackTrace(PrintStream ps)
 145:   {
 146:     super.printStackTrace(ps);
 147:     if (_exception != null)
 148:       _exception.printStackTrace(ps);
 149:   }
 150: 
 151:   /**
 152:    * Prints this exception's stack trace to a print writer. If this exception
 153:    * has a root exception; the stack trace of the root exception is also
 154:    * printed to the print writer.
 155:    *
 156:    * @param pw the non-null print writer to use for output.
 157:    */
 158:   public void printStackTrace(PrintWriter pw)
 159:   {
 160:     super.printStackTrace(pw);
 161:     if (_exception != null)
 162:       _exception.printStackTrace(pw);
 163:   }
 164: 
 165:   /**
 166:    * Returns the string representation of this exception. The string
 167:    * representation contains this exception's class name, its detailed
 168:    * messsage, and if it has a root exception, the string representation of the
 169:    * root exception. This string representation is meant for debugging and not
 170:    * meant to be interpreted programmatically.
 171:    *
 172:    * @return the non-null string representation of this exception.
 173:    * @see Throwable#getMessage()
 174:    */
 175:   public String toString()
 176:   {
 177:     StringBuffer sb = new StringBuffer(this.getClass().getName())
 178:       .append(": ").append(super.toString());
 179:     if (_exception != null)
 180:       sb.append("; caused by: ").append(_exception.toString());
 181:     return sb.toString();
 182:   }
 183: }