Interface ItemType

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static interface  ItemType.WithSequenceTypeCache
      Extension of the ItemType interface implemented by some item types, to provide a cache of SequenceType objects based on this item type, with different occurrence indicators.
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default java.util.Optional<java.lang.String> explainMismatch​(Item item, TypeHierarchy th)
      Get extra diagnostic information about why a supplied item does not conform to this item type, if available.
      java.lang.String generateJavaScriptItemTypeAcceptor​(java.lang.String errorCode, int targetVersion)
      Generate Javascript code to convert a supplied Javascript value to this item type, if conversion is possible, or throw an error otherwise.
      java.lang.String generateJavaScriptItemTypeTest​(ItemType knownToBe, int targetVersion)
      Generate Javascript code to test whether an item conforms to this item type
      java.lang.String getAlphaCode()
      Get an alphabetic code representing the type, or at any rate, the nearest built-in type from which this type is derived.
      PlainType getAtomizedItemType()
      Get the item type of the atomic values that will be produced when an item of this type is atomized
      Genre getGenre()
      Determine the Genre (top-level classification) of this type
      ItemType getPrimitiveItemType()
      Get the primitive item type corresponding to this item type.
      int getPrimitiveType()
      Get the primitive type corresponding to this item type.
      UType getUType()
      Get the corresponding UType.
      boolean isAtomicType()
      Determine whether this item type is an atomic type
      boolean isAtomizable​(TypeHierarchy th)
      Ask whether values of this type are atomizable
      boolean isPlainType()
      Determine whether this item type is a plain type (that is, whether it can ONLY match atomic values)
      default boolean isTrueItemType()
      Ask whether this ItemType actually represents an item type in the XDM sense of the term.
      boolean matches​(Item item, TypeHierarchy th)
      Test whether a given item conforms to this type
      default java.lang.String toExportString()
      Return a string representation of this ItemType suitable for use in stylesheet export files.
      java.lang.String toString()  
    • Method Detail

      • 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.
      • isTrueItemType

        default boolean isTrueItemType()
        Ask whether this ItemType actually represents an item type in the XDM sense of the term. The only instances that aren't true item types are user-defined union types derived by restriction from other union types or containing list types in their transitive membership ("impure union types")
        Returns:
        true if this is a true item type in the XDM sense
      • matches

        boolean matches​(Item item,
                        TypeHierarchy th)
                 throws XPathException
        Test whether a given item conforms to this type
        Parameters:
        item - The item to be tested
        th - The type hierarchy cache. Currently used only when matching function items.
        Returns:
        true if the item is an instance of this type; false otherwise
        Throws:
        XPathException
      • 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
      • 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
      • getAlphaCode

        java.lang.String getAlphaCode()
        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
      • toExportString

        default java.lang.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
      • generateJavaScriptItemTypeTest

        java.lang.String generateJavaScriptItemTypeTest​(ItemType knownToBe,
                                                        int targetVersion)
                                                 throws XPathException
        Generate Javascript code to test whether an item conforms to this item type
        Parameters:
        knownToBe - An item type that the supplied item is known to conform to; the generated code can assume that the item is an instance of this type.
        targetVersion - The version of Saxon-JS for which code is being generated. Currently either 1 or 2.
        Returns:
        a Javascript instruction or sequence of instructions, which can be used as the body of a Javascript function, and which returns a boolean indication whether the value of the variable "item" is an instance of this item type.
        Throws:
        XPathException - if JS code cannot be generated for this item type, for example because the test is schema-aware.
      • generateJavaScriptItemTypeAcceptor

        java.lang.String generateJavaScriptItemTypeAcceptor​(java.lang.String errorCode,
                                                            int targetVersion)
                                                     throws XPathException
        Generate Javascript code to convert a supplied Javascript value to this item type, if conversion is possible, or throw an error otherwise.
        Parameters:
        errorCode - the error to be thrown if conversion is not possible
        targetVersion - the version of Saxon-JS for which code is being generated
        Returns:
        a Javascript instruction or sequence of instructions, which can be used as the body of a Javascript function, and which returns the result of conversion to this type, or throws an error if conversion is not possible. The variable "val" will hold the supplied Javascript value.
        Throws:
        XPathException
      • toString

        java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • explainMismatch

        default java.util.Optional<java.lang.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