KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > xni > parser > XMLParseException


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

16
17 package org.apache.xerces.xni.parser;
18
19 import org.apache.xerces.xni.XMLLocator;
20 import org.apache.xerces.xni.XNIException;
21
22 /**
23  * A parsing exception. This exception is different from the standard
24  * XNI exception in that it stores the location in the document (or
25  * its entities) where the exception occurred.
26  *
27  * @author Andy Clark, IBM
28  *
29  * @version $Id: XMLParseException.java,v 1.8 2004/09/02 03:53:53 mrglavas Exp $
30  */

31 public class XMLParseException
32     extends XNIException {
33
34     /** Serialization version. */
35     static final long serialVersionUID = 1732959359448549967L;
36     
37     //
38
// Data
39
//
40

41     /** Public identifier. */
42     protected String JavaDoc fPublicId;
43
44     /** literal System identifier. */
45     protected String JavaDoc fLiteralSystemId;
46
47     /** expanded System identifier. */
48     protected String JavaDoc fExpandedSystemId;
49
50     /** Base system identifier. */
51     protected String JavaDoc fBaseSystemId;
52
53     /** Line number. */
54     protected int fLineNumber = -1;
55     
56     /** Column number. */
57     protected int fColumnNumber = -1;
58     
59     /** Character offset. */
60     protected int fCharacterOffset = -1;
61
62     //
63
// Constructors
64
//
65

66     /** Constructs a parse exception. */
67     public XMLParseException(XMLLocator locator, String JavaDoc message) {
68         super(message);
69         if (locator != null) {
70             fPublicId = locator.getPublicId();
71             fLiteralSystemId = locator.getLiteralSystemId();
72             fExpandedSystemId = locator.getExpandedSystemId();
73             fBaseSystemId = locator.getBaseSystemId();
74             fLineNumber = locator.getLineNumber();
75             fColumnNumber = locator.getColumnNumber();
76             fCharacterOffset = locator.getCharacterOffset();
77         }
78     } // <init>(XMLLocator,String)
79

80     /** Constructs a parse exception. */
81     public XMLParseException(XMLLocator locator,
82                              String JavaDoc message, Exception JavaDoc exception) {
83         super(message, exception);
84         if (locator != null) {
85             fPublicId = locator.getPublicId();
86             fLiteralSystemId = locator.getLiteralSystemId();
87             fExpandedSystemId = locator.getExpandedSystemId();
88             fBaseSystemId = locator.getBaseSystemId();
89             fLineNumber = locator.getLineNumber();
90             fColumnNumber = locator.getColumnNumber();
91             fCharacterOffset = locator.getCharacterOffset();
92         }
93     } // <init>(XMLLocator,String,Exception)
94

95     //
96
// Public methods
97
//
98

99     /** Returns the public identifier. */
100     public String JavaDoc getPublicId() {
101         return fPublicId;
102     } // getPublicId():String
103

104     /** Returns the expanded system identifier. */
105     public String JavaDoc getExpandedSystemId() {
106         return fExpandedSystemId;
107     } // getExpandedSystemId():String
108

109     /** Returns the literal system identifier. */
110     public String JavaDoc getLiteralSystemId() {
111         return fLiteralSystemId;
112     } // getLiteralSystemId():String
113

114     /** Returns the base system identifier. */
115     public String JavaDoc getBaseSystemId() {
116         return fBaseSystemId;
117     } // getBaseSystemId():String
118

119     /** Returns the line number. */
120     public int getLineNumber() {
121         return fLineNumber;
122     } // getLineNumber():int
123

124     /** Returns the row number. */
125     public int getColumnNumber() {
126         return fColumnNumber;
127     } // getRowNumber():int
128

129     /** Returns the character offset. */
130     public int getCharacterOffset() {
131         return fCharacterOffset;
132     } // getCharacterOffset():int
133

134     //
135
// Object methods
136
//
137

138     /** Returns a string representation of this object. */
139     public String JavaDoc toString() {
140
141         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
142         if (fPublicId != null) {
143             str.append(fPublicId);
144         }
145         str.append(':');
146         if (fLiteralSystemId != null) {
147             str.append(fLiteralSystemId);
148         }
149         str.append(':');
150         if (fExpandedSystemId != null) {
151             str.append(fExpandedSystemId);
152         }
153         str.append(':');
154         if (fBaseSystemId != null) {
155             str.append(fBaseSystemId);
156         }
157         str.append(':');
158         str.append(fLineNumber);
159         str.append(':');
160         str.append(fColumnNumber);
161         str.append(':');
162         str.append(fCharacterOffset);
163         str.append(':');
164         String JavaDoc message = getMessage();
165         if (message == null) {
166             Exception JavaDoc exception = getException();
167             if (exception != null) {
168                 message = exception.getMessage();
169             }
170         }
171         if (message != null) {
172             str.append(message);
173         }
174         return str.toString();
175
176     } // toString():String
177

178 } // XMLParseException
179
Popular Tags