001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with 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,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.maven.doxia.parser;
020
021/**
022 * Encapsulate a Doxia parse error.
023 *
024 * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
025 * @since 1.0
026 */
027public class ParseException extends Exception {
028    /** serialVersionUID */
029    static final long serialVersionUID = 295967936746221567L;
030
031    /** The file that caused the ParseException. */
032    private String fileName;
033
034    /** Line number where the parse exception occurred. */
035    private int lineNumber;
036
037    /** Column number where the parse exception occurred. */
038    private int columnNumber;
039
040    /**
041     * Construct a new <code>ParseException</code> with the specified cause.
042     * <br>
043     * <b>Note</b>: no line or column number will be used.
044     *
045     * @param e the cause. This can be retrieved later by the <code>Throwable.getCause()</code> method.
046     * (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
047     */
048    public ParseException(Exception e) {
049        this(null, e, null, -1, -1);
050    }
051
052    /**
053     * Construct a new <code>ParseException</code> with the specified detail message.
054     * <br>
055     * <b>Note</b>: no line or column number will be used.
056     *
057     * @param message The detailed message.
058     * This can later be retrieved by the <code>Throwable.getMessage()</code> method.
059     */
060    public ParseException(String message) {
061        this(message, null, null, -1, -1);
062    }
063
064    /**
065     * Construct a new <code>ParseException</code> with the specified detail message and cause.
066     * <br>
067     * <b>Note</b>: no line or column number will be used.
068     *
069     * @param message The detailed message.
070     * This can later be retrieved by the <code>Throwable.getMessage()</code> method.
071     * @param e the cause. This can be retrieved later by the <code>Throwable.getCause()</code> method.
072     * (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
073     */
074    public ParseException(String message, Exception e) {
075        this(message, e, null, -1, -1);
076    }
077
078    /**
079     * Construct a new <code>ParseException</code> with the specified detail message,
080     * line number and column number.
081     *
082     * @param message The detailed message.
083     * This can later be retrieved by the <code>Throwable.getMessage()</code> method.
084     * @param line The line number where the parsing failed.
085     * This can later be retrieved by the getLineNumber() method.
086     * @param column The column number where the parsing failed.
087     * This can later be retrieved by the getColumnNumber() method.
088     * @since 1.1
089     */
090    public ParseException(String message, int line, int column) {
091        this(message, null, null, line, column);
092    }
093
094    /**
095     * Construct a new <code>ParseException</code> with the specified detail message and cause,
096     * line number and column number.
097     *
098     * @param message The detailed message.
099     * This can later be retrieved by the <code>Throwable.getMessage()</code> method.
100     * @param e the cause. This can be retrieved later by the <code>Throwable.getCause()</code> method.
101     * (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
102     * @param line The line number where the parsing failed.
103     * This can later be retrieved by the getLineNumber() method.
104     * @param column The column number where the parsing failed.
105     * This can later be retrieved by the getColumnNumber() method.
106     * @since 1.1
107     */
108    public ParseException(String message, Exception e, int line, int column) {
109        this(message, e, null, line, column);
110    }
111
112    /**
113     * Constructs a new exception with the specified cause, line number and column number. The error message is
114     *  (cause == null ? null : cause.toString()).
115     *
116     * @param e the cause. This can be retrieved later by the <code>Throwable.getCause()</code> method.
117     * (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
118     * @param line The line number where the parsing failed.
119     * This can later be retrieved by the getLineNumber() method.
120     * @param column The column number where the parsing failed.
121     * This can later be retrieved by the getColumnNumber() method.
122     * @since 1.1
123     */
124    public ParseException(Exception e, int line, int column) {
125        this(null, e, null, line, column);
126    }
127
128    /**
129     * Construct a new <code>ParseException</code> with the specified cause,
130     * filename, line number and column number.
131     *
132     * @param e the cause. This can be retrieved later by the <code>Throwable.getCause()</code> method.
133     * (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
134     * @param file Name of a file that couldn't be parsed.
135     * This can later be retrieved by the getFileName() method.
136     * @param line The line number where the parsing failed.
137     * This can later be retrieved by the getLineNumber() method.
138     * @param column The column number where the parsing failed.
139     * This can later be retrieved by the getColumnNumber() method.
140     */
141    public ParseException(Exception e, String file, int line, int column) {
142        this(null, e, file, line, column);
143    }
144
145    /**
146     * Construct a new <code>ParseException</code> with the specified cause, detail message,
147     * filename, line number and column number.
148     * @param message The detailed message.
149     * This can later be retrieved by the <code>Throwable.getMessage()</code> method.
150     * @param e the cause. This can be retrieved later by the <code>Throwable.getCause()</code> method.
151     * (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
152     * @param file Name of a file that couldn't be parsed.
153     * This can later be retrieved by the getFileName() method.
154     * @param line The line number where the parsing failed.
155     * This can later be retrieved by the getLineNumber() method.
156     * @param column The column number where the parsing failed.
157     * This can later be retrieved by the getColumnNumber() method.
158     *
159     * @since 1.1
160     */
161    public ParseException(String message, Exception e, String file, int line, int column) {
162        super(message, e);
163
164        this.fileName = file;
165        this.lineNumber = line;
166        this.columnNumber = column;
167    }
168
169    /**
170     * <p>Getter for the field <code>fileName</code>.</p>
171     *
172     * @return the file name that caused the <code>ParseException</code>.
173     */
174    public String getFileName() {
175        return fileName;
176    }
177
178    /**
179     * <p>Getter for the field <code>lineNumber</code>.</p>
180     *
181     * @return the line number where the <code>ParseException</code> occurred.
182     */
183    public int getLineNumber() {
184        return lineNumber;
185    }
186
187    /**
188     * <p>Getter for the field <code>columnNumber</code>.</p>
189     *
190     * @return the column number where the <code>ParseException</code> occurred.
191     * @since 1.1
192     */
193    public int getColumnNumber() {
194        return columnNumber;
195    }
196}