1 /*
2 * SPDX-FileCopyrightText: none
3 * SPDX-License-Identifier: CC0-1.0
4 */
5
6 package dev.metaschema.core.metapath.function;
7
8 import dev.metaschema.core.metapath.IErrorCode;
9 import edu.umd.cs.findbugs.annotations.NonNull;
10
11 /**
12 * FORG: Exceptions related to argument types.
13 */
14 public class InvalidArgumentFunctionException
15 extends FunctionMetapathError {
16 @NonNull
17 private static final String PREFIX = "FORG";
18
19 /**
20 * <a href=
21 * "https://www.w3.org/TR/xpath-functions-31/#ERRFORG0001">err:FORG0001</a>: A
22 * general-purpose error raised when casting, if a cast between two datatypes is
23 * allowed in principle, but the supplied value cannot be converted: for example
24 * when attempting to cast the string "nine" to an integer.
25 */
26 public static final int INVALID_VALUE_FOR_CAST = 1;
27 /**
28 * <a href=
29 * "https://www.w3.org/TR/xpath-functions-31/#ERRFORG0002">err:FORG0002</a>:
30 * Raised when either argument to fn:resolve-uri is not a valid URI/IRI.
31 */
32 public static final int INVALID_ARGUMENT_TO_RESOLVE_URI = 2;
33 /**
34 * <a href=
35 * "https://www.w3.org/TR/xpath-functions-31/#ERRFORG0003">err:FORG0003</a>:
36 * Raised by <a href=
37 * "https://www.w3.org/TR/xpath-functions-31/#func-zero-or-one">fn:zero-or-one</a>
38 * if the supplied value contains more than one item.
39 *
40 */
41 public static final int INVALID_ARGUMENT_ZERO_OR_ONE = 3;
42 /**
43 * <a href=
44 * "https://www.w3.org/TR/xpath-functions-31/#ERRFORG0004">err:FORG0005</a>:
45 * Raised by <a href=
46 * "https://www.w3.org/TR/xpath-functions-31/#func-one-or-more">fn:one-or-more</a>
47 * if the supplied value is an empty sequence.
48 */
49 public static final int INVALID_ARGUMENT_ONE_OR_MORE = 4;
50 /**
51 * <a href=
52 * "https://www.w3.org/TR/xpath-functions-31/#ERRFORG0005">err:FORG0005</a>:
53 * Raised by <a href=
54 * "https://www.w3.org/TR/xpath-functions-31/#func-exactly-one">fn:exactly-one</a>
55 * if the supplied value is not a singleton sequence.
56 *
57 */
58 public static final int INVALID_ARGUMENT_EXACTLY_ONE = 5;
59 /**
60 * <a href=
61 * "https://www.w3.org/TR/xpath-functions-31/#ERRFORG0006">err:FORG0006</a>:
62 * Raised by functions such as
63 * <a href="https://www.w3.org/TR/xpath-functions-31/#func-max">fn:max</a>,
64 * <a href="https://www.w3.org/TR/xpath-functions-31/#func-min">fn:min</a>,
65 * <a href="https://www.w3.org/TR/xpath-functions-31/#func-avg">fn:avg</a>,
66 * <a href="https://www.w3.org/TR/xpath-functions-31/#func-sum">fn:sum</a> if
67 * the supplied sequence contains values inappropriate to this function.
68 */
69 public static final int INVALID_ARGUMENT_TYPE = 6;
70
71 /**
72 * <a href=
73 * "https://www.w3.org/TR/xpath-functions-31/#ERRFORG0008">err:FORG0008</a>:
74 * Raised by <a href=
75 * "https://www.w3.org/TR/xpath-functions-31/#func-dateTime">fn:dateTime</a> if
76 * the two arguments both have timezones and the timezones are different.
77 */
78 public static final int DATE_TIME_INCONSISTENT_TIMEZONE = 8;
79
80 /**
81 * the serial version UUID.
82 */
83 private static final long serialVersionUID = 1L;
84
85 /**
86 * Constructs a new exception with the provided {@code code}, {@code message},
87 * and {@code cause}.
88 *
89 * @param code
90 * the error code value
91 * @param message
92 * the exception message
93 * @param cause
94 * the original exception cause
95 */
96 public InvalidArgumentFunctionException(int code, String message, Throwable cause) {
97 super(IErrorCode.of(PREFIX, code), message, cause);
98 }
99
100 /**
101 * Constructs a new exception with the provided {@code code}, {@code message},
102 * and no cause.
103 *
104 * @param code
105 * the error code value
106 * @param message
107 * the exception message
108 */
109 public InvalidArgumentFunctionException(int code, String message) {
110 super(IErrorCode.of(PREFIX, code), message);
111 }
112
113 /**
114 * Constructs a new exception with the provided {@code code}, no message, and
115 * the {@code cause}.
116 *
117 * @param code
118 * the error code value
119 * @param cause
120 * the original exception cause
121 */
122 public InvalidArgumentFunctionException(int code, Throwable cause) {
123 super(IErrorCode.of(PREFIX, code), cause);
124 }
125 }