KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nu > xom > xslt > XSLException


1 /* Copyright 2002-2004 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.0
32  */

33 public class XSLException extends Exception JavaDoc {
34
35     
36     private Throwable JavaDoc cause;
37
38     
39     /**
40      * <p>
41      * Creates a new <code>XSLException</code> with the specified
42      * detail message and an underlying root cause.
43      * </p>
44      *
45      * @param message information about the cause of the exception
46      * @param cause the nested exception that caused this exception
47      */

48     public XSLException(String JavaDoc message, Throwable JavaDoc cause) {
49         super(message);
50         this.initCause(cause);
51     }
52     
53     
54     /**
55      * <p>
56      * Creates a new <code>XSLException</code>
57      * with the specified detail message.
58      * </p>
59      *
60      * @param message information about the cause of the exception
61      */

62     public XSLException(String JavaDoc message) {
63         super(message);
64     }
65
66     
67     // null is insufficient for detecting an uninitialized cause.
68
// The cause may be set to null which may not then be reset.
69
private boolean causeSet = false;
70
71     /**
72      * <p>
73      * Sets the root cause of this exception. This may
74      * only be called once. Subsequent calls throw an
75      * <code>IllegalStateException</code>.
76      * </p>
77      *
78      * <p>
79      * This method is unnecessary in Java 1.4 where it could easily be
80      * inherited from the superclass. However, including it here
81      * allows this method to be used in Java 1.3 and earlier.
82      * </p>
83      *
84      * @param cause the root cause of this exception
85      *
86      * @return this <code>XSLException</code>
87      *
88      * @throws IllegalArgumentException if the cause is this exception
89      * (An exception cannot be its own cause.)
90      * @throws IllegalStateException if this method is called twice
91      */

92     public Throwable JavaDoc initCause(Throwable JavaDoc cause) {
93         
94         if (causeSet) {
95             throw new IllegalStateException JavaDoc("Can't overwrite cause");
96         }
97         else if (cause == this) {
98             throw new IllegalArgumentException JavaDoc(
99               "Self-causation not permitted");
100         }
101         else this.cause = cause;
102         causeSet = true;
103         return this;
104         
105     }
106
107     
108     /**
109      * <p>
110      * Returns the underlying exception that caused this exception.
111      * </p>
112      *
113      * @return the initial exception that caused this exception
114      * to be thrown
115      */

116     public Throwable JavaDoc getCause() {
117         return this.cause;
118     }
119
120     
121 }
122
Popular Tags