KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > util > xml > catalog > CatalogException


1 // CatalogException.java - Catalog exception
2

3 /* ====================================================================
4  * The Apache Software License, Version 1.1
5  *
6  * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
7  * reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution,
22  * if any, must include the following acknowledgment:
23  * "This product includes software developed by the
24  * Apache Software Foundation (http://www.apache.org/)."
25  * Alternately, this acknowledgment may appear in the software itself,
26  * if and wherever such third-party acknowledgments normally appear.
27  *
28  * 4. The names "Apache" and "Apache Software Foundation" must
29  * not be used to endorse or promote products derived from this
30  * software without prior written permission. For written
31  * permission, please contact apache@apache.org.
32  *
33  * 5. Products derived from this software may not be called "Apache",
34  * nor may "Apache" appear in their name, without prior written
35  * permission of the Apache Software Foundation.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48  * SUCH DAMAGE.
49  * ====================================================================
50  *
51  * This software consists of voluntary contributions made by many
52  * individuals on behalf of the Apache Software Foundation. For more
53  * information on the Apache Software Foundation, please see
54  * <http://www.apache.org/>.
55  */

56
57 package org.jboss.util.xml.catalog;
58
59 /**
60  * Signal Catalog exception.
61  *
62  * <p>This exception is thrown if an error occurs loading a
63  * catalog file.</p>
64  *
65  * @see Catalog
66  *
67  * @author Norman Walsh
68  * <a HREF="mailto:Norman.Walsh@Sun.COM">Norman.Walsh@Sun.COM</a>
69  *
70  * @version 1.0
71  */

72 public class CatalogException extends Exception JavaDoc {
73   /** A wrapper around another exception */
74   public static final int WRAPPER = 1;
75   /** An invalid entry */
76   public static final int INVALID_ENTRY = 2;
77   /** An invalid entry type */
78   public static final int INVALID_ENTRY_TYPE = 3;
79   /** Could not instantiate an XML parser */
80   public static final int NO_XML_PARSER = 4;
81   /** Unknown XML format */
82   public static final int UNKNOWN_FORMAT = 5;
83   /** Unparseable XML catalog (not XML)*/
84   public static final int UNPARSEABLE = 6;
85   /** XML but parse failed */
86   public static final int PARSE_FAILED = 7;
87
88   /**
89    * The embedded exception if tunnelling, or null.
90    */

91   private Exception JavaDoc exception = null;
92   private int exceptionType = 0;
93
94   /**
95    * Create a new CatalogException.
96    *
97    * @param type The exception type
98    * @param message The error or warning message.
99    */

100   public CatalogException (int type, String JavaDoc message) {
101     super(message);
102     this.exceptionType = type;
103     this.exception = null;
104   }
105
106   /**
107    * Create a new CatalogException.
108    *
109    * @param type The exception type
110    */

111   public CatalogException (int type) {
112     super("Catalog Exception " + type);
113     this.exceptionType = type;
114     this.exception = null;
115   }
116
117   /**
118    * Create a new CatalogException wrapping an existing exception.
119    *
120    * <p>The existing exception will be embedded in the new
121    * one, and its message will become the default message for
122    * the CatalogException.</p>
123    *
124    * @param e The exception to be wrapped in a CatalogException.
125    */

126   public CatalogException (Exception JavaDoc e) {
127     super();
128     this.exceptionType = WRAPPER;
129     this.exception = e;
130   }
131
132   /**
133    * Create a new CatalogException from an existing exception.
134    *
135    * <p>The existing exception will be embedded in the new
136    * one, but the new exception will have its own message.</p>
137    *
138    * @param message The detail message.
139    * @param e The exception to be wrapped in a CatalogException.
140    */

141   public CatalogException (String JavaDoc message, Exception JavaDoc e) {
142     super(message);
143     this.exceptionType = WRAPPER;
144     this.exception = e;
145   }
146
147   /**
148    * Return a detail message for this exception.
149    *
150    * <p>If there is an embedded exception, and if the CatalogException
151    * has no detail message of its own, this method will return
152    * the detail message from the embedded exception.</p>
153    *
154    * @return The error or warning message.
155    */

156   public String JavaDoc getMessage ()
157   {
158     String JavaDoc message = super.getMessage();
159
160     if (message == null && exception != null) {
161       return exception.getMessage();
162     } else {
163       return message;
164     }
165   }
166
167   /**
168    * Return the embedded exception, if any.
169    *
170    * @return The embedded exception, or null if there is none.
171    */

172   public Exception JavaDoc getException ()
173   {
174     return exception;
175   }
176
177   /**
178    * Return the exception type
179    *
180    * @return The exception type
181    */

182   public int getExceptionType ()
183   {
184     return exceptionType;
185   }
186
187   /**
188    * Override toString to pick up any embedded exception.
189    *
190    * @return A string representation of this exception.
191    */

192   public String JavaDoc toString ()
193   {
194     if (exception != null) {
195       return exception.toString();
196     } else {
197       return super.toString();
198     }
199   }
200 }
201
Popular Tags