001: package com.sun.portal.providers.context;
002:
003: import java.io.PrintWriter;
004: import java.io.BufferedReader;
005: import java.io.PrintStream;
006: import java.io.PrintWriter;
007:
008: /**
009: * <p>This exception is a generic superclass for all provider related
010: * exceptions. All exceptions deliberately-thrown from a provider
011: * should be a subclass of this.
012: **/
013:
014: public class ProviderContextException extends Exception {
015: /**
016: * The root cause of the exception, or null if this exception is
017: * the root cause.
018: */
019: protected Throwable wrapped = null;
020:
021: /**
022: * Constructs a new exception with the specified message, indicating an
023: * error in the provider context as happened.<br><br>
024: *
025: * @param msg The descriptive message.
026: */
027: public ProviderContextException(String msg) {
028: super (msg);
029: }
030:
031: /**
032: * Constructs a new exception with the specified message, and the original
033: * <code>exception</code> or <code>error</code>, indicating an error in the
034: * provider context as happened.<br><br>
035: *
036: * @param msg The descriptive message.
037: * @param e The original <code>exception</code> or <code>error</code>.
038: */
039: public ProviderContextException(String msg, Throwable e) {
040: super (msg);
041: wrapped = e;
042: }
043:
044: /**
045: * Returns the <code>Throwable</code> object which is the root cause of
046: * the exception. It returns null if this exception is the root cause.
047: */
048: public Throwable getWrapped() {
049: return wrapped;
050: }
051:
052: /**
053: * Returns a descriptive message of this exception. If the <code>wrapped</code> object is
054: * not null, the appends the description of the wrapped object to the
055: * result.
056: */
057: public String toString() {
058: StringBuffer b = new StringBuffer();
059:
060: b.append(super .toString());
061: if (getWrapped() != null) {
062: b.append(wrapped.toString());
063: }
064:
065: return b.toString();
066: }
067:
068: /**
069: * Prints the stack backtrace. If the <code>wrapped</code> object is not null then
070: * it also prints the stack backtrace of that exception.
071: */
072: public void printStackTrace() {
073: super .printStackTrace();
074: if (getWrapped() != null) {
075: wrapped.printStackTrace();
076: }
077: }
078:
079: /**
080: * Prints the stack backtrace to the specified print stream.
081: * If the <code>wrapped</code> object is not null then it also prints the stack
082: * backtrace of that exception.
083: */
084: public void printStackTrace(PrintStream s) {
085: super .printStackTrace(s);
086: if (getWrapped() != null) {
087: wrapped.printStackTrace(s);
088: }
089: }
090:
091: /**
092: * Prints the stack backtrace to the specified print writer.
093: * If the <code>wrapped</code> object is not null then it also prints the stack
094: * backtrace of that exception.
095: */
096: public void printStackTrace(PrintWriter s) {
097: super.printStackTrace(s);
098: if (getWrapped() != null) {
099: wrapped.printStackTrace(s);
100: }
101: }
102: }
|