1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package dev.metaschema.core.metapath.function.regex;
7   
8   import dev.metaschema.core.metapath.IErrorCode;
9   import dev.metaschema.core.metapath.MetapathException;
10  import edu.umd.cs.findbugs.annotations.NonNull;
11  import edu.umd.cs.findbugs.annotations.Nullable;
12  
13  /**
14   * MPRX: Exceptions related to regular expression processing in Metapath
15   * functions.
16   */
17  public class RegularExpressionMetapathException
18      extends MetapathException {
19    @NonNull
20    private static final String PREFIX = "MPRX";
21    /**
22     * the serial version UID.
23     */
24    private static final long serialVersionUID = 1L;
25    /**
26     * <a href=
27     * "https://www.w3.org/TR/xpath-functions-31/#ERRFORX0001">err:MPRX0001</a>:
28     * Raised by regular expression functions such as <a href=
29     * "https://www.w3.org/TR/xpath-functions-31/#func-matches">fn:matches</a> and
30     * <a href=
31     * "https://www.w3.org/TR/xpath-functions-31/#func-replace">fn:replace</a> if
32     * the regular expression flags contain a character other than i, m, q, s, or x.
33     */
34    public static final int INVALID_FLAG = 1;
35    /**
36     * <a href=
37     * "https://www.w3.org/TR/xpath-functions-31/#ERRFORX0002">err:MPRX0002</a>:
38     * Raised by regular expression functions such as <a href=
39     * "https://www.w3.org/TR/xpath-functions-31/#func-matches">fn:matches</a> and
40     * <a href=
41     * "https://www.w3.org/TR/xpath-functions-31/#func-replace">fn:replace</a> if
42     * the regular expression is syntactically invalid.
43     */
44    public static final int INVALID_EXPRESSION = 2;
45    /**
46     * <a href=
47     * "https://www.w3.org/TR/xpath-functions-31/#ERRFORX0003">err:MPRX0003</a>: For
48     * functions such as <a href=
49     * "https://www.w3.org/TR/xpath-functions-31/#func-replace">fn:replace</a> and
50     * <a href=
51     * "https://www.w3.org/TR/xpath-functions-31/#func-tokenize">fn:tokenize</a>,
52     * raises an error if the supplied regular expression is capable of matching a
53     * zero length string.
54     */
55    public static final int MATCHES_ZERO_LENGTH_STRING = 3;
56    /**
57     * <a href=
58     * "https://www.w3.org/TR/xpath-functions-31/#ERRFORX0004">err:MPRX0004</a>:
59     * Raised by <a href=
60     * "https://www.w3.org/TR/xpath-functions-31/#func-replace">fn:replace</a> to
61     * report errors in the replacement string.
62     */
63    public static final int INVALID_REPLACEMENT_STRING = 4;
64  
65    /**
66     * Constructs a new exception with the provided {@code code}, {@code message},
67     * and {@code cause}.
68     *
69     * @param code
70     *          the error code value
71     * @param message
72     *          the exception message
73     * @param cause
74     *          the original exception cause
75     */
76    public RegularExpressionMetapathException(
77        int code,
78        @Nullable String message,
79        @Nullable Throwable cause) {
80      super(IErrorCode.of(PREFIX, code), message, cause);
81    }
82  
83    /**
84     * Constructs a new exception with the provided {@code code}, {@code message},
85     * and no cause.
86     *
87     * @param code
88     *          the error code value
89     * @param message
90     *          the exception message
91     */
92    public RegularExpressionMetapathException(
93        int code,
94        @Nullable String message) {
95      super(IErrorCode.of(PREFIX, code), message);
96    }
97  
98    /**
99     * Constructs a new exception with the provided {@code code}, no message, and
100    * the {@code cause}.
101    *
102    * @param code
103    *          the error code value
104    * @param cause
105    *          the original exception cause
106    */
107   public RegularExpressionMetapathException(
108       int code,
109       @Nullable Throwable cause) {
110     super(IErrorCode.of(PREFIX, code), cause);
111   }
112 }