| 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2 | // Copyright (c) 2018 Saxonica Limited. |
| 3 | // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. |
| 4 | // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 | // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. |
| 6 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 7 | |
| 8 | package net.sf.saxon.type; |
| 9 | |
| 10 | import com.saxonica.ee.schema.UserSimpleType; |
| 11 | import net.sf.saxon.expr.Expression; |
| 12 | import net.sf.saxon.lib.ConversionRules; |
| 13 | import net.sf.saxon.lib.NamespaceConstant; |
| 14 | import net.sf.saxon.om.*; |
| 15 | import net.sf.saxon.pattern.NodeTest; |
| 16 | import net.sf.saxon.trans.XPathException; |
| 17 | import net.sf.saxon.value.AtomicValue; |
| 18 | import net.sf.saxon.value.SequenceType; |
| 19 | import net.sf.saxon.value.UntypedAtomicValue; |
| 20 | import net.sf.saxon.value.Whitespace; |
| 21 | |
| 22 | import java.util.Collections; |
| 23 | import java.util.Optional; |
| 24 | |
| 25 | import static net.sf.saxon.type.SchemaComponent.ValidationStatus.VALIDATED; |
| 26 | |
| 27 | |
| 28 | /** |
| 29 | * This class has a singleton instance which represents the XML Schema 1.1 built-in type xs:error. |
| 30 | */ |
| 31 | |
| 32 | public final class ErrorType extends NodeTest implements AtomicType, UnionType, PlainType { |
| 33 | |
| 34 | /*@NotNull*/ private static ErrorType theInstance = new ErrorType(); |
| 35 | |
| 36 | /** |
| 37 | * Private constructor |
| 38 | */ |
| 39 | private ErrorType() { |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Get the corresponding {@link net.sf.saxon.type.UType}. A UType is a union of primitive item |
| 44 | * types. |
| 45 | * |
| 46 | * @return the smallest UType that subsumes this item type |
| 47 | */ |
| 48 | public UType getUType() { |
| 49 | return UType.VOID; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Get the local name of this type |
| 54 | * |
| 55 | * @return the local name of this type definition, if it has one. Return null in the case of an |
| 56 | * anonymous type. |
| 57 | */ |
| 58 | |
| 59 | /*@NotNull*/ |
| 60 | public String getName() { |
| 61 | return "error"; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Get the target namespace of this type |
| 66 | * |
| 67 | * @return the target namespace of this type definition, if it has one. Return null in the case |
| 68 | * of an anonymous type, and in the case of a global type defined in a no-namespace schema. |
| 69 | */ |
| 70 | |
| 71 | public String getTargetNamespace() { |
| 72 | return NamespaceConstant.SCHEMA; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Get the name of this type as an EQName, that is, a string in the format Q{uri}local. |
| 77 | * |
| 78 | * @return an EQName identifying the type. In the case of an anonymous type, an internally-generated |
| 79 | * name is returned |
| 80 | */ |
| 81 | public String getEQName() { |
| 82 | return "Q{" + NamespaceConstant.SCHEMA + "}error"; |
| 83 | } |
| 84 | |
| 85 | |
| 86 | |
| 87 | public boolean containsListType() { |
| 88 | return false; |
| 89 | } |
| 90 | |
| 91 | public Iterable<PlainType> getPlainMemberTypes() { |
| 92 | return Collections.emptySet(); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Return true if this is an external object type, that is, a Saxon-defined type for external |
| 97 | * Java or .NET objects |
| 98 | */ |
| 99 | |
| 100 | public boolean isExternalType() { |
| 101 | return false; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Determine whether this is a built-in type or a user-defined type |
| 106 | */ |
| 107 | |
| 108 | public boolean isBuiltInType() { |
| 109 | return true; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Get the redefinition level. This is zero for a component that has not been redefined; |
| 114 | * for a redefinition of a level-0 component, it is 1; for a redefinition of a level-N |
| 115 | * component, it is N+1. This concept is used to support the notion of "pervasive" redefinition: |
| 116 | * if a component is redefined at several levels, the top level wins, but it is an error to have |
| 117 | * two versions of the component at the same redefinition level. |
| 118 | * |
| 119 | * @return the redefinition level |
| 120 | */ |
| 121 | |
| 122 | public int getRedefinitionLevel() { |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Get the URI of the schema document containing the definition of this type |
| 128 | * |
| 129 | * @return null for a built-in type |
| 130 | */ |
| 131 | |
| 132 | /*@Nullable*/ |
| 133 | public String getSystemId() { |
| 134 | return null; |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Get the singular instance of this class |
| 139 | * |
| 140 | * @return the singular object representing xs:anyType |
| 141 | */ |
| 142 | |
| 143 | /*@NotNull*/ |
| 144 | public static ErrorType getInstance() { |
| 145 | return theInstance; |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Get the validation status - always valid |
| 150 | */ |
| 151 | public ValidationStatus getValidationStatus() { |
| 152 | return VALIDATED; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Get the base type |
| 157 | * |
| 158 | * @return AnyType |
| 159 | */ |
| 160 | |
| 161 | /*@NotNull*/ |
| 162 | public SchemaType getBaseType() { |
| 163 | return AnySimpleType.getInstance(); |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Returns the base type that this type inherits from. This method can be used to get the |
| 168 | * base type of a type that is known to be valid. |
| 169 | * |
| 170 | * @return the base type. |
| 171 | */ |
| 172 | |
| 173 | /*@NotNull*/ |
| 174 | public SchemaType getKnownBaseType() { |
| 175 | return getBaseType(); |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Test whether this SchemaType is a complex type |
| 180 | * |
| 181 | * @return true if this SchemaType is a complex type |
| 182 | */ |
| 183 | |
| 184 | public boolean isComplexType() { |
| 185 | return false; |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * Test whether this SchemaType is a simple type |
| 190 | * |
| 191 | * @return true if this SchemaType is a simple type |
| 192 | */ |
| 193 | |
| 194 | public boolean isSimpleType() { |
| 195 | return true; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Get the fingerprint of the name of this type |
| 200 | * |
| 201 | * @return the fingerprint. |
| 202 | */ |
| 203 | |
| 204 | public int getFingerprint() { |
| 205 | return StandardNames.XS_ERROR; |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Get the name of the nodes matched by this nodetest, if it matches a specific name. |
| 210 | * Return null if the node test matches nodes of more than one name |
| 211 | */ |
| 212 | @Override |
| 213 | public StructuredQName getMatchingNodeName() { |
| 214 | return StandardNames.getStructuredQName(StandardNames.XS_ERROR); |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * Get the name of the type as a StructuredQName |
| 219 | * |
| 220 | * @return a StructuredQName identifying the type. In the case of an anonymous type, an internally-generated |
| 221 | * name is returned |
| 222 | */ |
| 223 | public StructuredQName getStructuredQName() { |
| 224 | return new StructuredQName("xs", NamespaceConstant.SCHEMA, "error"); |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Get a description of this type for use in diagnostics |
| 229 | * |
| 230 | * @return the string "xs:anyType" |
| 231 | */ |
| 232 | |
| 233 | /*@NotNull*/ |
| 234 | public String getDescription() { |
| 235 | return "xs:error"; |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * Get the display name of the type: that is, a lexical QName with an arbitrary prefix |
| 240 | * |
| 241 | * @return a lexical QName identifying the type |
| 242 | */ |
| 243 | |
| 244 | /*@NotNull*/ |
| 245 | public String getDisplayName() { |
| 246 | return "xs:error"; |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * Test whether this is the same type as another type. They are considered to be the same type |
| 251 | * if they are derived from the same type definition in the original XML representation (which |
| 252 | * can happen when there are multiple includes of the same file) |
| 253 | */ |
| 254 | |
| 255 | public boolean isSameType(SchemaType other) { |
| 256 | return other instanceof ErrorType; |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * Get the typed value of a node that is annotated with this schema type. |
| 261 | * |
| 262 | * @param node the node whose typed value is required |
| 263 | * @return the typed value. |
| 264 | * @since 8.5 |
| 265 | */ |
| 266 | |
| 267 | /*@NotNull*/ |
| 268 | public AtomicSequence atomize(/*@NotNull*/ NodeInfo node) { |
| 269 | return new UntypedAtomicValue(node.getStringValueCS()); |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * Check that this type is validly derived from a given type |
| 274 | * |
| 275 | * @param type the type from which this type is derived |
| 276 | * @param block the derivations that are blocked by the relevant element declaration |
| 277 | * @throws net.sf.saxon.type.SchemaException |
| 278 | * if the derivation is not allowed |
| 279 | */ |
| 280 | |
| 281 | public void checkTypeDerivationIsOK(/*@NotNull*/ SchemaType type, int block) throws SchemaException { |
| 282 | if (type == this || type == AnySimpleType.getInstance()) { |
| 283 | return; |
| 284 | } |
| 285 | throw new SchemaException("Type xs:error is not validly derived from " + type.getDescription()); |
| 286 | } |
| 287 | |
| 288 | /** |
| 289 | * Test whether this Simple Type is an atomic type |
| 290 | * |
| 291 | * @return false, this is not (necessarily) an atomic type |
| 292 | */ |
| 293 | |
| 294 | public boolean isAtomicType() { |
| 295 | return false; |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * Ask whether this type is an ID type. This is defined to be any simple type |
| 300 | * who typed value may contain atomic values of type xs:ID: that is, it includes types derived |
| 301 | * from ID by restriction, list, or union. Note that for a node to be treated |
| 302 | * as an ID, its typed value must be a *single* atomic value of type ID; the type of the |
| 303 | * node, however, can still allow a list. |
| 304 | */ |
| 305 | |
| 306 | public boolean isIdType() { |
| 307 | return false; |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * Ask whether this type is an IDREF or IDREFS type. This is defined to be any simple type |
| 312 | * who typed value may contain atomic values of type xs:IDREF: that is, it includes types derived |
| 313 | * from IDREF or IDREFS by restriction, list, or union |
| 314 | */ |
| 315 | |
| 316 | public boolean isIdRefType() { |
| 317 | return false; |
| 318 | } |
| 319 | |
| 320 | public boolean isAnonymousType() { |
| 321 | return false; |
| 322 | } |
| 323 | |
| 324 | |
| 325 | /** |
| 326 | * Determine whether this is a list type |
| 327 | * |
| 328 | * @return false (it isn't a list type) |
| 329 | */ |
| 330 | public boolean isListType() { |
| 331 | return false; |
| 332 | } |
| 333 | |
| 334 | /** |
| 335 | * Determin whether this is a union type |
| 336 | * |
| 337 | * @return true (this is a union type with no members) |
| 338 | */ |
| 339 | public boolean isUnionType() { |
| 340 | return true; |
| 341 | } |
| 342 | |
| 343 | /** |
| 344 | * Get the built-in ancestor of this type in the type hierarchy |
| 345 | * |
| 346 | * @return xs:anySimpleType |
| 347 | */ |
| 348 | /*@NotNull*/ |
| 349 | public SchemaType getBuiltInBaseType() { |
| 350 | return this; |
| 351 | } |
| 352 | |
| 353 | /** |
| 354 | * Get the typed value corresponding to a given string value, assuming it is |
| 355 | * valid against this type |
| 356 | * |
| 357 | * @param value the string value |
| 358 | * @param resolver a namespace resolver used to resolve any namespace prefixes appearing |
| 359 | * in the content of values. Can supply null, in which case any namespace-sensitive content |
| 360 | * will be rejected. |
| 361 | * @param rules the conversion rules |
| 362 | * @return an iterator over the atomic sequence comprising the typed value. The objects |
| 363 | * returned by this SequenceIterator will all be of type {@link net.sf.saxon.value.AtomicValue} |
| 364 | * @throws ValidationException if the supplied value is not in the lexical space of the data type (which is |
| 365 | * always true for this type) |
| 366 | */ |
| 367 | |
| 368 | /*@NotNull*/ |
| 369 | public AtomicSequence getTypedValue(CharSequence value, NamespaceResolver resolver, ConversionRules rules) throws ValidationException { |
| 370 | throw new ValidationFailure("Cast to xs:error always fails").makeException(); |
| 371 | } |
| 372 | |
| 373 | /** |
| 374 | * Get a StringConverter, an object which converts strings in the lexical space of this |
| 375 | * data type to instances (in the value space) of the data type. |
| 376 | * |
| 377 | * @return a StringConverter to do the conversion, or null if no built-in converter is available. |
| 378 | */ |
| 379 | public StringConverter getStringConverter(ConversionRules rules) { |
| 380 | return null; |
| 381 | } |
| 382 | |
| 383 | /** |
| 384 | * Check whether a given input string is valid according to this SimpleType |
| 385 | * |
| 386 | * @param value the input string to be checked |
| 387 | * @param nsResolver a namespace resolver used to resolve namespace prefixes if the type |
| 388 | * is namespace sensitive. The value supplied may be null; in this case any namespace-sensitive |
| 389 | * content will throw an UnsupportedOperationException. |
| 390 | * @param rules the conversion rules |
| 391 | * @return null if validation succeeds (which it never does for this implementation) |
| 392 | * @throws UnsupportedOperationException if the type is namespace-sensitive and no namespace |
| 393 | * resolver is supplied |
| 394 | */ |
| 395 | /*@NotNull*/ |
| 396 | public ValidationFailure validateContent(/*@NotNull*/ CharSequence value, NamespaceResolver nsResolver, /*@NotNull*/ ConversionRules rules) { |
| 397 | return new ValidationFailure("No content is ever valid against the type xs:error"); |
| 398 | } |
| 399 | |
| 400 | /** |
| 401 | * Test whether this type represents namespace-sensitive content |
| 402 | * |
| 403 | * @return false |
| 404 | */ |
| 405 | public boolean isNamespaceSensitive() { |
| 406 | return false; |
| 407 | } |
| 408 | |
| 409 | /** |
| 410 | * Returns the value of the 'block' attribute for this type, as a bit-signnificant |
| 411 | * integer with fields such as {@link net.sf.saxon.type.SchemaType#DERIVATION_LIST} and {@link net.sf.saxon.type.SchemaType#DERIVATION_EXTENSION} |
| 412 | * |
| 413 | * @return the value of the 'block' attribute for this type |
| 414 | */ |
| 415 | |
| 416 | public int getBlock() { |
| 417 | return 0; |
| 418 | } |
| 419 | |
| 420 | /** |
| 421 | * Gets the integer code of the derivation method used to derive this type from its |
| 422 | * parent. Returns zero for primitive types. |
| 423 | * |
| 424 | * @return a numeric code representing the derivation method, for example {@link net.sf.saxon.type.SchemaType#DERIVATION_RESTRICTION} |
| 425 | */ |
| 426 | |
| 427 | public int getDerivationMethod() { |
| 428 | return SchemaType.DERIVATION_RESTRICTION; |
| 429 | } |
| 430 | |
| 431 | /** |
| 432 | * Determines whether derivation (of a particular kind) |
| 433 | * from this type is allowed, based on the "final" property |
| 434 | * |
| 435 | * @param derivation the kind of derivation, for example {@link net.sf.saxon.type.SchemaType#DERIVATION_LIST} |
| 436 | * @return true if this kind of derivation is allowed |
| 437 | */ |
| 438 | |
| 439 | public boolean allowsDerivation(int derivation) { |
| 440 | return false; |
| 441 | } |
| 442 | |
| 443 | /** |
| 444 | * Get the types of derivation that are not permitted, by virtue of the "final" property. |
| 445 | * |
| 446 | * @return the types of derivation that are not permitted, as a bit-significant integer |
| 447 | * containing bits such as {@link net.sf.saxon.type.SchemaType#DERIVATION_EXTENSION} |
| 448 | */ |
| 449 | public int getFinalProhibitions() { |
| 450 | return SchemaType.DERIVATION_EXTENSION | SchemaType.DERIVATION_RESTRICTION | SchemaType.DERIVATION_LIST | |
| 451 | SchemaType.DERIVATION_UNION; |
| 452 | } |
| 453 | |
| 454 | /** |
| 455 | * Determine how values of this simple type are whitespace-normalized. |
| 456 | * |
| 457 | * @return one of {@link net.sf.saxon.value.Whitespace#PRESERVE}, {@link net.sf.saxon.value.Whitespace#COLLAPSE}, |
| 458 | * {@link net.sf.saxon.value.Whitespace#REPLACE}. |
| 459 | */ |
| 460 | |
| 461 | public int getWhitespaceAction() { |
| 462 | return Whitespace.COLLAPSE; |
| 463 | } |
| 464 | |
| 465 | /** |
| 466 | * Analyze an expression to see whether the expression is capable of delivering a value of this |
| 467 | * type. |
| 468 | * |
| 469 | * @param expression the expression that delivers the content |
| 470 | * @param kind the node kind whose content is being delivered: {@link Type#ELEMENT}, |
| 471 | * {@link Type#ATTRIBUTE}, or {@link Type#DOCUMENT} |
| 472 | */ |
| 473 | |
| 474 | public void analyzeContentExpression(Expression expression, int kind) throws XPathException { |
| 475 | throw new XPathException("No expression can ever return a value of type xs:error"); |
| 476 | } |
| 477 | |
| 478 | /** |
| 479 | * Apply any pre-lexical facets, other than whitespace. At the moment the only such |
| 480 | * facet is saxon:preprocess |
| 481 | * |
| 482 | * @param input the value to be preprocessed |
| 483 | * @return the value after preprocessing |
| 484 | */ |
| 485 | |
| 486 | public CharSequence preprocess(CharSequence input) { |
| 487 | return input; |
| 488 | } |
| 489 | |
| 490 | /** |
| 491 | * Reverse any pre-lexical facets, other than whitespace. At the moment the only such |
| 492 | * facet is saxon:preprocess. This is called when converting a value of this type to |
| 493 | * a string |
| 494 | * |
| 495 | * @param input the value to be postprocessed: this is the "ordinary" result of converting |
| 496 | * the value to a string |
| 497 | * @return the value after postprocessing |
| 498 | */ |
| 499 | |
| 500 | public CharSequence postprocess(CharSequence input) { |
| 501 | return input; |
| 502 | } |
| 503 | |
| 504 | public boolean isPlainType() { |
| 505 | return true; |
| 506 | } |
| 507 | |
| 508 | public boolean matches(Item item, TypeHierarchy th) { |
| 509 | return false; |
| 510 | } |
| 511 | |
| 512 | @Override |
| 513 | public boolean matches(int nodeKind, NodeName name, SchemaType annotation) { |
| 514 | return false; |
| 515 | } |
| 516 | |
| 517 | public AtomicType getPrimitiveItemType() { |
| 518 | return this; |
| 519 | } |
| 520 | |
| 521 | public int getPrimitiveType() { |
| 522 | return Type.ITEM; |
| 523 | } |
| 524 | |
| 525 | public double getDefaultPriority() { |
| 526 | return -1000; |
| 527 | } |
| 528 | |
| 529 | public AtomicType getAtomizedItemType() { |
| 530 | return BuiltInAtomicType.UNTYPED_ATOMIC; |
| 531 | } |
| 532 | |
| 533 | public boolean isAtomizable(TypeHierarchy th) { |
| 534 | return false; |
| 535 | } |
| 536 | |
| 537 | public SequenceType getResultTypeOfCast() { |
| 538 | // The return type is chosen so that use of the error() function will never give a static type error, |
| 539 | // on the basis that item()? overlaps every other type, and it's almost impossible to make any |
| 540 | // unwarranted inferences from it, except perhaps count(error()) lt 2. |
| 541 | return SequenceType.OPTIONAL_ITEM; |
| 542 | } |
| 543 | |
| 544 | /** |
| 545 | * Return a string representation of this ItemType suitable for use in stylesheet |
| 546 | * export files. This differs from the result of toString() in that it will not contain |
| 547 | * any references to anonymous types. Note that it may also use the Saxon extended syntax |
| 548 | * for union types and tuple types. The default implementation returns the result of |
| 549 | * calling {@code toString()}. |
| 550 | * |
| 551 | * @return the string representation as an instance of the XPath SequenceType construct |
| 552 | */ |
| 553 | @Override |
| 554 | public String toExportString() { |
| 555 | return toString(); |
| 556 | } |
| 557 | |
| 558 | public String toString() { |
| 559 | return "xs:error"; |
| 560 | } |
| 561 | |
| 562 | /** |
| 563 | * Validate that a primitive atomic value is a valid instance of a type derived from the |
| 564 | * same primitive type. |
| 565 | * |
| 566 | * @param primValue the value in the value space of the primitive type. |
| 567 | * @param lexicalValue the value in the lexical space. If null, the string value of primValue |
| 568 | * is used. This value is checked against the pattern facet (if any) |
| 569 | * @param rules the conversion rules |
| 570 | * @return null if the value is valid; otherwise, a ValidationFailure object indicating |
| 571 | * the nature of the error. |
| 572 | * @throws UnsupportedOperationException in the case of an external object type |
| 573 | */ |
| 574 | public ValidationFailure validate(AtomicValue primValue, CharSequence lexicalValue, ConversionRules rules) { |
| 575 | return new ValidationFailure("No value is valid against type xs:error"); |
| 576 | } |
| 577 | |
| 578 | /** |
| 579 | * Determine whether the atomic type is ordered, that is, whether less-than and greater-than comparisons |
| 580 | * are permitted |
| 581 | * |
| 582 | * @param optimistic if true, the function takes an optimistic view, returning true if ordering comparisons |
| 583 | * are available for some subtype. This mainly affects xs:duration, where the function returns true if |
| 584 | * optimistic is true, false if it is false. |
| 585 | * @return true if ordering operations are permitted |
| 586 | */ |
| 587 | public boolean isOrdered(boolean optimistic) { |
| 588 | return false; |
| 589 | } |
| 590 | |
| 591 | /** |
| 592 | * Determine whether the type is abstract, that is, whether it cannot have instances that are not also |
| 593 | * instances of some concrete subtype |
| 594 | */ |
| 595 | public boolean isAbstract() { |
| 596 | return true; |
| 597 | } |
| 598 | |
| 599 | /** |
| 600 | * Determine whether the atomic type is a primitive type. The primitive types are |
| 601 | * the 19 primitive types of XML Schema, plus xs:integer, xs:dayTimeDuration and xs:yearMonthDuration; |
| 602 | * xs:untypedAtomic; and all supertypes of these (xs:anyAtomicType, xs:numeric, ...) |
| 603 | * |
| 604 | * @return true if the type is considered primitive under the above rules |
| 605 | */ |
| 606 | public boolean isPrimitiveType() { |
| 607 | return false; |
| 608 | } |
| 609 | |
| 610 | /** |
| 611 | * Get the name of this type as a StructuredQName, unless the type is anonymous, in which case |
| 612 | * return null |
| 613 | * |
| 614 | * @return the name of the atomic type, or null if the type is anonymous. |
| 615 | */ |
| 616 | public StructuredQName getTypeName() { |
| 617 | return new StructuredQName("xs", NamespaceConstant.SCHEMA, "error"); |
| 618 | } |
| 619 | |
| 620 | /** |
| 621 | * Validate an atomic value, which is known to be an instance of one of the member types of the |
| 622 | * union, against any facets (pattern facets or enumeration facets) defined at the level of the |
| 623 | * union itself. |
| 624 | * |
| 625 | * @param value the Atomic Value to be checked. This must be an instance of a member type of the |
| 626 | * union |
| 627 | * @param rules the ConversionRules for the Configuration |
| 628 | * @return a ValidationFailure if the value is not valid; null if it is valid. |
| 629 | */ |
| 630 | @Override |
| 631 | public ValidationFailure checkAgainstFacets(AtomicValue value, ConversionRules rules) { |
| 632 | return null; |
| 633 | } |
| 634 | |
| 635 | /** |
| 636 | * Generate Javascript code to test whether an item conforms to this item type |
| 637 | * |
| 638 | * @return a Javascript instruction or sequence of instructions, which can be used as the body |
| 639 | * of a Javascript function, and which returns a boolean indication whether the value of the |
| 640 | * variable "item" is an instance of this item type. |
| 641 | * @param knownToBe |
| 642 | * @param targetVersion |
| 643 | */ |
| 644 | @Override |
| 645 | public String generateJavaScriptItemTypeTest(ItemType knownToBe, int targetVersion) { |
| 646 | return "return false;"; |
| 647 | } |
| 648 | |
| 649 | /** |
| 650 | * Get extra diagnostic information about why a supplied item does not conform to this |
| 651 | * item type, if available. If extra information is returned, it should be in the form of a complete |
| 652 | * sentence, minus the closing full stop. No information should be returned for obvious cases. |
| 653 | * |
| 654 | * @param item the item that doesn't match this type |
| 655 | * @param th the type hierarchy cache |
| 656 | * @return optionally, a message explaining why the item does not match the type |
| 657 | */ |
| 658 | @Override |
| 659 | public Optional<String> explainMismatch(Item item, TypeHierarchy th) { |
| 660 | return Optional.of("Evaluation of the supplied expression will always fail"); |
| 661 | } |
| 662 | |
| 663 | //#ifdefined SCHEMA |
| 664 | |
| 665 | /** |
| 666 | * Get the schema component in the form of a function item. This allows schema information |
| 667 | * to be made visible to XSLT or XQuery code. The function makes available the contents of the |
| 668 | * schema component as defined in the XSD specification. The function takes a string as argument |
| 669 | * representing a property name, and returns the corresponding property of the schema component. |
| 670 | * There is also a property "class" which returns the kind of schema component, for example |
| 671 | * "Attribute Declaration". |
| 672 | * |
| 673 | * @return the schema component represented as a function from property names to property values. |
| 674 | */ |
| 675 | public Function getComponentAsFunction() { |
| 676 | return UserSimpleType.getComponentAsFunction(this); |
| 677 | } |
| 678 | //#endif |
| 679 | |
| 680 | } |
| 681 |