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 dev.metaschema.core.metapath.item.atomic.IAnyAtomicItem;
10 import edu.umd.cs.findbugs.annotations.NonNull;
11
12 /**
13 * FOCA: Exceptions related to type casting.
14 */
15 public class CastFunctionException
16 extends FunctionMetapathError {
17 @NonNull
18 private static final String PREFIX = "FOCA";
19 /**
20 * <a href=
21 * "https://www.w3.org/TR/xpath-functions-31/#ERRFOCA0002">err:FOCA0002</a>:
22 * Raised by fn:resolve-QName and fn:QName when a supplied value does not have
23 * the lexical form of a QName or URI respectively; and when casting to decimal,
24 * if the supplied value is NaN or Infinity.
25 */
26 public static final int INVALID_LEXICAL_VALUE = 2;
27
28 /**
29 * <a href=
30 * "https://www.w3.org/TR/xpath-functions-31/#ERRFOCA0003">err:FOCA0003</a>:
31 * Raised when casting to xs:integer if the supplied value exceeds the
32 * implementation-defined limits for the datatype.
33 */
34 public static final int INPUT_VALUE_TOO_LARGE = 3;
35
36 /**
37 * the serial version UUID.
38 */
39 private static final long serialVersionUID = 1L;
40
41 /**
42 * The atomic item that could not be cast to the target type.
43 */
44 @NonNull
45 private final IAnyAtomicItem item;
46
47 /**
48 * Constructs a new exception with the provided {@code code}, {@code item}, and
49 * no cause.
50 *
51 * @param code
52 * the error code value
53 * @param item
54 * the item the exception applies to
55 * @param message
56 * the exception message text
57 */
58 public CastFunctionException(int code, @NonNull IAnyAtomicItem item, String message) {
59 super(IErrorCode.of(PREFIX, code), message);
60 this.item = item;
61 }
62
63 /**
64 * Constructs a new exception with the provided {@code code}, {@code item}, and
65 * {@code cause}.
66 *
67 * @param code
68 * the error code value
69 * @param item
70 * the item the exception applies to
71 * @param message
72 * the exception message text
73 * @param cause
74 * the original exception cause
75 */
76 public CastFunctionException(int code, @NonNull IAnyAtomicItem item, String message, Throwable cause) {
77 super(IErrorCode.of(PREFIX, code), message, cause);
78 this.item = item;
79 }
80
81 /**
82 * Get the item associated with the exception.
83 *
84 * @return the associated item
85 */
86 @NonNull
87 public IAnyAtomicItem getItem() {
88 return item;
89 }
90 }