| 1 |
/* |
| 2 |
* Copyright 1999-2010 University of Chicago |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in |
| 5 |
* compliance with the License. You may obtain a copy of the License at |
| 6 |
* |
| 7 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
* |
| 9 |
* Unless required by applicable law or agreed to in writing, software distributed under the License is |
| 10 |
* distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 11 |
* express or implied. |
| 12 |
* |
| 13 |
* See the License for the specific language governing permissions and limitations under the License. |
| 14 |
*/ |
| 15 |
package org.globus.common; |
| 16 |
|
| 17 |
/** |
| 18 |
* @deprecated |
| 19 |
*/ |
| 20 |
public class ChainedCertificateException |
| 21 |
extends java.security.cert.CertificateException { |
| 22 |
|
| 23 |
/** |
| 24 |
* The possibly null root cause exception. |
| 25 |
* @serial |
| 26 |
*/ |
| 27 |
private Throwable exception; |
| 28 |
|
| 29 |
/** |
| 30 |
* Constructs a new instance of <tt>ChainedIOException</tt>. |
| 31 |
* The root exception and the detailed message are null. |
| 32 |
*/ |
| 33 |
public ChainedCertificateException () { |
| 34 |
super(); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Constructs a new instance of <tt>ChainedIOException</tt> with a |
| 39 |
* detailed message. The root exception is null. |
| 40 |
* |
| 41 |
* @param detail A possibly null string containing details of the |
| 42 |
* exception. |
| 43 |
* |
| 44 |
* @see java.lang.Throwable#getMessage |
| 45 |
*/ |
| 46 |
public ChainedCertificateException (String detail) { |
| 47 |
super(detail); |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Constructs a new instance of <tt>ChainedIOException</tt> with a |
| 52 |
* detailed message and a root exception. |
| 53 |
* |
| 54 |
* @param detail A possibly null string containing details of the |
| 55 |
* exception. |
| 56 |
* @param ex A possibly null root exception that caused this exception. |
| 57 |
* |
| 58 |
* @see java.lang.Throwable#getMessage |
| 59 |
* @see #getException |
| 60 |
*/ |
| 61 |
public ChainedCertificateException (String detail, Throwable ex) { |
| 62 |
super(detail); |
| 63 |
exception = ex; |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Returns the root exception that caused this exception. |
| 68 |
* @return The possibly null root exception that caused this exception. |
| 69 |
*/ |
| 70 |
public Throwable getException() { |
| 71 |
return exception; |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Prints this exception's stack trace to <tt>System.err</tt>. |
| 76 |
* If this exception has a root exception; the stack trace of the |
| 77 |
* root exception is printed to <tt>System.err</tt> instead. |
| 78 |
*/ |
| 79 |
public void printStackTrace() { |
| 80 |
printStackTrace( System.err ); |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Prints this exception's stack trace to a print stream. |
| 85 |
* If this exception has a root exception; the stack trace of the |
| 86 |
* root exception is printed to the print stream instead. |
| 87 |
* @param ps The non-null print stream to which to print. |
| 88 |
*/ |
| 89 |
public void printStackTrace(java.io.PrintStream ps) { |
| 90 |
if ( exception != null ) { |
| 91 |
String superString = getLocalMessage(); |
| 92 |
synchronized ( ps ) { |
| 93 |
ps.print(superString); |
| 94 |
ps.print((superString.endsWith(".") ? |
| 95 |
" Caused by " : ". Caused by ")); |
| 96 |
exception.printStackTrace( ps ); |
| 97 |
} |
| 98 |
} else { |
| 99 |
super.printStackTrace( ps ); |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* Prints this exception's stack trace to a print writer. |
| 105 |
* If this exception has a root exception; the stack trace of the |
| 106 |
* root exception is printed to the print writer instead. |
| 107 |
* @param pw The non-null print writer to which to print. |
| 108 |
*/ |
| 109 |
public void printStackTrace(java.io.PrintWriter pw) { |
| 110 |
if ( exception != null ) { |
| 111 |
String superString = getLocalMessage(); |
| 112 |
synchronized (pw) { |
| 113 |
pw.print(superString); |
| 114 |
pw.print((superString.endsWith(".") ? |
| 115 |
" Caused by " : ". Caused by ")); |
| 116 |
exception.printStackTrace( pw ); |
| 117 |
} |
| 118 |
} else { |
| 119 |
super.printStackTrace( pw ); |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
public String getMessage() { |
| 124 |
String answer = super.getMessage(); |
| 125 |
if (exception != null && exception != this) { |
| 126 |
String msg = exception.getMessage(); |
| 127 |
if (msg == null) { |
| 128 |
msg = exception.getClass().getName(); |
| 129 |
} |
| 130 |
answer += " [Caused by: " + msg + "]"; |
| 131 |
} |
| 132 |
return answer; |
| 133 |
} |
| 134 |
|
| 135 |
private String getLocalMessage() { |
| 136 |
String message = super.getMessage(); |
| 137 |
return (message == null) ? getClass().getName() : message; |
| 138 |
} |
| 139 |
} |