1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package gov.nist.secauto.metaschema.core.metapath;
7   
8   import edu.umd.cs.findbugs.annotations.NonNull;
9   import edu.umd.cs.findbugs.annotations.Nullable;
10  
11  /**
12   * MPST: Exceptions related to the Metapath static context and static
13   * evaluation.
14   */
15  // TODO: review use of this exception
16  // TODO: include a reference to the Metapath expression?
17  // TODO: Move this to a StaticMetapathException that extends this class; align
18  // signatures with DynamicMetapathError
19  @SuppressWarnings("PMD.DataClass")
20  public class StaticMetapathException
21      extends MetapathException {
22    @NonNull
23    private static final String PREFIX = "MPST";
24    /**
25     * <a href= "https://www.w3.org/TR/xpath-31/#ERRXPST0003">err:MPST0003</a>: It
26     * is a <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static
27     * error</a> if an expression is not a valid instance of the Metapath grammar.
28     */
29    // TODO: need a Metapath grammar link
30    protected static final int INVALID_PATH_GRAMMAR = 3;
31  
32    /**
33     * <a href= "https://www.w3.org/TR/xpath-31/#ERRXPST0008">err:MPST0008</a>: It
34     * is a <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static
35     * error</a> if an expression refers to an element name, attribute name, schema
36     * type name, namespace prefix, or variable name that is not defined in the
37     * <a href="https://www.w3.org/TR/xpath-31/#dt-static-context">static
38     * context</a>, except for an ElementName in an <a href=
39     * "https://www.w3.org/TR/xpath-31/#doc-xpath31-ElementTest">ElementTest</a> or
40     * an AttributeName in an <a href=
41     * "https://www.w3.org/TR/xpath-31/#doc-xpath31-AttributeTest">AttributeTest</a>.
42     */
43    public static final int NOT_DEFINED = 8;
44    /**
45     * <a href= "https://www.w3.org/TR/xpath-31/#ERRXPST0010">err:MPST0010</a>: An
46     * implementation that does not support the namespace axis must raise a
47     * <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static error</a> if
48     * it encounters a reference to the namespace axis and XPath 1.0 compatibility
49     * mode is false.
50     */
51    public static final int AXIS_NAMESPACE_UNSUPPORTED = 10;
52  
53    /**
54     * <a href= "https://www.w3.org/TR/xpath-31/#ERRXPST0017">err:MPST0017</a>: It
55     * is a <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static
56     * error</a> if the
57     * <a href="https://www.w3.org/TR/xpath-31/#dt-expanded-qname">expanded
58     * QName</a> and number of arguments in a static function call do not match the
59     * name and arity of a
60     * <a href="https://www.w3.org/TR/xpath-31/#dt-known-func-signatures">function
61     * signature</a> in the
62     * <a href="https://www.w3.org/TR/xpath-31/#dt-static-context">static
63     * context</a>.
64     */
65    public static final int NO_FUNCTION_MATCH = 17;
66  
67    /**
68     * <a href= "https://www.w3.org/TR/xpath-31/#ERRXPST0051">err:MPST0051</a>: It
69     * is a static error if the
70     * <a href="https://www.w3.org/TR/xpath-31/#dt-expanded-qname">expanded
71     * QName</a> for an AtomicOrUnionType in a SequenceType is not defined in the
72     * <a href="https://www.w3.org/TR/xpath-31/#dt-is-types">in-scope schema
73     * types</a> as a <a href=
74     * "https://www.w3.org/TR/xpath-31/#dt-generalized-atomic-type">generalized
75     * atomic type</a>.
76     */
77    public static final int UNKNOWN_TYPE = 51;
78  
79    /**
80     * <a href= "https://www.w3.org/TR/xpath-31/#ERRXQST0052">err:MQST0052</a>: The
81     * type named in a cast or castable expression must be the name of a type
82     * defined in the <a href="https://www.w3.org/TR/xpath-31/#dt-is-types">in-scope
83     * schema types</a>, and the type must be simple.
84     */
85    public static final int CAST_UNKNOWN_TYPE = 52;
86  
87    /**
88     * <a href= "https://www.w3.org/TR/xpath-31/#ERRXQST0070">err:MQST0070</a>: A
89     * <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static error</a> is
90     * raised if any of the following conditions is statically detected in any
91     * expression.
92     * <ul>
93     * <li>The prefix xml is bound to some namespace URI other than
94     * http://www.w3.org/XML/1998/namespace.
95     * <li>A prefix other than xml is bound to the namespace URI
96     * http://www.w3.org/XML/1998/namespace.
97     * <li>The prefix xmlns is bound to any namespace URI.
98     * <li>A prefix other than xmlns is bound to the namespace URI
99     * http://www.w3.org/2000/xmlns/.
100    * </ul>
101    */
102   public static final int NAMESPACE_MISUSE = 70;
103 
104   /**
105    * <a href= "https://www.w3.org/TR/xpath-31/#ERRXPST0080">err:MPST0080</a>: It
106    * is a <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static
107    * error</a> if the target type of a cast or castable expression is
108    * meta:anyAtomicType.
109    */
110   public static final int CAST_ANY_ATOMIC = 80;
111 
112   /**
113    * <a href= "https://www.w3.org/TR/xpath-31/#ERRXQST0070">err:MPST0070</a>: It
114    * is a <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static
115    * error</a> if a QName used in an expression contains a namespace prefix that
116    * cannot be expanded into a namespace URI by using the
117    * <a href="https://www.w3.org/TR/xpath-31/#dt-static-namespaces">statically
118    * known namespaces</a>.
119    */
120   public static final int PREFIX_NOT_EXPANDABLE = 81;
121 
122   /**
123    * <a href= "https://www.w3.org/TR/xpath-31/#ERRXQST0134">err:MPST0134</a>: The
124    * namespace axis is not supported.
125    */
126   public static final int AXIS_NAMESPACE_UNSUPPORTED_IN_TEST = 134;
127 
128   /**
129    * the serial version UID.
130    */
131   private static final long serialVersionUID = 2L;
132 
133   /**
134    * Constructs a new exception with the provided {@code code}, {@code message},
135    * and {@code cause}.
136    *
137    * @param code
138    *          the error code value
139    * @param message
140    *          the exception message
141    * @param cause
142    *          the original exception cause
143    */
144   public StaticMetapathException(
145       int code,
146       @Nullable String message,
147       @Nullable Throwable cause) {
148     super(IErrorCode.of(PREFIX, code), message, cause);
149   }
150 
151   /**
152    * Constructs a new exception with the provided {@code code}, {@code message},
153    * and no cause.
154    *
155    * @param code
156    *          the error code value
157    * @param message
158    *          the exception message
159    */
160   public StaticMetapathException(
161       int code,
162       @Nullable String message) {
163     super(IErrorCode.of(PREFIX, code), message, null);
164   }
165 
166   /**
167    * Constructs a new exception with the provided {@code code}, no message, and
168    * the {@code cause}.
169    *
170    * @param code
171    *          the error code value
172    * @param cause
173    *          the original exception cause
174    */
175   public StaticMetapathException(
176       int code,
177       @Nullable Throwable cause) {
178     super(IErrorCode.of(PREFIX, code), null, cause);
179   }
180 }