001: // CatalogException.java - Catalog exception
002:
003: /*
004: * Copyright 2001-2004 The Apache Software Foundation or its licensors,
005: * as applicable.
006: *
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: */
019:
020: package com.sun.org.apache.xml.internal.resolver;
021:
022: /**
023: * Signal Catalog exception.
024: *
025: * <p>This exception is thrown if an error occurs loading a
026: * catalog file.</p>
027: *
028: * @see Catalog
029: *
030: * @author Norman Walsh
031: * <a href="mailto:Norman.Walsh@Sun.COM">Norman.Walsh@Sun.COM</a>
032: *
033: * @version 1.0
034: */
035: public class CatalogException extends Exception {
036: /** A wrapper around another exception */
037: public static final int WRAPPER = 1;
038: /** An invalid entry */
039: public static final int INVALID_ENTRY = 2;
040: /** An invalid entry type */
041: public static final int INVALID_ENTRY_TYPE = 3;
042: /** Could not instantiate an XML parser */
043: public static final int NO_XML_PARSER = 4;
044: /** Unknown XML format */
045: public static final int UNKNOWN_FORMAT = 5;
046: /** Unparseable XML catalog (not XML)*/
047: public static final int UNPARSEABLE = 6;
048: /** XML but parse failed */
049: public static final int PARSE_FAILED = 7;
050: /** Text catalog ended in mid-comment */
051: public static final int UNENDED_COMMENT = 8;
052:
053: /**
054: * The embedded exception if tunnelling, or null.
055: */
056: private Exception exception = null;
057: private int exceptionType = 0;
058:
059: /**
060: * Create a new CatalogException.
061: *
062: * @param type The exception type
063: * @param message The error or warning message.
064: */
065: public CatalogException(int type, String message) {
066: super (message);
067: this .exceptionType = type;
068: this .exception = null;
069: }
070:
071: /**
072: * Create a new CatalogException.
073: *
074: * @param type The exception type
075: */
076: public CatalogException(int type) {
077: super ("Catalog Exception " + type);
078: this .exceptionType = type;
079: this .exception = null;
080: }
081:
082: /**
083: * Create a new CatalogException wrapping an existing exception.
084: *
085: * <p>The existing exception will be embedded in the new
086: * one, and its message will become the default message for
087: * the CatalogException.</p>
088: *
089: * @param e The exception to be wrapped in a CatalogException.
090: */
091: public CatalogException(Exception e) {
092: super ();
093: this .exceptionType = WRAPPER;
094: this .exception = e;
095: }
096:
097: /**
098: * Create a new CatalogException from an existing exception.
099: *
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 message, Exception 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 getMessage() {
122: String message = super .getMessage();
123:
124: if (message == null && exception != null) {
125: return exception.getMessage();
126: } else {
127: return message;
128: }
129: }
130:
131: /**
132: * Return the embedded exception, if any.
133: *
134: * @return The embedded exception, or null if there is none.
135: */
136: public Exception getException() {
137: return exception;
138: }
139:
140: /**
141: * Return the exception type
142: *
143: * @return The exception type
144: */
145: public int getExceptionType() {
146: return exceptionType;
147: }
148:
149: /**
150: * Override toString to pick up any embedded exception.
151: *
152: * @return A string representation of this exception.
153: */
154: public String toString() {
155: if (exception != null) {
156: return exception.toString();
157: } else {
158: return super.toString();
159: }
160: }
161: }
|