~ubuntu-branches/ubuntu/precise/xom/precise

« back to all changes in this revision

Viewing changes to src/nu/xom/canonical/CanonicalizationException.java

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2007-11-25 15:50:40 UTC
  • Revision ID: james.westby@ubuntu.com-20071125155040-r75ikcqf1vu0cei7
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 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
package nu.xom.canonical;
 
22
 
 
23
/**
 
24
 * <p>
 
25
 * Indicates problems with canonicalization.
 
26
 * </p>
 
27
 * 
 
28
 * @author Elliotte Rusty Harold
 
29
 * @version 1.1b3
 
30
 * 
 
31
 */
 
32
public class CanonicalizationException extends RuntimeException {
 
33
 
 
34
 
 
35
    private static final long serialVersionUID = 6935623053373600014L;
 
36
    
 
37
    private Throwable cause;
 
38
 
 
39
    
 
40
    /**
 
41
     * <p>
 
42
     * Creates a new <code>CanonicalizationException</code> 
 
43
     * with a detail message.
 
44
     * </p>
 
45
     * 
 
46
     * @param message a string indicating the specific problem
 
47
     */
 
48
    public CanonicalizationException(String message) {
 
49
        super(message);
 
50
    }
 
51
 
 
52
 
 
53
    /**
 
54
     * <p>
 
55
     *  Return the original cause that led to this exception,
 
56
     *  or null if there was no original exception.
 
57
     * </p>
 
58
     *
 
59
     * @return the root cause of this exception
 
60
     */
 
61
    public final Throwable getCause() {
 
62
        return this.cause;  
 
63
    }
 
64
 
 
65
    
 
66
    // null is insufficient for detecting an uninitialized cause.
 
67
    // The cause may be set to null which may not then be reset.
 
68
    private boolean causeSet = false;
 
69
 
 
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>XMLException</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 final Throwable initCause(Throwable cause) {
 
93
        
 
94
        if (causeSet) {
 
95
            throw new IllegalStateException("Can't overwrite cause");
 
96
        } 
 
97
        else if (cause == this) {
 
98
            throw new IllegalArgumentException("Self-causation not permitted"); 
 
99
        }
 
100
        else this.cause = cause;
 
101
        causeSet = true;
 
102
        return this;
 
103
        
 
104
    }
 
105
    
 
106
}