KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > xquery > parser > XQueryException


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.xquery.parser;
24
25 public class XQueryException extends Exception JavaDoc {
26     
27     /** Error code for exception that have no associated error code. */
28     public static final int NO_CODE = 0;
29     /** Error code for server with too high a load */
30     public static final int LOAD_TOO_HIGH = 1;
31     /** Error code for illegal attempt to do something on data source */
32     public static final int PERMISSION_DENIED = 2;
33
34     //*************************** Properties declaration:
35

36     /** The error code of this exception. */
37     protected int errorCode;
38
39     /** The underlying exception (or error) of this exception. */
40     protected java.lang.Throwable JavaDoc exception;
41
42     //*************************** Constructor declaration:
43

44     /**
45      * Constructor with error code.
46      * @param code the code featuring the kind of error (see constants).
47      */

48     public XQueryException(int code) {
49         this(code, "",null);
50     }
51
52     /**
53      * Constructor with message.
54      * @param msg a message to describe the exception.
55      */

56     public XQueryException(java.lang.String JavaDoc msg) {
57         this(XQueryException.NO_CODE, msg, null);
58     }
59
60     /**
61      * Constructor with error code and message.
62      * @param code the code featuring the kind of error (see constants).
63      * @param msg a message to describe the exception.
64      */

65     public XQueryException(int code, java.lang.String JavaDoc msg) {
66         this(code, msg, null);
67     }
68
69     /**
70      * Constructor with message and underlying exception.
71      * @param msg a message to describe the exception.
72      * @param exception the underlying exception (or error).
73      */

74     public XQueryException(java.lang.String JavaDoc msg, java.lang.Throwable JavaDoc exception) {
75         this(XQueryException.NO_CODE, msg, exception);
76     }
77
78     /**
79      * Constructor with error code, message and underlying exception.
80      * @param code the code featuring the kind of error (see constants).
81      * @param msg a message to describe the exception.
82      * @param exception the underlying exception (or error).
83      */

84     public XQueryException(int code, java.lang.String JavaDoc msg, java.lang.Throwable JavaDoc exception) {
85         super(msg);
86         this.errorCode = code;
87         this.exception = exception;
88     }
89
90     //*************************** Other methods declaration:
91

92     /**
93      * To get the code of this exception/error.
94      * @return the error code.
95      */

96     public int getCode() {
97         return this.errorCode;
98     }
99
100     /**
101      * To get the exception of this exception/error.
102      * @return the underlying exception.
103      */

104     public java.lang.Throwable JavaDoc getException() {
105         return this.exception;
106     }
107
108
109     /**
110      * Returns the exception message, or the embedded exception message if none is present
111      * @return the message
112      */

113     public String JavaDoc getMessage() {
114     String JavaDoc message = super.getMessage();
115     if ((message == null || message.length() == 0) && this.exception != null) {
116         message = this.exception.getMessage();
117     }
118     return message;
119     }
120     /**
121      *
122      */

123     public void printStackTrace()
124     {
125         if (null != this.exception) {
126             this.exception.printStackTrace();
127         }
128         super.printStackTrace();
129     }
130
131     /**
132      *
133      */

134     public void printStackTrace(java.io.PrintWriter JavaDoc pw)
135     {
136         if (null != this.exception) {
137             this.exception.printStackTrace(pw);
138         }
139         super.printStackTrace(pw);
140     }
141
142     /**
143      *
144      */

145     public void printStackTrace(java.io.PrintStream JavaDoc ps)
146     {
147         if (null != this.exception) {
148             this.exception.printStackTrace(ps);
149         }
150         super.printStackTrace(ps);
151     }
152 }
153
154
155
156
157
158
159
160
161
162
163
164
165
Popular Tags