001: /* Copyright 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: package nu.xom.canonical;
022:
023: /**
024: * <p>
025: * Indicates problems with canonicalization.
026: * </p>
027: *
028: * @author Elliotte Rusty Harold
029: * @version 1.1b3
030: *
031: */
032: public class CanonicalizationException extends RuntimeException {
033:
034: private static final long serialVersionUID = 6935623053373600014L;
035:
036: private Throwable cause;
037:
038: /**
039: * <p>
040: * Creates a new <code>CanonicalizationException</code>
041: * with a detail message.
042: * </p>
043: *
044: * @param message a string indicating the specific problem
045: */
046: public CanonicalizationException(String message) {
047: super (message);
048: }
049:
050: /**
051: * <p>
052: * Return the original cause that led to this exception,
053: * or null if there was no original exception.
054: * </p>
055: *
056: * @return the root cause of this exception
057: */
058: public final Throwable getCause() {
059: return this .cause;
060: }
061:
062: // null is insufficient for detecting an uninitialized cause.
063: // The cause may be set to null which may not then be reset.
064: private boolean causeSet = false;
065:
066: /**
067: * <p>
068: * Sets the root cause of this exception. This may
069: * only be called once. Subsequent calls throw an
070: * <code>IllegalStateException</code>.
071: * </p>
072: *
073: * <p>
074: * This method is unnecessary in Java 1.4 where it could easily be
075: * inherited from the superclass. However, including it here
076: * allows this method to be used in Java 1.3 and earlier.
077: * </p>
078: *
079: * @param cause the root cause of this exception
080: *
081: * @return this <code>XMLException</code>
082: *
083: * @throws IllegalArgumentException if the cause is this exception
084: * (An exception cannot be its own cause.)
085: * @throws IllegalStateException if this method is called twice
086: */
087: public final Throwable initCause(Throwable cause) {
088:
089: if (causeSet) {
090: throw new IllegalStateException("Can't overwrite cause");
091: } else if (cause == this ) {
092: throw new IllegalArgumentException(
093: "Self-causation not permitted");
094: } else
095: this .cause = cause;
096: causeSet = true;
097: return this;
098:
099: }
100:
101: }
|