001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.css.parser;
020:
021: /**
022: * This class encapsulates a general parse error or warning.
023: *
024: * <p>This class can contain basic error or warning information from
025: * either the parser or the application.
026: *
027: * <p>If the application needs to pass through other types of
028: * exceptions, it must wrap those exceptions in a ParseException.
029: *
030: * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
031: * @version $Id: ParseException.java 475685 2006-11-16 11:16:05Z cam $
032: */
033: public class ParseException extends RuntimeException {
034:
035: /**
036: * @serial The embedded exception if tunnelling, or null.
037: */
038: protected Exception exception;
039:
040: /**
041: * @serial The line number.
042: */
043: protected int lineNumber;
044:
045: /**
046: * @serial The column number.
047: */
048: protected int columnNumber;
049:
050: /**
051: * Creates a new ParseException.
052: * @param message The error or warning message.
053: * @param line The line of the last parsed character.
054: * @param column The column of the last parsed character.
055: */
056: public ParseException(String message, int line, int column) {
057: super (message);
058: exception = null;
059: lineNumber = line;
060: columnNumber = column;
061: }
062:
063: /**
064: * Creates a new ParseException wrapping an existing exception.
065: *
066: * <p>The existing exception will be embedded in the new
067: * one, and its message will become the default message for
068: * the ParseException.
069: * @param e The exception to be wrapped in a ParseException.
070: */
071: public ParseException(Exception e) {
072: exception = e;
073: lineNumber = -1;
074: columnNumber = -1;
075: }
076:
077: /**
078: * Creates a new ParseException from an existing exception.
079: *
080: * <p>The existing exception will be embedded in the new
081: * one, but the new exception will have its own message.
082: * @param message The detail message.
083: * @param e The exception to be wrapped in a SAXException.
084: */
085: public ParseException(String message, Exception e) {
086: super (message);
087: this .exception = e;
088: }
089:
090: /**
091: * Return a detail message for this exception.
092: *
093: * <p>If there is a embedded exception, and if the ParseException
094: * has no detail message of its own, this method will return
095: * the detail message from the embedded exception.
096: * @return The error or warning message.
097: */
098: public String getMessage() {
099: String message = super .getMessage();
100:
101: if (message == null && exception != null) {
102: return exception.getMessage();
103: } else {
104: return message;
105: }
106: }
107:
108: /**
109: * Return the embedded exception, if any.
110: * @return The embedded exception, or null if there is none.
111: */
112: public Exception getException() {
113: return exception;
114: }
115:
116: /**
117: * Returns the line of the last parsed character.
118: */
119: public int getLineNumber() {
120: return lineNumber;
121: }
122:
123: /**
124: * Returns the column of the last parsed character.
125: */
126: public int getColumnNumber() {
127: return columnNumber;
128: }
129: }
|