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