Class GNodeType

java.lang.Object
net.sf.saxon.type.gnode.GNodeType
All Implemented Interfaces:
NodePredicate, NodeTest, ItemType, ItemTypeWithSequenceTypeCache
Direct Known Subclasses:
AnyGNodeType, ErrorType, JNodeType, XNodeType

public abstract class GNodeType extends Object implements ItemTypeWithSequenceTypeCache, ItemType, NodeTest
Abstract superclass for all gnode types. In 4.0, node predicates (as used in axis steps) are separated from node types (as item types). Subclasses of GNodeType represent item types whose instances are all nodes; they cannot be used directly as node predicates in an axis step.
  • Constructor Details

    • GNodeType

      public GNodeType()
  • Method Details

    • getGenre

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

      public final boolean isAtomicType()
      Determine whether this item type is an atomic type
      Specified by:
      isAtomicType in interface ItemType
      Returns:
      true if this is ANY_ATOMIC_TYPE or a subtype thereof
    • isPlainType

      public final boolean isPlainType()
      Determine whether this item type is a plain type (that is, whether it can ONLY match atomic values)
      Specified by:
      isPlainType in interface ItemType
      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.
    • getContentType

      public SchemaType getContentType()
      Get the allowed content type. By default, this returns ANY_TYPE, allowing any content.
      Returns:
      the allowed content type
    • getPrimitiveItemType

      public 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.
      Specified by:
      getPrimitiveItemType in interface ItemType
      Returns:
      the corresponding primitive type
    • getPrimitiveType

      public 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.
      Specified by:
      getPrimitiveType in interface ItemType
      Returns:
      the integer fingerprint of the corresponding primitive type
    • matches

      public abstract boolean matches(Item item)
      Test whether a given item conforms to this type
      Specified by:
      matches in interface ItemType
      Parameters:
      item - The item to be tested
      Returns:
      true if the item is an instance of this type; false otherwise
    • test

      public final boolean test(GNode node)
      Test whether a given item conforms to this type (to implement NodePredicate)
      Specified by:
      test in interface NodePredicate
      Specified by:
      test in interface NodeTest
      Parameters:
      node - The item to be tested
      Returns:
      true if the item is an instance of this type; false otherwise
    • getUType

      public UType getUType()
      Get the corresponding UType. A UType is a union of primitive item types.
      Specified by:
      getUType in interface ItemType
      Specified by:
      getUType in interface NodeTest
      Returns:
      the smallest UType that subsumes this item type
    • getCoercionPlan

      public 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
      Specified by:
      getCoercionPlan in interface ItemType
      Parameters:
      version - the XPath language version (40 or 31)
    • getAtomizedItemType

      public PlainType getAtomizedItemType()
      Get the item type of the atomic values that will be produced when an item of this type is atomized
      Specified by:
      getAtomizedItemType in interface ItemType
      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

      public boolean isAtomizable(TypeHierarchy th)
      Ask whether values of this type are atomizable
      Specified by:
      isAtomizable in interface ItemType
      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
    • explainMismatch

      public 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.
      Specified by:
      explainMismatch in interface ItemType
      Specified by:
      explainMismatch in interface NodeTest
      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
    • getQNameTest

      public QNameTest getQNameTest()
      Extract a QNameTest (the strongest one possible) that must be satisfied by a node if it is to satisfy this NodeTest
      Specified by:
      getQNameTest in interface NodeTest
      Returns:
      the strongest possible QNameTest
    • getItemType

      public ItemType getItemType()
      Get an item type that all matching nodes must satisfy
      Specified by:
      getItemType in interface NodeTest
      Returns:
      an item type
    • toShortString

      public String toShortString()
      Get a concise string representation of this node test for use in diagnostics
      Specified by:
      toShortString in interface NodeTest
      Returns:
      a suitably abbreviated respresention of the node test
    • one

      public SequenceType one()
      Get a sequence type representing exactly one instance of this type
      Specified by:
      one in interface ItemTypeWithSequenceTypeCache
      Returns:
      a sequence type representing exactly one instance of this type
    • zeroOrOne

      public SequenceType zeroOrOne()
      Get a sequence type representing zero or one instances of this type
      Specified by:
      zeroOrOne in interface ItemTypeWithSequenceTypeCache
      Returns:
      a sequence type representing zero or one instances of this type
    • oneOrMore

      public SequenceType oneOrMore()
      Get a sequence type representing one or more instances of this type
      Specified by:
      oneOrMore in interface ItemTypeWithSequenceTypeCache
      Returns:
      a sequence type representing one or more instances of this type
    • zeroOrMore

      public SequenceType zeroOrMore()
      Get a sequence type representing one or more instances of this type
      Specified by:
      zeroOrMore in interface ItemTypeWithSequenceTypeCache
      Returns:
      a sequence type representing one or more instances of this type