Frames | No Frames |
1: /* KeyAgreementException.java -- 2: Copyright (C) 2003, 2006 Free Software Foundation, Inc. 3: 4: This file is a 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 of the License, or (at 9: your option) 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; if not, write to the Free Software 18: Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 19: 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 gnu.javax.crypto.key; 40: 41: import java.io.PrintStream; 42: import java.io.PrintWriter; 43: import java.io.Serializable; 44: import java.security.KeyManagementException; 45: 46: /** 47: * A generic exception indicating that an unexpected condition has been detected 48: * during the setup and/or processing of a key agreement protocol exchange. 49: */ 50: public class KeyAgreementException 51: extends KeyManagementException 52: implements Serializable 53: { 54: /** @serial The possibly <code>null</code> <i>root</i> cause exception. */ 55: private Throwable cause = null; 56: 57: /** 58: * Constructs a new instance of <code>KeyAgreementException</code>. The 59: * root exception and the detailed message are <code>null</code>. 60: */ 61: public KeyAgreementException() 62: { 63: super(); 64: } 65: 66: /** 67: * Constructs a new instance of <code>KeyAgreementException</code> with a 68: * detailed message. The <i>root</i> exception is <code>null</code>. 69: * 70: * @param detail a possibly <code>null</code> string containing details of 71: * the exception. 72: * @see Throwable#getMessage() 73: */ 74: public KeyAgreementException(String detail) 75: { 76: super(detail); 77: } 78: 79: /** 80: * Constructs a new instance of <code>KeyAgreementException</code> with a 81: * detailed message and a <i>root</i> exception. 82: * 83: * @param detail a possibly <code>null</code> string containing details of 84: * the exception. 85: * @param cause a possibly <code>null</code> root exception that caused this 86: * exception. 87: * @see Throwable#getMessage() 88: * @see #getCause() 89: */ 90: public KeyAgreementException(String detail, Throwable cause) 91: { 92: super(detail); 93: this.cause = cause; 94: } 95: 96: /** 97: * Returns the cause of this throwable or <code>null</code> if the cause is 98: * nonexistent or unknown. The <i>cause</i> is the throwable that caused this 99: * exception to be thrown. 100: * 101: * @return the possibly <code>null</code> exception that caused this one. 102: */ 103: public Throwable getCause() 104: { 105: return cause; 106: } 107: 108: /** 109: * Prints this exception's stack trace to <code>System.err</code>. If this 110: * exception has a <i>root</i> exception; the stack trace of the <i>root</i> 111: * exception is also printed to <code>System.err</code>. 112: */ 113: public void printStackTrace() 114: { 115: super.printStackTrace(); 116: if (cause != null) 117: cause.printStackTrace(); 118: } 119: 120: /** 121: * Prints this exception's stack trace to a print stream. If this exception 122: * has a <i>root</i> exception; the stack trace of the <i>root</i> exception 123: * is also printed to the print stream. 124: * 125: * @param ps the non-null print stream to which to print. 126: */ 127: public void printStackTrace(PrintStream ps) 128: { 129: super.printStackTrace(ps); 130: if (cause != null) 131: cause.printStackTrace(ps); 132: } 133: 134: /** 135: * Prints this exception's stack trace to a print writer. If this exception 136: * has a <i>root</i> exception; the stack trace of the <i>root</i> exception 137: * is also printed to the print writer. 138: * 139: * @param pw the non-null print writer to use for output. 140: */ 141: public void printStackTrace(PrintWriter pw) 142: { 143: super.printStackTrace(pw); 144: if (cause != null) 145: cause.printStackTrace(pw); 146: } 147: 148: /** 149: * Returns the string representation of this exception. The string 150: * representation contains this exception's class name, its detailed messsage, 151: * and if it has a <i>root</i> exception, the string representation of the 152: * root exception. This string representation is meant for debugging and is 153: * not meant to be interpreted programmatically. 154: * 155: * @return the non-null string representation of this exception. 156: * @see Throwable#getMessage() 157: */ 158: public String toString() 159: { 160: StringBuffer sb = new StringBuffer(this.getClass().getName()).append(": ") 161: .append(super.toString()); 162: if (cause != null) 163: sb.append("; caused by: ").append(cause.toString()); 164: return sb.toString(); 165: } 166: }