~hudson-ubuntu/+junk/hudson-dom4j

« back to all changes in this revision

Viewing changes to src/java/org/dom4j/DocumentException.java

  • Committer: James Page
  • Date: 2010-11-18 13:20:23 UTC
  • Revision ID: james.page@canonical.com-20101118132023-puz3z975327yu8ib
Initial release of hudson variant

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
 
3
 *
 
4
 * This software is open source.
 
5
 * See the bottom of this file for the licence.
 
6
 */
 
7
 
 
8
package org.dom4j;
 
9
 
 
10
import java.io.PrintStream;
 
11
import java.io.PrintWriter;
 
12
 
 
13
/**
 
14
 * <p>
 
15
 * <code>DocumentException</code> is a nested Exception which may be thrown
 
16
 * during the processing of a DOM4J document.
 
17
 * </p>
 
18
 * 
 
19
 * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
 
20
 * @version $Revision: 1.7 $
 
21
 */
 
22
public class DocumentException extends Exception {
 
23
    /** A wrapped <code>Throwable</code> */
 
24
    private Throwable nestedException;
 
25
 
 
26
    public DocumentException() {
 
27
        super("Error occurred in DOM4J application.");
 
28
    }
 
29
 
 
30
    public DocumentException(String message) {
 
31
        super(message);
 
32
    }
 
33
 
 
34
    public DocumentException(Throwable nestedException) {
 
35
        super(nestedException.getMessage());
 
36
        this.nestedException = nestedException;
 
37
    }
 
38
 
 
39
    public DocumentException(String message, Throwable nestedException) {
 
40
        super(message);
 
41
        this.nestedException = nestedException;
 
42
    }
 
43
 
 
44
    public Throwable getNestedException() {
 
45
        return nestedException;
 
46
    }
 
47
 
 
48
    // on JDK 1.4 and above this helps exception chaining
 
49
    public Throwable getCause() {
 
50
        return nestedException;
 
51
    }
 
52
 
 
53
    public String getMessage() {
 
54
        if (nestedException != null) {
 
55
            return super.getMessage() + " Nested exception: "
 
56
                    + nestedException.getMessage();
 
57
        } else {
 
58
            return super.getMessage();
 
59
        }
 
60
    }
 
61
 
 
62
    public void printStackTrace() {
 
63
        super.printStackTrace();
 
64
 
 
65
        if (nestedException != null) {
 
66
            System.err.print("Nested exception: ");
 
67
            nestedException.printStackTrace();
 
68
        }
 
69
    }
 
70
 
 
71
    public void printStackTrace(PrintStream out) {
 
72
        super.printStackTrace(out);
 
73
 
 
74
        if (nestedException != null) {
 
75
            out.println("Nested exception: ");
 
76
            nestedException.printStackTrace(out);
 
77
        }
 
78
    }
 
79
 
 
80
    public void printStackTrace(PrintWriter writer) {
 
81
        super.printStackTrace(writer);
 
82
 
 
83
        if (nestedException != null) {
 
84
            writer.println("Nested exception: ");
 
85
            nestedException.printStackTrace(writer);
 
86
        }
 
87
    }
 
88
}
 
89
 
 
90
/*
 
91
 * Redistribution and use of this software and associated documentation
 
92
 * ("Software"), with or without modification, are permitted provided that the
 
93
 * following conditions are met:
 
94
 * 
 
95
 * 1. Redistributions of source code must retain copyright statements and
 
96
 * notices. Redistributions must also contain a copy of this document.
 
97
 * 
 
98
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 
99
 * this list of conditions and the following disclaimer in the documentation
 
100
 * and/or other materials provided with the distribution.
 
101
 * 
 
102
 * 3. The name "DOM4J" must not be used to endorse or promote products derived
 
103
 * from this Software without prior written permission of MetaStuff, Ltd. For
 
104
 * written permission, please contact dom4j-info@metastuff.com.
 
105
 * 
 
106
 * 4. Products derived from this Software may not be called "DOM4J" nor may
 
107
 * "DOM4J" appear in their names without prior written permission of MetaStuff,
 
108
 * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
 
109
 * 
 
110
 * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
 
111
 * 
 
112
 * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
 
113
 * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
114
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
115
 * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
 
116
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
117
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
118
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
119
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 
120
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
121
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
122
 * POSSIBILITY OF SUCH DAMAGE.
 
123
 * 
 
124
 * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
 
125
 */