~vcs-imports/xena/trunk

« back to all changes in this revision

Viewing changes to src/nu/xom/xslt/XSLException.java

  • Committer: matthewoliver
  • Date: 2009-12-10 03:18:07 UTC
  • Revision ID: vcs-imports@canonical.com-20091210031807-l086qguzdlljtkl9
Merged Xena Testing into Xena Stable for the Xena 5 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2002-2005 Elliotte Rusty Harold
 
2
   
 
3
   This library is free software; you can redistribute it and/or modify
 
4
   it under the terms of version 2.1 of the GNU Lesser General Public 
 
5
   License as published by the Free Software Foundation.
 
6
   
 
7
   This library is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 
10
   GNU Lesser General Public License for more details.
 
11
   
 
12
   You should have received a copy of the GNU Lesser General Public
 
13
   License along with this library; if not, write to the 
 
14
   Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
 
15
   Boston, MA 02111-1307  USA
 
16
   
 
17
   You can contact Elliotte Rusty Harold by sending e-mail to
 
18
   elharo@metalab.unc.edu. Please include the word "XOM" in the
 
19
   subject line. The XOM home page is located at http://www.xom.nu/
 
20
*/
 
21
 
 
22
package nu.xom.xslt;
 
23
 
 
24
/**
 
25
 * <p>
 
26
 *   Thrown when an XSL stylesheet fails to compile
 
27
 *   or an XSL transform fails.
 
28
 * </p>
 
29
 * 
 
30
 * @author Elliotte Rusty Harold
 
31
 * @version 1.1b3
 
32
 */
 
33
public class XSLException extends Exception {
 
34
 
 
35
    private static final long serialVersionUID = -8605437693812807627L;
 
36
    
 
37
    private Throwable cause;
 
38
 
 
39
    
 
40
    /**
 
41
     * <p>
 
42
     * Creates a new <code>XSLException</code> with the specified 
 
43
     * detail message and an underlying root cause.
 
44
     * </p>
 
45
     * 
 
46
     * @param message information about the cause of the exception
 
47
     * @param cause the nested exception that caused this exception
 
48
     */
 
49
    public XSLException(String message, Throwable cause) {
 
50
        super(message);
 
51
        this.initCause(cause);
 
52
    }
 
53
    
 
54
    
 
55
    /**
 
56
     * <p>
 
57
     * Creates a new <code>XSLException</code>
 
58
     * with the specified detail message.
 
59
     * </p>
 
60
     * 
 
61
     * @param message information about the cause of the exception
 
62
     */
 
63
    public XSLException(String message) {
 
64
        super(message);
 
65
    }
 
66
 
 
67
    
 
68
    // null is insufficient for detecting an uninitialized cause.
 
69
    // The cause may be set to null which may not then be reset.
 
70
    private boolean causeSet = false;
 
71
 
 
72
    /**
 
73
     * <p>
 
74
     * Sets the root cause of this exception. This may 
 
75
     * only be called once. Subsequent calls throw an 
 
76
     * <code>IllegalStateException</code>.
 
77
     * </p>
 
78
     * 
 
79
     * <p>
 
80
     * This method is unnecessary in Java 1.4 where it could easily be
 
81
     * inherited from the superclass. However, including it here
 
82
     * allows this  method to be used in Java 1.3 and earlier.
 
83
     * </p>
 
84
     *
 
85
     * @param cause the root cause of this exception
 
86
     * 
 
87
     * @return this <code>XSLException</code>
 
88
     * 
 
89
     * @throws IllegalArgumentException if the cause is this exception
 
90
     *   (An exception cannot be its own cause.)
 
91
     * @throws IllegalStateException if this method is called twice
 
92
     */
 
93
    public final Throwable initCause(Throwable cause) {
 
94
        
 
95
        if (causeSet) {
 
96
            throw new IllegalStateException("Can't overwrite cause");
 
97
        } 
 
98
        else if (cause == this) {
 
99
            throw new IllegalArgumentException(
 
100
              "Self-causation not permitted"); 
 
101
        }
 
102
        else this.cause = cause;
 
103
        causeSet = true;
 
104
        return this;
 
105
        
 
106
    }
 
107
 
 
108
    
 
109
    /**
 
110
     * <p>
 
111
     * Returns the underlying exception that caused this exception.
 
112
     * </p>
 
113
     * 
 
114
     * @return the initial exception that caused this exception 
 
115
     *     to be thrown
 
116
     */
 
117
    public Throwable getCause() {
 
118
        return this.cause;  
 
119
    }
 
120
 
 
121
    
 
122
}