Interface ItemType

All Known Subinterfaces:
AtomicType, FunctionItemType, ItemTypeWithSequenceTypeCache, PlainType, UnionType
All Known Implementing Classes:
AnyExternalObjectType, AnyFunctionType, AnyFunctionTypeWithAssertions, AnyGNodeType, AnyItemType, AnyJNodeType, AnyXNodeType, ArrayItemType, BuiltInAtomicType, ChoiceItemType, DocumentNodeType, EnumerationUnionType, ErrorType, ExternalObjectType, GNodeType, JavaExternalObjectType, JNodeType, LocalUnionType, MapType, NamedXNodeType, NodeKindType, NumericType, PortableNamedXNodeType, RecordType, RootJNodeType, SchemaAttributeType, SchemaElementType, SingletonEnumType, SpecificFunctionType, SpecificJNodeType, UserAtomicType, UserUnionType, XNodeType

public interface ItemType
ItemType is an interface that allows testing of whether an Item conforms to an expected type. ItemType represents the types in the type hierarchy in the XPath model, as distinct from the schema model: an item type is either item() (matches everything), a node type (matches nodes), an atomic type (matches atomic values), or empty() (matches nothing). Atomic types, represented by the class AtomicType, are also instances of SimpleType in the schema type hierarchy. Node Types, represented by the class NodeTest, are also Patterns as used in XSLT.

Saxon assumes that apart from AnyItemType (which corresponds to item() and matches anything), every ItemType will be either an AtomicType, a NodeTest, or a FunctionItemType. User-defined implementations of ItemType must therefore extend one of those three classes/interfaces.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Expand this item type to a choice item type.
    Get extra diagnostic information about why a supplied item does not conform to this item type, if available.
    Get the item type of the atomic values that will be produced when an item of this type is atomized
    Get an alphabetic code representing the type, or at any rate, the nearest built-in type from which this type is derived.
    getCoercionPlan(int version)
    Get the coercion plan for use when this type is the required type for (say) coercion of arguments in a function call
    double
    Get the default priority when this ItemType is used as an XSLT pattern
    Determine the Genre (top-level classification) of this type
    default double
    Get the default priority normalized into the range 0 to 1
    Get the primitive item type corresponding to this item type.
    int
    Get the primitive type corresponding to this item type.
    Get the corresponding UType.
    boolean
    Determine whether this item type is an atomic type
    boolean
    Ask whether values of this type are atomizable
    boolean
    Determine whether this item type is a plain type (that is, whether it can ONLY match atomic values)
    boolean
    matches(Item item)
    Test whether a given item conforms to this type
    default ItemType
    Normalize this item type, returning a potentially different item type that matches the same items.
    default String
    Return a string representation of this ItemType suitable for use in stylesheet export files.
  • Method Details

    • getGenre

      Genre getGenre()
      Determine the Genre (top-level classification) of this type
      Returns:
      the Genre to which this type belongs, for example node or atomic value
    • isAtomicType

      boolean isAtomicType()
      Determine whether this item type is an atomic type
      Returns:
      true if this is ANY_ATOMIC_TYPE or a subtype thereof
    • isPlainType

      boolean isPlainType()
      Determine whether this item type is a plain type (that is, whether it can ONLY match atomic values)
      Returns:
      true if this is ANY_ATOMIC_TYPE or a subtype thereof, or a "plain" union type (that is, unions of atomic types that impose no further restrictions). Return false if this is a union type whose member types are not all known.
    • matches

      boolean matches(Item item)
      Test whether a given item conforms to this type
      Parameters:
      item - The item to be tested
      Returns:
      true if the item is an instance of this type; false otherwise
    • getPrimitiveItemType

      ItemType getPrimitiveItemType()
      Get the primitive item type corresponding to this item type. For item(), this is Type.ITEM. For node(), it is Type.NODE. For specific node kinds, it is the value representing the node kind, for example Type.ELEMENT. For anyAtomicValue and union types it is Type.ATOMIC_VALUE. For numeric it is Type.NUMBER. For other atomic types it is the primitive type as defined in XML Schema, except that integer, xs:dayTimeDuration, and xs:yearMonthDuration are considered to be primitive types.
      Returns:
      the corresponding primitive type
    • getPrimitiveType

      int getPrimitiveType()
      Get the primitive type corresponding to this item type. For item(), this is Type.ITEM. For node(), it is Type.NODE. For specific node kinds, it is the value representing the node kind, for example Type.ELEMENT. For anyAtomicValue it is BuiltInAtomicType.ANY_ATOMIC. For numeric it is Type.NUMBER. For other atomic types it is the primitive type as defined in XML Schema, except that INTEGER is considered to be a primitive type.
      Returns:
      the integer fingerprint of the corresponding primitive type
    • getUType

      UType getUType()
      Get the corresponding UType. A UType is a union of primitive item types.
      Returns:
      the smallest UType that subsumes this item type
    • getDefaultPriority

      double getDefaultPriority()
      Get the default priority when this ItemType is used as an XSLT pattern
      Returns:
      the default priority
    • getNormalizedDefaultPriority

      default double getNormalizedDefaultPriority()
      Get the default priority normalized into the range 0 to 1
      Returns:
      the default priority plus one divided by two
    • getAtomizedItemType

      PlainType getAtomizedItemType()
      Get the item type of the atomic values that will be produced when an item of this type is atomized
      Returns:
      the best available item type of the atomic values that will be produced when an item of this type is atomized, or null if it is known that atomization will throw an error.
    • isAtomizable

      boolean isAtomizable(TypeHierarchy th)
      Ask whether values of this type are atomizable
      Parameters:
      th - the type hierarchy cache
      Returns:
      true if some or all instances of this type can be successfully atomized; false if no instances of this type can be atomized
    • getCoercionPlan

      CoercionPlan getCoercionPlan(int version)
      Get the coercion plan for use when this type is the required type for (say) coercion of arguments in a function call
      Parameters:
      version - the XPath language version (40 or 31)
    • getBasicAlphaCode

      String getBasicAlphaCode()
      Get an alphabetic code representing the type, or at any rate, the nearest built-in type from which this type is derived. The codes are designed so that for any two built-in types A and B, alphaCode(A) is a prefix of alphaCode(B) if and only if A is a supertype of B.
      Returns:
      the alphacode for the nearest containing built-in type. For example: for xs:string return "AS", for xs:boolean "AB", for node() "N", for element() "NE", for map(*) "FM", for array(*) "FA".
    • toExportString

      default String toExportString()
      Return a string representation of this ItemType suitable for use in stylesheet export files. This differs from the result of toString() in that it will not contain any references to anonymous types. Note that it may also use the Saxon extended syntax for union types and tuple types. The default implementation returns the result of calling toString().
      Returns:
      the string representation as an instance of the XPath SequenceType construct
    • normalizeItemType

      default ItemType normalizeItemType()
      Normalize this item type, returning a potentially different item type that matches the same items. For example, record(*) and map(*) match the same items. The default implementation returns the item type unchanged. This method does NOT expand item types to an equivalent choice item type.

      Item types should be normalized before comparison using equals().

      Returns:
      the normalized item type.
    • asChoiceItemType

      default ChoiceItemType asChoiceItemType()
      Expand this item type to a choice item type. The default delivers a choice with this type as its only member. Implementations for abstract types return a choice of the corresponding concrete types, for example node() expands to a choice of the seven node kinds. The implementation for a choice type that includes abstract member types should expand these recursively.
    • explainMismatch

      Optional<String> explainMismatch(Item item, TypeHierarchy th)
      Get extra diagnostic information about why a supplied item does not conform to this item type, if available. If extra information is returned, it should be in the form of a complete sentence, minus the closing full stop. No information should be returned for obvious cases.
      Parameters:
      item - the item that doesn't match this type
      th - the type hierarchy cache
      Returns:
      optionally, a message explaining why the item does not match the type