Mir goes GPL
[mir.git] / source / mir / misc / ConfigException.java
1 /*
2  * Copyright (C) 2001, 2002  The Mir-coders group
3  *
4  * This file is part of Mir.
5  *
6  * Mir is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * Mir is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Mir; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  * In addition, as a special exception, The Mir-coders gives permission to link
21  * the code of this program with the com.oreilly.servlet library, any library
22  * licensed under the Apache Software License, The Sun (tm) Java Advanced
23  * Imaging library (JAI), The Sun JIMI library (or with modified versions of
24  * the above that use the same license as the above), and distribute linked
25  * combinations including the two.  You must obey the GNU General Public
26  * License in all respects for all of the code used other than the above
27  * mentioned libraries.  If you modify this file, you may extend this exception
28  * to your version of the file, but you are not obligated to do so.  If you do
29  * not wish to do so, delete this exception statement from your version.
30  */
31
32 package mir.misc;
33
34
35 import java.io.*;
36
37 /**
38  * Reports the location of the error in the File.
39  * Based and inspired by a source from the Ant distribution
40  * (Copyright (c) 1999-2001 The Apache Software Foundation.)
41  *
42  * @version $Id: ConfigException.java,v 1.1.6.1 2002/09/01 21:31:40 mh Exp $
43  *
44  * @author The Mir-coders group
45  */
46
47 public class ConfigException extends RuntimeException {
48
49     /** Exception that might have caused this one. */
50     private Throwable cause;
51
52     /** Location in the build file where the exception occured */
53     private Location location = Location.UNKNOWN_LOCATION;
54
55     /**
56      * Constructs a build exception with no descriptive information.
57      */
58     public ConfigException() {
59         super();
60     }
61
62     /**
63      * Constructs an exception with the given descriptive message.
64      * @param msg Description of or information about the exception.
65      */
66     public ConfigException(String msg) {
67         super(msg);
68     }
69
70     /**
71      * Constructs an exception with the given message and exception as
72      * a root cause.
73      * @param msg Description of or information about the exception.
74      * @param cause Throwable that might have cause this one.
75      */
76     public ConfigException(String msg, Throwable cause) {
77         super(msg);
78         this.cause = cause;
79     }
80
81     /**
82      * Constructs an exception with the given message and exception as
83      * a root cause and a location in a file.
84      * @param msg Description of or information about the exception.
85      * @param cause Exception that might have cause this one.
86      * @param location Location in the project file where the error occured.
87      */
88     public ConfigException(String msg, Throwable cause, Location location) {
89         this(msg, cause);
90         this.location = location;
91     }
92
93     /**
94      * Constructs an exception with the given exception as a root cause.
95      * @param cause Exception that might have caused this one.
96      */
97     public ConfigException(Throwable cause) {
98         super(cause.toString());
99         this.cause = cause;
100     }
101
102     /**
103      * Constructs an exception with the given descriptive message and a location
104      * in a file.
105      * @param msg Description of or information about the exception.
106      * @param location Location in the project file where the error occured.
107      */
108     public ConfigException(String msg, Location location) {
109         super(msg);
110         this.location = location;
111     }
112
113     /**
114      * Constructs an exception with the given exception as
115      * a root cause and a location in a file.
116      * @param cause Exception that might have cause this one.
117      * @param location Location in the project file where the error occured.
118      */
119     public ConfigException(Throwable cause, Location location) {
120         this(cause);
121         this.location = location;
122     }
123
124     /**
125      * Returns the nested exception.
126      */
127     public Throwable getException() {
128         return cause;
129     }
130
131     /**
132      * Returns the location of the error and the error message.
133      */
134     public String toString() {
135         return location.toString() + getMessage();
136     }
137
138     /**
139      * Sets the file location where the error occured.
140      */
141     public void setLocation(Location location) {
142         this.location = location;
143     }
144
145     /**
146      * Returns the file location where the error occured.
147      */
148     public Location getLocation() {
149         return location;
150     }
151
152     // Override stack trace methods to show original cause:
153     public void printStackTrace() {
154         printStackTrace(System.err);
155     }
156     
157 }