View Javadoc

1   /**
2    * Copyright (c) 2011, University of Konstanz, Distributed Systems Group
3    * All rights reserved.
4    * 
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    * * Redistributions of source code must retain the above copyright
8    * notice, this list of conditions and the following disclaimer.
9    * * Redistributions in binary form must reproduce the above copyright
10   * notice, this list of conditions and the following disclaimer in the
11   * documentation and/or other materials provided with the distribution.
12   * * Neither the name of the University of Konstanz nor the
13   * names of its contributors may be used to endorse or promote products
14   * derived from this software without specific prior written permission.
15   * 
16   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18   * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19   * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20   * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26   */
27  
28  package org.treetank.service.xml.xpath;
29  
30  /**
31   * <h1>XPathError</h1>
32   * <p>
33   * XPath error as described in <a href="http://www.w3.org/2005/xqt-errors/"> XQuery 1.0 and XPath 2.0 Error
34   * Codes </a>.
35   * </p>
36   * <p>
37   * A static error is an error that must be detected during the static analysis.
38   * </p>
39   * <p>
40   * A dynamic error is an error that must be detected during the dynamic evaluation phase and may be detected
41   * during the static analysis phase.
42   * </p>
43   * <p>
44   * A type error may be raised during the static analysis phase or the dynamic evaluation phase.
45   * </p>
46   * <p>
47   * The errors are identified by QNames that have the form err:XPYYnnnn, where:
48   * <li>err denotes the namespace for XPath and XQuery errors.</li>
49   * <li>XP identifies the error as an XPath error.</li>
50   * <li>YY denotes the error category, using the following encoding: ST denotes a static error. DY denotes a
51   * dynamic error. TY denotes a type error. nnnn is a unique numeric code.</li>
52   */
53  public class XPathError extends RuntimeException {
54  
55      /** . */
56      private static final long serialVersionUID = 1L;
57  
58      /**
59       * Constructor. Initializes the internal state.
60       * 
61       * @param mErr
62       *            The specific error type of the error.
63       */
64      public XPathError(final ErrorType mErr) {
65  
66          super(mErr.getMsg());
67      }
68  
69      /**
70       * {@inheritDoc}
71       */
72      @Override
73      public Throwable fillInStackTrace() {
74          // note: this prevents generation of the stack trace. In case of
75          // debugging
76          // simply comment it out. The application's stack trace should be hidden
77          // from
78          // the user. In addition to that it's generation is costly in time and
79          // space.
80  
81          return this;
82      }
83  
84      /**
85       * Enumeration for all the XPath error types with their specified error
86       * message.
87       * 
88       * @author Tina Scherer
89       */
90      public enum ErrorType {
91  
92              /** XPath static error 0001. */
93              XPST0001("err:XPST0001:  Some component of the static context has not "
94                  + "been assigned a value."),
95  
96              /** XPath dynamic error 0004. */
97              XPDY0002("err:XPDY0002:   Some part of the dynamic context has not " + "been assigned a value."),
98  
99              /** XPath static error 0003. */
100             XPST0003("err:XPST0003: Expression is not a valid instance of the grammar"
101                 + "defined in A.1 EBNF."),
102 
103             /** XPath type error 0004. */
104             XPTY0004("err:XPTY0004 The type is not appropriate the expression or the "
105                 + "typedoes not match a required type as specified by the matching rules."),
106 
107             /** XPath static error 0005. */
108             XPST0005("err:XPST0005:  The static type assigned to an expression other than the "
109                 + "expression() or data(()) is empty-sequence()."),
110 
111             /** XPath static error 0008. */
112             XPST0008("err:XPST0008 Expression refers to a name that is not defined in the "
113                 + "static context"),
114 
115             /** XPath static error 0010. */
116             XPST0010("err:XPST0010: " + "Axis is not supported."),
117 
118             /** XPath static error 0017. */
119             XPST0017("err:XPST0017  The expanded QName and number of arguments in a "
120                 + "function call do not match the name and arity of a function " + "signature."),
121 
122             /** XPath type error 0018. */
123             XPTY0018("err:XPTY0018  Result of the last step "
124                 + "in a path expression contains both nodes and atomic values."),
125 
126             /** XPath type error 0019. */
127             XPTY0019("err:XPTY0019  Result of a step (other "
128                 + "than the last step) in a path expression contains an atomic value."),
129 
130             /** XPath type error 0020. */
131             XPTY0020("err:XPTY0020 Context item in an axis step is not a node."),
132 
133             /** XPath dynamic error 0050. */
134             XPDY0050("err:XPDY0050 " + "Dynamic type of the operand of a treat expression does not match"
135                 + " the sequence type specified by the treat expression."),
136 
137             /** XPath static error 0051. */
138             XPST0051("err:XPST0051 " + "Type is not defined in the in-scope schema types as an "
139                 + "atomic type."),
140 
141             /** XPath static error 0080. */
142             XPST0080("err:XPST0080 " + "Target type of a cast or castable expression must not be "
143                 + "xs:NOTATION or xs:anyAtomicType."),
144 
145             /** XPath static error 0081. */
146             XPST0081("err:XPST0081 " + "Namespace prefix cannot be expanded into a namespace URI by "
147                 + "using the statically known namespaces."),
148 
149             FOCA0001("err:FOCA0001, Input value too large for decimal."),
150             FOCA0002("err:FOCA0002, Invalid lexical value."),
151             FOCA0003("err:FOCA0003, Input value too large for integer."),
152             FOCA0005("err:FOCA0005, NaN supplied as float/double value."),
153             FOCA0006("err:FOCA0006, String to be cast to decimal has too many digits of precision."),
154             FOCH0001("err:FOCH0001, Code point not valid."),
155             FOCH0002("err:FOCH0002, Unsupported collation."),
156             FOCH0003("err:FOCH0003, Unsupported normalization form."),
157             FORH0004("err:FOCH0004, Collation does not support collation units."),
158             FODC0001("err:FODC0001, No context document."),
159             FODC0002("err:FODC0002, Error retrieving resource."),
160             FODC0003("err:FODC0003, Function stability not defined."),
161             FODC0004("err:FODC0004, Invalid argument to fn:collection."),
162             FODC0005("err:FODC0005, Invalid argument to fn:doc or fn:doc-available."),
163             FODT0001("err:FODT0001, Overflow/underflow in date/time operation."),
164             FODT0002("err:FODT0002, Overflow/underflow in duration operation."),
165             FODT0003("err:FODT0003, Invalid timezone value."),
166             FONS0004("err:FONS0004, No namespace found for prefix."),
167             FONS0005("err:FONS0005, Base-uri not defined in the static context."),
168             /**
169              * XQuery and XPath Function and Operators error 0001. This error is
170              * raised whenever an attempt is made to divide by zero.
171              */
172             FOAR0001("err:FOAR0001: Division by zero."),
173             /**
174              * XQuery and XPath Function and Operators error 0002. This error is
175              * raised whenever numeric operations result in an overflow or
176              * underflow.
177              */
178             FOAR0002("err:FOAR0002: Numeric operation overflow/underflow."),
179             FOER0000("err:FOER0000: Unidentified error."),
180             FORG0001("err:FORG0001, Invalid value for cast/constructor."),
181             FORG0002("err:FORG0002, Invalid argument to fn:resolve-uri()."),
182             FORG0003("err:FORG0003, fn:zero-or-one called with a sequence containing more than one item."),
183             FORG0004("err:FORG0004, fn:one-or-more called with a sequence containing no items."),
184             FORG0005(
185                 "err:FORG0005, fn:exactly-one called with a sequence containing zero or more than one item."),
186             /** XQuery and XPath Function and Operators error 0006. */
187             FORG0006("err:FORG0006 Invalid argument type."), FORG0007(""), FORG0008(
188                 "err:FORG0008, Both arguments to fn:dateTime have a specified timezone."), FORG0009(
189                 "err:FORG0009, Error in resolving a relative URI against a base URI in fn:resolve-uri."),
190             FORX0001("err:FORX0001, Invalid regular expression. flags"), FORX0002(
191                 "err:FORX0002, Invalid regular expression."), FORX0003(
192                 "err:FORX0003, Regular expression matches zero-length string."), FORX0004(
193                 "err:FORX0004, Invalid replacement string."), FOTY0012(
194                 "err:FOTY0012, Argument node does not have a typed value."), ;
195 
196         /** error message. */
197         private String message;
198 
199         /**
200          * Constructor. Initializes the internal state.
201          * 
202          * @param msg
203          *            the error message
204          */
205         private ErrorType(final String msg) {
206 
207             message = msg;
208         }
209 
210         /**
211          * Returns the error message of the respective error.
212          * 
213          * @return error message
214          */
215         public String getMsg() {
216 
217             return message;
218         }
219 
220     }
221 
222 }