001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 2001, 2002 The Apache Software Foundation.
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "Xerces" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 1999, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057:
058: package com.sun.xml.stream.xerces.xni.parser;
059:
060: import com.sun.xml.stream.xerces.xni.XMLLocator;
061: import com.sun.xml.stream.xerces.xni.XNIException;
062:
063: /**
064: * A parsing exception. This exception is different from the standard
065: * XNI exception in that it stores the location in the document (or
066: * its entities) where the exception occurred.
067: *
068: * @author Andy Clark, IBM
069: *
070: * @version $Id: XMLParseException.java,v 1.2 2006/04/01 06:01:44 jeffsuttor Exp $
071: */
072: public class XMLParseException extends XNIException {
073:
074: //
075: // Data
076: //
077:
078: /** Public identifier. */
079: protected String fPublicId;
080:
081: /** literal System identifier. */
082: protected String fLiteralSystemId;
083:
084: /** expanded System identifier. */
085: protected String fExpandedSystemId;
086:
087: /** Base system identifier. */
088: protected String fBaseSystemId;
089:
090: /** Line number. */
091: protected int fLineNumber = -1;
092:
093: /** Column number. */
094: protected int fColumnNumber = -1;
095:
096: //
097: // Constructors
098: //
099:
100: /** Constructs a parse exception. */
101: public XMLParseException(XMLLocator locator, String message) {
102: super (message);
103: if (locator != null) {
104: fPublicId = locator.getPublicId();
105: fLiteralSystemId = locator.getLiteralSystemId();
106: fExpandedSystemId = locator.getExpandedSystemId();
107: fBaseSystemId = locator.getBaseSystemId();
108: fLineNumber = locator.getLineNumber();
109: fColumnNumber = locator.getColumnNumber();
110: }
111: } // <init>(XMLLocator,String)
112:
113: /** Constructs a parse exception. */
114: public XMLParseException(XMLLocator locator, String message,
115: Exception exception) {
116: super (message, exception);
117: fPublicId = locator.getPublicId();
118: fLiteralSystemId = locator.getLiteralSystemId();
119: fExpandedSystemId = locator.getExpandedSystemId();
120: fBaseSystemId = locator.getBaseSystemId();
121: fLineNumber = locator.getLineNumber();
122: fColumnNumber = locator.getColumnNumber();
123: } // <init>(XMLLocator,String,Exception)
124:
125: //
126: // Public methods
127: //
128:
129: /** Returns the public identifier. */
130: public String getPublicId() {
131: return fPublicId;
132: } // getPublicId():String
133:
134: /** Returns the expanded system identifier. */
135: public String getExpandedSystemId() {
136: return fExpandedSystemId;
137: } // getExpandedSystemId():String
138:
139: /** Returns the literal system identifier. */
140: public String getLiteralSystemId() {
141: return fLiteralSystemId;
142: } // getLiteralSystemId():String
143:
144: /** Returns the base system identifier. */
145: public String getBaseSystemId() {
146: return fBaseSystemId;
147: } // getBaseSystemId():String
148:
149: /** Returns the line number. */
150: public int getLineNumber() {
151: return fLineNumber;
152: } // getLineNumber():int
153:
154: /** Returns the row number. */
155: public int getColumnNumber() {
156: return fColumnNumber;
157: } // getRowNumber():int
158:
159: //
160: // Object methods
161: //
162:
163: /** Returns a string representation of this object. */
164: public String toString() {
165:
166: StringBuffer str = new StringBuffer();
167: if (fPublicId != null) {
168: str.append(fPublicId);
169: }
170: str.append(':');
171: if (fPublicId != null) {
172: str.append(fPublicId);
173: }
174: str.append(':');
175: if (fLiteralSystemId != null) {
176: str.append(fLiteralSystemId);
177: }
178: str.append(':');
179: if (fExpandedSystemId != null) {
180: str.append(fExpandedSystemId);
181: }
182: str.append(':');
183: if (fBaseSystemId != null) {
184: str.append(fBaseSystemId);
185: }
186: str.append(':');
187: str.append(fLineNumber);
188: str.append(':');
189: str.append(fColumnNumber);
190: str.append(':');
191: String message = getMessage();
192: if (message == null) {
193: Exception exception = getException();
194: if (exception != null) {
195: message = exception.getMessage();
196: }
197: }
198: if (message != null) {
199: str.append(message);
200: }
201: return str.toString();
202:
203: } // toString():String
204:
205: } // XMLParseException
|