1 package org.apache.maven.doxia.parser;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 /**
23 * Encapsulate a Doxia parse error.
24 *
25 * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
26 * @version $Id$
27 * @since 1.0
28 */
29 public class ParseException
30 extends Exception
31 {
32 /** serialVersionUID */
33 static final long serialVersionUID = 295967936746221567L;
34
35 /** The file that caused the ParseException. */
36 private String fileName;
37
38 /** Line number where the parse exception occurred. */
39 private int lineNumber;
40
41 /** Column number where the parse exception occurred. */
42 private int columnNumber;
43
44 /**
45 * Construct a new <code>ParseException</code> with the specified detail message.
46 * <br/>
47 * <b>Note</b>: no line or column number will be used.
48 *
49 * @param message The detailed message.
50 * This can later be retrieved by the <code>Throwable.getMessage()</code> method.
51 */
52 public ParseException( String message )
53 {
54 this( null, message, null, -1, -1 );
55 }
56
57 /**
58 * Construct a new <code>ParseException</code> with the specified detail message and cause.
59 * <br/>
60 * <b>Note</b>: no line or column number will be used.
61 *
62 * @param message The detailed message.
63 * This can later be retrieved by the <code>Throwable.getMessage()</code> method.
64 * @param e the cause. This can be retrieved later by the <code>Throwable.getCause()</code> method.
65 * (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
66 */
67 public ParseException( String message, Exception e )
68 {
69 this( e, message, null, -1, -1 );
70 }
71
72 /**
73 * Construct a new <code>ParseException</code> with the specified detail message,
74 * line number and column number.
75 *
76 * @param message The detailed message.
77 * This can later be retrieved by the <code>Throwable.getMessage()</code> method.
78 * @param line The line number where the parsing failed.
79 * This can later be retrieved by the getLineNumber() method.
80 * @param column The column number where the parsing failed.
81 * This can later be retrieved by the getColumnNumber() method.
82 * @since 1.1
83 */
84 public ParseException( String message, int line, int column )
85 {
86 this( null, message, null, line, column );
87 }
88
89 /**
90 * Construct a new <code>ParseException</code> with the specified detail message and cause,
91 * line number and column number.
92 *
93 * @param message The detailed message.
94 * This can later be retrieved by the <code>Throwable.getMessage()</code> method.
95 * @param e the cause. This can be retrieved later by the <code>Throwable.getCause()</code> method.
96 * (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
97 * @param line The line number where the parsing failed.
98 * This can later be retrieved by the getLineNumber() method.
99 * @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 }