001: /* Copyright 2000 - 2001 Quadcap Software. All rights reserved.
002: *
003: * This software is distributed under the Quadcap Free Software License.
004: * This software may be used or modified for any purpose, personal or
005: * commercial. Open Source redistributions are permitted. Commercial
006: * redistribution of larger works derived from, or works which bundle
007: * this software requires a "Commercial Redistribution License"; see
008: * http://www.quadcap.com/purchase.
009: *
010: * Redistributions qualify as "Open Source" under one of the following terms:
011: *
012: * Redistributions are made at no charge beyond the reasonable cost of
013: * materials and delivery.
014: *
015: * Redistributions are accompanied by a copy of the Source Code or by an
016: * irrevocable offer to provide a copy of the Source Code for up to three
017: * years at the cost of materials and delivery. Such redistributions
018: * must allow further use, modification, and redistribution of the Source
019: * Code under substantially the same terms as this license.
020: *
021: * Redistributions of source code must retain the copyright notices as they
022: * appear in each source code file, these license terms, and the
023: * disclaimer/limitation of liability set forth as paragraph 6 below.
024: *
025: * Redistributions in binary form must reproduce this Copyright Notice,
026: * these license terms, and the disclaimer/limitation of liability set
027: * forth as paragraph 6 below, in the documentation and/or other materials
028: * provided with the distribution.
029: *
030: * The Software is provided on an "AS IS" basis. No warranty is
031: * provided that the Software is free of defects, or fit for a
032: * particular purpose.
033: *
034: * Limitation of Liability. Quadcap Software shall not be liable
035: * for any damages suffered by the Licensee or any third party resulting
036: * from use of the Software.
037: */
038:
039: // SAX exception class.
040: // No warranty; no copyright -- use this as you will.
041: // $Id: SAXException.java,v 1.3 2001/01/06 06:11:03 stan Exp $
042: package org.xml.sax;
043:
044: /**
045: * Encapsulate a general SAX error or warning.
046: *
047: * <p>This class can contain basic error or warning information from
048: * either the XML parser or the application: a parser writer or
049: * application writer can subclass it to provide additional
050: * functionality. SAX handlers may throw this exception or
051: * any exception subclassed from it.</p>
052: *
053: * <p>If the application needs to pass through other types of
054: * exceptions, it must wrap those exceptions in a SAXException
055: * or an exception derived from a SAXException.</p>
056: *
057: * <p>If the parser or application needs to include information about a
058: * specific location in an XML document, it should use the
059: * SAXParseException subclass.</p>
060: *
061: * @author David Megginson (ak117@freenet.carleton.ca)
062: * @version 1.0
063: * @see org.xml.sax.SAXParseException
064: */
065: public class SAXException extends Exception {
066:
067: /**
068: * Create a new SAXException.
069: *
070: * @param message The error or warning message.
071: * @see org.xml.sax.Parser#setLocale
072: */
073: public SAXException(String message) {
074: super ();
075: this .message = message;
076: this .exception = null;
077: }
078:
079: /**
080: * Create a new SAXException wrapping an existing exception.
081: *
082: * <p>The existing exception will be embedded in the new
083: * one, and its message will become the default message for
084: * the SAXException.</p>
085: *
086: * @param e The exception to be wrapped in a SAXException.
087: */
088: public SAXException(Exception e) {
089: super ();
090: this .message = null;
091: this .exception = e;
092: }
093:
094: /**
095: * Create a new SAXException from an existing exception.
096: *
097: * <p>The existing exception will be embedded in the new
098: * one, but the new exception will have its own message.</p>
099: *
100: * @param message The detail message.
101: * @param e The exception to be wrapped in a SAXException.
102: * @see org.xml.sax.Parser#setLocale
103: */
104: public SAXException(String message, Exception e) {
105: super ();
106: this .message = message;
107: this .exception = e;
108: }
109:
110: /**
111: * Return a detail message for this exception.
112: *
113: * <p>If there is a embedded exception, and if the SAXException
114: * has no detail message of its own, this method will return
115: * the detail message from the embedded exception.</p>
116: *
117: * @return The error or warning message.
118: * @see org.xml.sax.Parser#setLocale
119: */
120: public String getMessage() {
121: if (message == null && exception != null) {
122: return exception.getMessage();
123: } else {
124: return this .message;
125: }
126: }
127:
128: /**
129: * Return the embedded exception, if any.
130: *
131: * @return The embedded exception, or null if there is none.
132: */
133: public Exception getException() {
134: return exception;
135: }
136:
137: /**
138: * Convert this exception to a string.
139: *
140: * @return A string version of this exception.
141: */
142: public String toString() {
143: return getMessage();
144: }
145:
146: //////////////////////////////////////////////////////////////////////
147: // Internal state.
148: //////////////////////////////////////////////////////////////////////
149:
150: private String message;
151: private Exception exception;
152:
153: }
|