KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xml > internal > resolver > CatalogException


1 // CatalogException.java - Catalog exception
2

3 /*
4  * Copyright 2001-2004 The Apache Software Foundation or its licensors,
5  * as applicable.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19
20 package com.sun.org.apache.xml.internal.resolver;
21
22 /**
23  * Signal Catalog exception.
24  *
25  * <p>This exception is thrown if an error occurs loading a
26  * catalog file.</p>
27  *
28  * @see Catalog
29  *
30  * @author Norman Walsh
31  * <a HREF="mailto:Norman.Walsh@Sun.COM">Norman.Walsh@Sun.COM</a>
32  *
33  * @version 1.0
34  */

35 public class CatalogException extends Exception JavaDoc {
36   /** A wrapper around another exception */
37   public static final int WRAPPER = 1;
38   /** An invalid entry */
39   public static final int INVALID_ENTRY = 2;
40   /** An invalid entry type */
41   public static final int INVALID_ENTRY_TYPE = 3;
42   /** Could not instantiate an XML parser */
43   public static final int NO_XML_PARSER = 4;
44   /** Unknown XML format */
45   public static final int UNKNOWN_FORMAT = 5;
46   /** Unparseable XML catalog (not XML)*/
47   public static final int UNPARSEABLE = 6;
48   /** XML but parse failed */
49   public static final int PARSE_FAILED = 7;
50   /** Text catalog ended in mid-comment */
51   public static final int UNENDED_COMMENT = 8;
52
53   /**
54    * The embedded exception if tunnelling, or null.
55    */

56   private Exception JavaDoc exception = null;
57   private int exceptionType = 0;
58
59   /**
60    * Create a new CatalogException.
61    *
62    * @param type The exception type
63    * @param message The error or warning message.
64    */

65   public CatalogException (int type, String JavaDoc message) {
66     super(message);
67     this.exceptionType = type;
68     this.exception = null;
69   }
70
71   /**
72    * Create a new CatalogException.
73    *
74    * @param type The exception type
75    */

76   public CatalogException (int type) {
77     super("Catalog Exception " + type);
78     this.exceptionType = type;
79     this.exception = null;
80   }
81
82   /**
83    * Create a new CatalogException wrapping an existing exception.
84    *
85    * <p>The existing exception will be embedded in the new
86    * one, and its message will become the default message for
87    * the CatalogException.</p>
88    *
89    * @param e The exception to be wrapped in a CatalogException.
90    */

91   public CatalogException (Exception JavaDoc e) {
92     super();
93     this.exceptionType = WRAPPER;
94     this.exception = e;
95   }
96
97   /**
98    * Create a new CatalogException from an existing exception.
99    *
100    * <p>The existing exception will be embedded in the new
101    * one, but the new exception will have its own message.</p>
102    *
103    * @param message The detail message.
104    * @param e The exception to be wrapped in a CatalogException.
105    */

106   public CatalogException (String JavaDoc message, Exception JavaDoc e) {
107     super(message);
108     this.exceptionType = WRAPPER;
109     this.exception = e;
110   }
111
112   /**
113    * Return a detail message for this exception.
114    *
115    * <p>If there is an embedded exception, and if the CatalogException
116    * has no detail message of its own, this method will return
117    * the detail message from the embedded exception.</p>
118    *
119    * @return The error or warning message.
120    */

121   public String JavaDoc getMessage ()
122   {
123     String JavaDoc message = super.getMessage();
124
125     if (message == null && exception != null) {
126       return exception.getMessage();
127     } else {
128       return message;
129     }
130   }
131
132   /**
133    * Return the embedded exception, if any.
134    *
135    * @return The embedded exception, or null if there is none.
136    */

137   public Exception JavaDoc getException ()
138   {
139     return exception;
140   }
141
142   /**
143    * Return the exception type
144    *
145    * @return The exception type
146    */

147   public int getExceptionType ()
148   {
149     return exceptionType;
150   }
151
152   /**
153    * Override toString to pick up any embedded exception.
154    *
155    * @return A string representation of this exception.
156    */

157   public String JavaDoc toString ()
158   {
159     if (exception != null) {
160       return exception.toString();
161     } else {
162       return super.toString();
163     }
164   }
165 }
166
Popular Tags