001: /*
002: * regain - A file search engine providing plenty of formats
003: * Copyright (C) 2004 Til Schneider
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * Contact: Til Schneider, info@murfman.de
020: *
021: * CVS information:
022: * $RCSfile$
023: * $Source$
024: * $Date: 2005-02-24 16:31:49 +0100 (Do, 24 Feb 2005) $
025: * $Author: til132 $
026: * $Revision: 30 $
027: */
028: package net.sf.regain.util.sharedtag.taglib;
029:
030: import java.io.PrintStream;
031: import java.io.PrintWriter;
032:
033: import javax.servlet.jsp.JspException;
034:
035: /**
036: * Eine JspException, die eingebettete Exceptions unterstützt.
037: * <p>
038: * This class has the same code as {@link net.sf.regain.RegainException}.
039: * The only difference is, that is inherits from <code>JspException</code>.
040: *
041: * @author Til Schneider, www.murfman.de
042: */
043: public class ExtendedJspException extends JspException {
044:
045: /** The nested exception. May be null. */
046: private Throwable mCause;
047:
048: /**
049: * Creates a new instance of SearchException.
050: *
051: * @param message The error message
052: */
053: public ExtendedJspException(String message) {
054: this (message, null);
055: }
056:
057: /**
058: * Creates a new instance of SearchException.
059: *
060: * @param message The error message
061: * @param cause The nested exception.
062: */
063: public ExtendedJspException(String message, Throwable cause) {
064: super (message);
065:
066: mCause = cause;
067: }
068:
069: /**
070: * Gets the cause of this exception. (May be null)
071: *
072: * @return The cause of this exception or <code>null</code> if there no other
073: * Throwable has caused this exception.
074: */
075: public Throwable getCause() {
076: return mCause;
077: }
078:
079: /**
080: * Prints the stack trace of this exception an of the nested exception, if
081: * present.
082: *
083: * @param stream The stream to print to.
084: */
085: public void printStackTrace(PrintStream stream) {
086: super .printStackTrace(stream);
087:
088: if ((mCause != null) && (!super ClassPrintsCause())) {
089: stream.println("Caused by: " + mCause.getMessage() + ":");
090: mCause.printStackTrace(stream);
091: }
092: }
093:
094: /**
095: * Prints the stack trace of this exception an of the nested exception, if
096: * present.
097: *
098: * @param writer The writer to print to.
099: */
100: public void printStackTrace(PrintWriter writer) {
101: super .printStackTrace(writer);
102:
103: if ((mCause != null) && (!super ClassPrintsCause())) {
104: writer.println("Caused by: " + mCause.getMessage() + ":");
105: mCause.printStackTrace(writer);
106: }
107: }
108:
109: /**
110: * Gets whether the superclass is able to print the cause of the exception.
111: * This is true for Java 1.4 and above.
112: *
113: * @return Whether the superclass is able to print the cause of the exception.
114: */
115: private boolean super ClassPrintsCause() {
116: // Check whether there is a getCause method in the super class
117: try {
118: getClass().getSuperclass().getMethod("getCause", null);
119:
120: // The superclass has a getCause method -> It must be Java 1.4 or more
121: return true;
122: } catch (Exception exc) {
123: // The superclass has no getCause method -> It must be Java 1.3 or less
124: return false;
125: }
126: }
127:
128: }
|