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.model.io;
20
21 import java.io.IOException;
22
23 /**
24 * Signals a failure to parse the POM due to invalid syntax (e.g. non-wellformed XML or unknown elements).
25 *
26 * @author Benjamin Bentmann
27 */
28 public class ModelParseException extends IOException {
29
30 /**
31 * The one-based index of the line containing the error.
32 */
33 private final int lineNumber;
34
35 /**
36 * The one-based index of the column containing the error.
37 */
38 private final int columnNumber;
39
40 /**
41 * Creates a new parser exception with the specified details.
42 *
43 * @param message The error message, may be {@code null}.
44 * @param lineNumber The one-based index of the line containing the error or {@code -1} if unknown.
45 * @param columnNumber The one-based index of the column containing the error or {@code -1} if unknown.
46 */
47 public ModelParseException(String message, int lineNumber, int columnNumber) {
48 super(message);
49 this.lineNumber = lineNumber;
50 this.columnNumber = columnNumber;
51 }
52
53 /**
54 * Creates a new parser exception with the specified details.
55 *
56 * @param message The error message, may be {@code null}.
57 * @param lineNumber The one-based index of the line containing the error or {@code -1} if unknown.
58 * @param columnNumber The one-based index of the column containing the error or {@code -1} if unknown.
59 * @param cause The nested cause of this error, may be {@code null}.
60 */
61 public ModelParseException(String message, int lineNumber, int columnNumber, Throwable cause) {
62 super(message);
63 initCause(cause);
64 this.lineNumber = lineNumber;
65 this.columnNumber = columnNumber;
66 }
67
68 /**
69 * Gets the one-based index of the line containing the error.
70 *
71 * @return The one-based index of the line containing the error or a non-positive value if unknown.
72 */
73 public int getLineNumber() {
74 return lineNumber;
75 }
76
77 /**
78 * Gets the one-based index of the column containing the error.
79 *
80 * @return The one-based index of the column containing the error or non-positive value if unknown.
81 */
82 public int getColumnNumber() {
83 return columnNumber;
84 }
85 }