001: /*
002: * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
003: * @version $Id: PortletDispatcherException.java 6385 2007-10-25 14:02:26Z wehrens $
004: */
005: package org.gridsphere.portletcontainer;
006:
007: import javax.servlet.ServletException;
008: import java.io.PrintStream;
009: import java.io.PrintWriter;
010:
011: /**
012: * The <code>PortletException</code> class defines a general exception that a
013: * portlet can throw when it encounters an exceptional condition.
014: */
015: public class PortletDispatcherException extends ServletException {
016:
017: private Throwable cause = null;
018: private String text = "";
019:
020: /**
021: * Constructs an instance of PortletException
022: */
023: public PortletDispatcherException() {
024: super ();
025: }
026:
027: /**
028: * Constructs an instance of PortletException with the given text.
029: * The portlet container may use the text write it to a log.
030: *
031: * @param text the exception text
032: */
033: public PortletDispatcherException(String text) {
034: super (text);
035: this .text = text;
036: }
037:
038: /**
039: * Constructs a new portlet exception with the given text.
040: * The portlet container may use the text write it to a log.
041: *
042: * @param text the exception text
043: * @param cause the root cause
044: */
045: public PortletDispatcherException(String text, Throwable cause) {
046: super (text, cause);
047: this .text = text;
048: this .cause = cause;
049: }
050:
051: /**
052: * Constructs a new portlet exception when the portlet needs to throw an exception.
053: * The exception's message is based on the localized message of the underlying exception.
054: *
055: * @param cause the root cause
056: */
057: public PortletDispatcherException(Throwable cause) {
058: super (cause);
059: this .cause = cause;
060: text = cause.getMessage();
061: }
062:
063: /**
064: * Return the exception message
065: *
066: * @return the exception message
067: */
068: public String getMessage() {
069: return text;
070: }
071:
072: public Throwable getCause() {
073: return ((cause != null) ? cause.getCause() : null);
074: }
075:
076: public void printStackTrace() {
077: if (cause != null) {
078: cause.printStackTrace();
079: }
080: }
081:
082: public void printStackTrace(PrintStream ps) {
083: if (text != null)
084: ps.println(text);
085: if (cause != null) {
086: ps.println("Caused by:");
087: cause.printStackTrace(ps);
088: }
089: }
090:
091: public void printStackTrace(PrintWriter pw) {
092: if (text != null)
093: pw.println(text);
094: if (cause != null) {
095: pw.println("Caused by:");
096: cause.printStackTrace(pw);
097: }
098: }
099:
100: /**
101: * Returns the exception that caused this servlet exception.
102: *
103: *
104: * @return the <code>Throwable</code>
105: * that caused this servlet exception
106: *
107: */
108:
109: public Throwable getRootCause() {
110: return cause;
111: }
112:
113: }
|