Class NamedXNodeType

All Implemented Interfaces:
NamedXNodePredicate, NodePredicate, NodeTest, NodeVectorMatchMaker, ItemType, ItemTypeWithSequenceTypeCache

public class NamedXNodeType extends XNodeType implements NamedXNodePredicate, NodeVectorMatchMaker
NamedXNodeType is a node type corresponding to the syntax element(N, T) or attribute(N, T) or namespace(N) or processing-instruction(N).

It tests for a node of a particular kind, whose name matches a QNameTest (which embraces wildcards and choices) and whose type annotation matches a given schema type; it is also conditional on whether the node is nilled.

A NamedXNodeType is tied to one Configuration, which means it cannot be used in the signature of a built-in function, as these are shared across configurations. An alternative is therefore available in the class PortableNamedXNodeType.

  • Constructor Details

    • NamedXNodeType

      public NamedXNodeType(int nodeKind, QNameTest nameTest, SchemaType schemaType, boolean nillable, Configuration config)
      Create an NamedNodeKindType
      Parameters:
      nodeKind - the kind of nodes to be matched: always elements or attributes
      nameTest - constrains the name of the node
      schemaType - the required type annotation, as a simple or complex schema type
      nillable - indicates whether an element with xsi:nil=true satisifies the test
      config - the Configuration, supplied because this KindTest needs access to schema information
    • NamedXNodeType

      public NamedXNodeType(int nodeKind, QNameTest nameTest, Configuration config)
      Simplified convenience constructor
      Parameters:
      nodeKind - the kind of nodes to be matched: always elements or attributes
      nameTest - constrains the name of the node
      config - the Configuration, supplied because this KindTest needs access to schema information
    • NamedXNodeType

      public NamedXNodeType(int nodeKind, StructuredQName nameTest, Configuration config)
      Simplified convenience constructor
      Parameters:
      nodeKind - the kind of nodes to be matched: always elements or attributes
      nameTest - constrains the name of the node
      config - the Configuration, supplied because this KindTest needs access to schema information
  • Method Details

    • make

      public static NodeTest make(int nodeKind, NamespaceUri uri, String localName, Configuration config)
    • make

      public static NodeTest make(int nodeKind, int fingerprint, Configuration config)
    • setImplicitSchemaType

      public void setImplicitSchemaType(boolean implicitSchemaType)
      Say that the schema type is implicit. As an item type, element(E) and element(E, xs:anyType?) are equivalent, but as XSLT patterns, they have different default priority, and therefore need to be distinguished. If the schema type was omitted in the pattern we set implicitType to true, and this affects the calculation of a default priority.
      Parameters:
      implicitSchemaType - true if the node test in a pattern did not contain an explicit schema type
    • 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
      Overrides:
      getUType in class XNodeType
      Returns:
      the smallest UType that subsumes this item 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
      Overrides:
      getQNameTest in class GNodeType
      Returns:
      the strongest possible QNameTest
    • getAllowedNodeNames

      public QNameTest getAllowedNodeNames()
      Get the set of allowed node names that this type if capable of matching
      Specified by:
      getAllowedNodeNames in class XNodeType
      Returns:
      the allowed node names
    • getRequiredFingerprint

      public int getRequiredFingerprint()
      For an XNodeType that can only match one kind of node and one node name, return that node name, as an integer fingerprint. In other cases, return -1.
      Specified by:
      getRequiredFingerprint in interface NamedXNodePredicate
      Returns:
      an integer fingerprint in the case of a node type that only matches one node kind and one qualified name. In other cases return -1.
    • getPrimitiveItemType

      public ItemType getPrimitiveItemType()
      Description copied from class: GNodeType
      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
      Overrides:
      getPrimitiveItemType in class GNodeType
      Returns:
      the corresponding primitive type
    • getMatchingNodeName

      public StructuredQName getMatchingNodeName()
      Get the corresponding StructuredQName: the name that all nodes must have if they are to satisfy the predicate
      Specified by:
      getMatchingNodeName in interface NamedXNodePredicate
      Returns:
      if all nodes selected by the node test are of the required nodeKind, and have the same name, then return that name; otherwise return null.
    • isFingerprintSufficient

      public boolean isFingerprintSufficient()
      Ask whether having the required fingerprint and node kind is a sufficient condition for a node to satisfy the predicate, or whether other conditions (such as type annotation or nillability) must also be satisfied.
      Specified by:
      isFingerprintSufficient in interface NamedXNodePredicate
      Returns:
      true if matching the fingerprint is a sufficient condition.
    • getConfiguration

      public Configuration getConfiguration()
      Get the Saxon Configuration to which this type belongs
      Returns:
      the Saxon configuration
    • isNillable

      public boolean isNillable()
      The test is nillable if a question mark was specified as the occurrence indicator
      Specified by:
      isNillable in interface NodeTest
      Overrides:
      isNillable in class XNodeType
      Returns:
      true if the test is nillable
    • getContentType

      public SchemaType getContentType()
      Description copied from class: XNodeType
      Get the allowed content type permitted by this item type. Defaults to allowing any content
      Overrides:
      getContentType in class XNodeType
      Returns:
      the allowed content type
    • getNodeKind

      public int getNodeKind()
      Description copied from interface: NamedXNodePredicate
      Get the kind of nodes that this node predicate matches
      Specified by:
      getNodeKind in interface NamedXNodePredicate
      Returns:
      the kind of nodes, for example Type.ELEMENT or net.sf.saxon.type.Type#ATTRIBUTE
    • matches

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

      public IntPredicate getMatcher(NodeVectorTree tree)
      Get a matching function that can be used to test whether numbered nodes in a TinyTree or DominoTree satisfy the node test. (Calling this matcher must give the same result as calling matchesNode(tree.getNode(nodeNr)), but it may well be faster).
      Specified by:
      getMatcher in interface NodeVectorMatchMaker
      Parameters:
      tree - the tree against which the returned function will operate
      Returns:
      an IntPredicate; the matches() method of this predicate takes a node number as input, and returns true if and only if the node identified by this node number matches the node predicate.
    • getDefaultPriority

      public final double getDefaultPriority()
      Determine the default priority of this node test when used on its own as a Pattern
      Specified by:
      getDefaultPriority in interface ItemType
      Specified by:
      getDefaultPriority in interface NodeTest
      Returns:
      the default priority
    • getPrimitiveType

      public int getPrimitiveType()
      Determine the types of nodes to which this pattern applies. Used for optimisation.
      Specified by:
      getPrimitiveType in interface ItemType
      Overrides:
      getPrimitiveType in class GNodeType
      Returns:
      the type of node matched by this pattern. e.g. Type.ELEMENT or Type.TEXT
    • getAtomizedItemType

      public AtomicType getAtomizedItemType()
      Get the item type of the atomic values that will be produced when an item of this type is atomized (assuming that atomization succeeds)
      Specified by:
      getAtomizedItemType in interface ItemType
      Overrides:
      getAtomizedItemType in class GNodeType
      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
      Overrides:
      isAtomizable in class GNodeType
      Parameters:
      th - The type hierarchy cache
      Returns:
      true unless it is known that these items will be elements with element-only content, in which case return false
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toExportString

      public 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().
      Specified by:
      toExportString in interface ItemType
      Returns:
      the string representation as an instance of the XPath SequenceType construct
    • hashCode

      public int hashCode()
      Returns a hash code value for the object.
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object other)
      Indicates whether some other object is "equal to" this one.
      Overrides:
      equals in class Object
    • normalizeItemType

      public ItemType normalizeItemType()
      Description copied from interface: ItemType
      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().

      Specified by:
      normalizeItemType in interface ItemType
      Returns:
      the normalized item type.
    • 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
      Overrides:
      explainMismatch in class GNodeType
      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
    • getBasicAlphaCode

      public 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.
      Specified by:
      getBasicAlphaCode in interface ItemType
      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".