Populate data/ hierarchy
[yangtools.git] / data / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / leafref / LeafRefYangSyntaxErrorException.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.data.impl.leafref;
9
10 import static java.util.Objects.requireNonNull;
11
12 public class LeafRefYangSyntaxErrorException extends Exception {
13     private static final long serialVersionUID = 1L;
14     private final String module;
15     private final int line;
16     private final int charPositionInLine;
17
18     public LeafRefYangSyntaxErrorException(final String module, final int line, final int charPositionInLine,
19             final String message) {
20         this(module, line, charPositionInLine, message, null);
21     }
22
23     public LeafRefYangSyntaxErrorException(final String module, final int line, final int charPositionInLine,
24             final String message, final Throwable cause) {
25         super(requireNonNull(message), cause);
26         this.module = module;
27         this.line = line;
28         this.charPositionInLine = charPositionInLine;
29     }
30
31     public String getModule() {
32         return module;
33     }
34
35     public int getLine() {
36         return line;
37     }
38
39     public int getCharPositionInLine() {
40         return charPositionInLine;
41     }
42
43     public String getFormattedMessage() {
44         final StringBuilder sb = new StringBuilder(getMessage());
45         if (module != null) {
46             sb.append(" in module ");
47             sb.append(module);
48         }
49         if (line != 0) {
50             sb.append(" on line ");
51             sb.append(line);
52             if (charPositionInLine != 0) {
53                 sb.append(" character ");
54                 sb.append(charPositionInLine);
55             }
56         }
57         return sb.toString();
58     }
59
60     @Override
61     public String toString() {
62         return this.getClass().getName() + ": " + getFormattedMessage();
63     }
64 }