some small changes delting unneeded imports. two new exceptions in mir.storage. usage...
[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
36 /**
37  * Reports the location of the error in the File.
38  * Based and inspired by a source from the Ant distribution
39  * (Copyright (c) 1999-2001 The Apache Software Foundation.)
40  *
41  * @version $Id: ConfigException.java,v 1.3 2003/01/25 17:45:17 idfx Exp $
42  *
43  * @author The Mir-coders group
44  */
45
46 public class ConfigException extends RuntimeException {
47
48     /** Exception that might have caused this one. */
49     private Throwable cause;
50
51     /** Location in the build file where the exception occured */
52     private Location location = Location.UNKNOWN_LOCATION;
53
54     /**
55      * Constructs a build exception with no descriptive information.
56      */
57     public ConfigException() {
58         super();
59     }
60
61     /**
62      * Constructs an exception with the given descriptive message.
63      * @param msg Description of or information about the exception.
64      */
65     public ConfigException(String msg) {
66         super(msg);
67     }
68
69     /**
70      * Constructs an exception with the given message and exception as
71      * a root cause.
72      * @param msg Description of or information about the exception.
73      * @param cause Throwable that might have cause this one.
74      */
75     public ConfigException(String msg, Throwable cause) {
76         super(msg);
77         this.cause = cause;
78     }
79
80     /**
81      * Constructs an exception with the given message and exception as
82      * a root cause and a location in a file.
83      * @param msg Description of or information about the exception.
84      * @param cause Exception that might have cause this one.
85      * @param location Location in the project file where the error occured.
86      */
87     public ConfigException(String msg, Throwable cause, Location location) {
88         this(msg, cause);
89         this.location = location;
90     }
91
92     /**
93      * Constructs an exception with the given exception as a root cause.
94      * @param cause Exception that might have caused this one.
95      */
96     public ConfigException(Throwable cause) {
97         super(cause.toString());
98         this.cause = cause;
99     }
100
101     /**
102      * Constructs an exception with the given descriptive message and a location
103      * in a file.
104      * @param msg Description of or information about the exception.
105      * @param location Location in the project file where the error occured.
106      */
107     public ConfigException(String msg, Location location) {
108         super(msg);
109         this.location = location;
110     }
111
112     /**
113      * Constructs an exception with the given exception as
114      * a root cause and a location in a file.
115      * @param cause Exception that might have cause this one.
116      * @param location Location in the project file where the error occured.
117      */
118     public ConfigException(Throwable cause, Location location) {
119         this(cause);
120         this.location = location;
121     }
122
123     /**
124      * Returns the nested exception.
125      */
126     public Throwable getException() {
127         return cause;
128     }
129
130     /**
131      * Returns the location of the error and the error message.
132      */
133     public String toString() {
134         return location.toString() + getMessage();
135     }
136
137     /**
138      * Sets the file location where the error occured.
139      */
140     public void setLocation(Location location) {
141         this.location = location;
142     }
143
144     /**
145      * Returns the file location where the error occured.
146      */
147     public Location getLocation() {
148         return location;
149     }
150
151     // Override stack trace methods to show original cause:
152     public void printStackTrace() {
153         printStackTrace(System.err);
154     }
155     
156 }