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