001/* 002 * SPDX-FileCopyrightText: none 003 * SPDX-License-Identifier: CC0-1.0 004 */ 005 006package dev.metaschema.core.metapath; 007 008import edu.umd.cs.findbugs.annotations.NonNull; 009import edu.umd.cs.findbugs.annotations.Nullable; 010 011/** 012 * MPST: Exceptions related to the Metapath static context and static 013 * evaluation. 014 */ 015// TODO: review use of this exception 016// TODO: include a reference to the Metapath expression? 017// TODO: Move this to a StaticMetapathException that extends this class; align 018// signatures with DynamicMetapathError 019@SuppressWarnings("PMD.DataClass") 020public class StaticMetapathException 021 extends MetapathException { 022 @NonNull 023 private static final String PREFIX = "MPST"; 024 /** 025 * <a href= "https://www.w3.org/TR/xpath-31/#ERRXPST0003">err:MPST0003</a>: It 026 * is a <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static 027 * error</a> if an expression is not a valid instance of the Metapath grammar. 028 */ 029 // TODO: need a Metapath grammar link 030 protected static final int INVALID_PATH_GRAMMAR = 3; 031 032 /** 033 * <a href= "https://www.w3.org/TR/xpath-31/#ERRXPST0008">err:MPST0008</a>: It 034 * is a <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static 035 * error</a> if an expression refers to an element name, attribute name, schema 036 * type name, namespace prefix, or variable name that is not defined in the 037 * <a href="https://www.w3.org/TR/xpath-31/#dt-static-context">static 038 * context</a>, except for an ElementName in an <a href= 039 * "https://www.w3.org/TR/xpath-31/#doc-xpath31-ElementTest">ElementTest</a> or 040 * an AttributeName in an <a href= 041 * "https://www.w3.org/TR/xpath-31/#doc-xpath31-AttributeTest">AttributeTest</a>. 042 */ 043 public static final int NOT_DEFINED = 8; 044 /** 045 * <a href= "https://www.w3.org/TR/xpath-31/#ERRXPST0010">err:MPST0010</a>: An 046 * implementation that does not support the namespace axis must raise a 047 * <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static error</a> if 048 * it encounters a reference to the namespace axis and XPath 1.0 compatibility 049 * mode is false. 050 */ 051 public static final int AXIS_NAMESPACE_UNSUPPORTED = 10; 052 053 /** 054 * <a href= "https://www.w3.org/TR/xpath-31/#ERRXPST0017">err:MPST0017</a>: It 055 * is a <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static 056 * error</a> if the 057 * <a href="https://www.w3.org/TR/xpath-31/#dt-expanded-qname">expanded 058 * QName</a> and number of arguments in a static function call do not match the 059 * name and arity of a 060 * <a href="https://www.w3.org/TR/xpath-31/#dt-known-func-signatures">function 061 * signature</a> in the 062 * <a href="https://www.w3.org/TR/xpath-31/#dt-static-context">static 063 * context</a>. 064 */ 065 public static final int NO_FUNCTION_MATCH = 17; 066 067 /** 068 * <a href= "https://www.w3.org/TR/xpath-31/#ERRXPST0051">err:MPST0051</a>: It 069 * is a static error if the 070 * <a href="https://www.w3.org/TR/xpath-31/#dt-expanded-qname">expanded 071 * QName</a> for an AtomicOrUnionType in a SequenceType is not defined in the 072 * <a href="https://www.w3.org/TR/xpath-31/#dt-is-types">in-scope schema 073 * types</a> as a <a href= 074 * "https://www.w3.org/TR/xpath-31/#dt-generalized-atomic-type">generalized 075 * atomic type</a>. 076 */ 077 public static final int UNKNOWN_TYPE = 51; 078 079 /** 080 * <a href= "https://www.w3.org/TR/xpath-31/#ERRXQST0052">err:MQST0052</a>: The 081 * type named in a cast or castable expression must be the name of a type 082 * defined in the <a href="https://www.w3.org/TR/xpath-31/#dt-is-types">in-scope 083 * schema types</a>, and the type must be simple. 084 */ 085 public static final int CAST_UNKNOWN_TYPE = 52; 086 087 /** 088 * <a href= "https://www.w3.org/TR/xpath-31/#ERRXQST0070">err:MQST0070</a>: A 089 * <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static error</a> is 090 * raised if any of the following conditions is statically detected in any 091 * expression. 092 * <ul> 093 * <li>The prefix xml is bound to some namespace URI other than 094 * http://www.w3.org/XML/1998/namespace. 095 * <li>A prefix other than xml is bound to the namespace URI 096 * http://www.w3.org/XML/1998/namespace. 097 * <li>The prefix xmlns is bound to any namespace URI. 098 * <li>A prefix other than xmlns is bound to the namespace URI 099 * 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}