Debian Codegraph @

net/sf/saxon/s9api/StaticError.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.s9api;
9
10 import net.sf.saxon.expr.parser.Location;
11 import net.sf.saxon.om.NodeInfo;
12 import net.sf.saxon.trans.XPathException;
13 import net.sf.saxon.tree.util.Navigator;
14
15 import javax.xml.transform.TransformerException;
16
17 /**
18 * The <b>StaticError</b> class contains information about a static error detected during compilation
19 * of a stylesheet, query, or XPath expression.
20 */
21 public class StaticError {
22
23 XPathException exception;
24 Location locator = null;
25 boolean isWarning = false;
26
27
28 public StaticError(TransformerException err, boolean isWarning){
29 exception = XPathException.makeXPathException(err);
30 locator = exception.getLocator();
31 this.isWarning = isWarning;
32 }
33
34 public StaticError(TransformerException err){
35 exception = XPathException.makeXPathException(err);
36 locator = exception.getLocator();
37
38 }
39
40 public void setWarning(boolean warning) {
41 isWarning = warning;
42 }
43
44 /**
45 * The error code, as a QName. May be null if no error code has been assigned
46 *
47 * @return QName
48 */
49 public QName getErrorCode(){
50 return new QName(exception.getErrorCodeQName());
51 }
52
53
54 /**
55 * Return the error message associated with this error
56 * @return String
57 */
58 public String getMessage(){
59 return exception.getMessage();
60 }
61
62 /**
63 * The URI of the query or stylesheet module in which the error was detected (as a string)
64 * May be null if the location of the error is unknown, or if the error is not localized
65 * to a specific module, or if the module in question has no known URI (for example, if
66 * it was supplied as an anonymous Stream)
67 *
68 * @return String
69 */
70 public String getModuleUri(){
71 return exception.getLocator().getSystemId();
72 }
73
74
75 /**
76 * The coloumn number locating the error within a query or stylesheet module
77 *
78 * @return int
79 */
80 public int getColumnNumber() {
81 Location locator = exception.getLocator();
82 if (locator != null) {
83 return locator.getColumnNumber();
84 }
85 return -1;
86 }
87
88 /**
89 * The line number locating the error within a query or stylesheet module
90 *
91 * @return int
92 */
93 public int getLineNumber(){
94 Location locator = exception.getLocator();
95 if (locator != null){
96 return locator.getLineNumber();
97 }
98 return -1;
99 }
100
101
102 /**
103 * Get a name identifying the kind of instruction, in terms meaningful to a user. This method
104 * is not used in the case where the instruction name code is a standard name (&lt;1024).
105 *
106 * @return a name identifying the kind of instruction, in terms meaningful to a user.
107 * The name will always be in the form of a lexical XML QName, and should match the name used
108 * in explain() output displaying the instruction.
109 */
110 public String getInstructionName(){
111 return ((NodeInfo)locator).getDisplayName();
112 }
113
114
115 /**
116 * Indicate whether this error is being reported as a warning condition.
117 * If so, applications may ignore the condition, though the results may not be as intended.
118 * @return boolean
119 */
120 public boolean isWarning(){
121 return isWarning;
122 }
123
124
125 /**
126 * Indicate whether this condition is a type error.
127 * @return boolean
128 */
129 public boolean isTypeError(){
130 return exception.isTypeError();
131 }
132
133
134 /**
135 * Get the absolute XPath expression that identifies the node within its document
136 * where the error occurred, if available
137 *
138 * @return String - a path expression
139 */
140 public String getPath(){
141 NodeInfo node = null;
142
143 if (locator instanceof NodeInfo) {
144 node = (NodeInfo) locator;
145 return Navigator.getPath(node);
146 }
147 return null;
148 }
149
150 /**
151 * Return the underlying exception. This method may not be stable across Saxon releases.
152 *
153 * @return XPathException the underlying exception
154 */
155 public XPathException getUnderlyingException(){
156 return exception;
157 }
158
159 }