001: /* Copyright 2002-2005 Elliotte Rusty Harold
002:
003: This library is free software; you can redistribute it and/or modify
004: it under the terms of version 2.1 of the GNU Lesser General Public
005: License as published by the Free Software Foundation.
006:
007: This library is distributed in the hope that it will be useful,
008: but WITHOUT ANY WARRANTY; without even the implied warranty of
009: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
010: GNU Lesser General Public License for more details.
011:
012: You should have received a copy of the GNU Lesser General Public
013: License along with this library; if not, write to the
014: Free Software Foundation, Inc., 59 Temple Place, Suite 330,
015: Boston, MA 02111-1307 USA
016:
017: You can contact Elliotte Rusty Harold by sending e-mail to
018: elharo@metalab.unc.edu. Please include the word "XOM" in the
019: subject line. The XOM home page is located at http://www.xom.nu/
020: */
021:
022: package nu.xom.xslt;
023:
024: /**
025: * <p>
026: * Thrown when an XSL stylesheet fails to compile
027: * or an XSL transform fails.
028: * </p>
029: *
030: * @author Elliotte Rusty Harold
031: * @version 1.1b3
032: */
033: public class XSLException extends Exception {
034:
035: private static final long serialVersionUID = -8605437693812807627L;
036:
037: private Throwable cause;
038:
039: /**
040: * <p>
041: * Creates a new <code>XSLException</code> with the specified
042: * detail message and an underlying root cause.
043: * </p>
044: *
045: * @param message information about the cause of the exception
046: * @param cause the nested exception that caused this exception
047: */
048: public XSLException(String message, Throwable cause) {
049: super (message);
050: this .initCause(cause);
051: }
052:
053: /**
054: * <p>
055: * Creates a new <code>XSLException</code>
056: * with the specified detail message.
057: * </p>
058: *
059: * @param message information about the cause of the exception
060: */
061: public XSLException(String message) {
062: super (message);
063: }
064:
065: // null is insufficient for detecting an uninitialized cause.
066: // The cause may be set to null which may not then be reset.
067: private boolean causeSet = false;
068:
069: /**
070: * <p>
071: * Sets the root cause of this exception. This may
072: * only be called once. Subsequent calls throw an
073: * <code>IllegalStateException</code>.
074: * </p>
075: *
076: * <p>
077: * This method is unnecessary in Java 1.4 where it could easily be
078: * inherited from the superclass. However, including it here
079: * allows this method to be used in Java 1.3 and earlier.
080: * </p>
081: *
082: * @param cause the root cause of this exception
083: *
084: * @return this <code>XSLException</code>
085: *
086: * @throws IllegalArgumentException if the cause is this exception
087: * (An exception cannot be its own cause.)
088: * @throws IllegalStateException if this method is called twice
089: */
090: public final Throwable initCause(Throwable cause) {
091:
092: if (causeSet) {
093: throw new IllegalStateException("Can't overwrite cause");
094: } else if (cause == this ) {
095: throw new IllegalArgumentException(
096: "Self-causation not permitted");
097: } else
098: this .cause = cause;
099: causeSet = true;
100: return this ;
101:
102: }
103:
104: /**
105: * <p>
106: * Returns the underlying exception that caused this exception.
107: * </p>
108: *
109: * @return the initial exception that caused this exception
110: * to be thrown
111: */
112: public Throwable getCause() {
113: return this.cause;
114: }
115:
116: }
|