Class AttributeCollectionImpl

  • All Implemented Interfaces:
    AttributeCollection, Attributes

    public class AttributeCollectionImpl
    extends Object
    implements Attributes, AttributeCollection
    AttributeCollectionImpl is an implementation of both the SAX2 interface Attributes and the Saxon equivalent AttributeCollection.

    As well as providing the information required by the SAX2 interface, an AttributeCollection can hold type information (as needed to support the JAXP 1.3 ValidatorHandler interface), and location information for debugging. The location information is used in the case of attributes on a result tree to identify the location in the query or stylesheet from which they were generated.

    • Constructor Detail

      • AttributeCollectionImpl

        public AttributeCollectionImpl​(Configuration config)
        Create an empty attribute list.
        Parameters:
        config - the Saxon Configuration
    • Method Detail

      • copy

        public static AttributeCollectionImpl copy​(AttributeCollectionImpl atts)
        Create an attribute list as a copy of an existing attribute list
        Parameters:
        atts - the existing attribute list to be copied
        Returns:
        the copied attribute list. Note that if the original attribute list is empty, the method returns the singleton object EMPTY_ATTRIBUTE_COLLECTION; this case must therefore be handled specially if the returned attribute list is to be modified.
      • addAttribute

        public void addAttribute​(NodeName nodeName,
                                 SimpleType type,
                                 String value,
                                 Location locationId,
                                 int properties)
        Add an attribute to an attribute list. The parameters correspond to the parameters of the Receiver.attribute(NodeName, SimpleType, CharSequence, net.sf.saxon.expr.parser.Location, int) method. There is no check that the name of the attribute is distinct from other attributes already in the collection: this check must be made by the caller.
        Parameters:
        nodeName - Object representing the attribute name.
        type - The attribute type
        value - The attribute value (must not be null)
        locationId - Identifies the attribute location.
        properties - Attribute properties
      • setAttribute

        public void setAttribute​(int index,
                                 NodeName nodeName,
                                 SimpleType type,
                                 String value,
                                 Location locationId,
                                 int properties)
        Set (overwrite) an attribute in the attribute list. The parameters correspond to the parameters of the Receiver.attribute(NodeName, SimpleType, CharSequence, net.sf.saxon.expr.parser.Location, int) method.
        Parameters:
        index - Identifies the entry to be replaced. Must be in range (nasty things happen if not)
        nodeName - representing the attribute name.
        type - The attribute type code
        value - The attribute value (must not be null)
        locationId - Identifies the attribtue location.
        properties - Attribute properties
      • clear

        public void clear()
        Clear the attribute list. This removes the values but doesn't free the memory used. free the memory, use clear() then compact().
      • compact

        public void compact()
        Compact the attribute list to avoid wasting memory
      • getLength

        public int getLength()
        Return the number of attributes in the list.
        Specified by:
        getLength in interface AttributeCollection
        Specified by:
        getLength in interface Attributes
        Returns:
        The number of attributes that have been created in this attribute collection. This is the number of slots used in the list, including any slots allocated to attributes that have since been deleted. Such slots are not reused, to preserve attribute identity.
      • getFingerprint

        public int getFingerprint​(int index)
        Get the fingerprint of an attribute (by position).
        Specified by:
        getFingerprint in interface AttributeCollection
        Parameters:
        index - The position of the attribute in the list.
        Returns:
        The display name of the attribute as a string, or -1 if there is no attribute at that position.
      • getNodeName

        public NodeName getNodeName​(int index)
        Get the node name of an attribute (by position).
        Specified by:
        getNodeName in interface AttributeCollection
        Parameters:
        index - The position of the attribute in the list.
        Returns:
        The node name, as a NodeName object, or null if there is no name at this index
      • getTypeAnnotation

        public SimpleType getTypeAnnotation​(int index)
        Get the type of an attribute (by position).
        Specified by:
        getTypeAnnotation in interface AttributeCollection
        Parameters:
        index - The position of the attribute in the list.
        Returns:
        The type annotation
      • getLocation

        public Location getLocation​(int index)
        Get the location of an attribute (by position)
        Specified by:
        getLocation in interface AttributeCollection
        Parameters:
        index - The position of the attribute in the list.
        Returns:
        The location of the attribute. This can be used to obtain the actual system identifier and line number of the relevant location
      • getSystemId

        public String getSystemId​(int index)
        Get the systemId part of the location of an attribute, at a given index.

        Attribute location information is not available from a SAX parser, so this method is not useful for getting the location of an attribute in a source document. However, in a Saxon result document, the location information represents the location in the stylesheet of the instruction used to generate this attribute, which is useful for debugging.

        Specified by:
        getSystemId in interface AttributeCollection
        Parameters:
        index - the required attribute
        Returns:
        the systemId of the location of the attribute
      • getLineNumber

        public int getLineNumber​(int index)
        Get the line number part of the location of an attribute, at a given index.

        Attribute location information is not available from a SAX parser, so this method is not useful for getting the location of an attribute in a source document. However, in a Saxon result document, the location information represents the location in the stylesheet of the instruction used to generate this attribute, which is useful for debugging.

        Specified by:
        getLineNumber in interface AttributeCollection
        Parameters:
        index - the required attribute
        Returns:
        the line number of the location of the attribute
      • getProperties

        public int getProperties​(int index)
        Get the properties of an attribute (by position)
        Specified by:
        getProperties in interface AttributeCollection
        Parameters:
        index - The position of the attribute in the list.
        Returns:
        The properties of the attribute. This is a set of bit-settings defined in class ReceiverOptions. The most interesting of these is {ReceiverOptions.DEFAULTED_ATTRIBUTE, which indicates an attribute that was added to an element as a result of schema validation.
      • getPrefix

        public String getPrefix​(int index)
        Get the prefix of the name of an attribute (by position).
        Specified by:
        getPrefix in interface AttributeCollection
        Parameters:
        index - The position of the attribute in the list.
        Returns:
        The prefix of the attribute name as a string, or null if there is no attribute at that position. Returns "" for an attribute that has no prefix.
      • getQName

        public String getQName​(int index)
        Get the lexical QName of an attribute (by position).
        Specified by:
        getQName in interface AttributeCollection
        Specified by:
        getQName in interface Attributes
        Parameters:
        index - The position of the attribute in the list.
        Returns:
        The lexical QName of the attribute as a string, or null if there is no attribute at that position.
      • getLocalName

        public String getLocalName​(int index)
        Get the local name of an attribute (by position).
        Specified by:
        getLocalName in interface AttributeCollection
        Specified by:
        getLocalName in interface Attributes
        Parameters:
        index - The position of the attribute in the list.
        Returns:
        The local name of the attribute as a string, or null if there is no attribute at that position.
      • getURI

        public String getURI​(int index)
        Get the namespace URI of an attribute (by position).
        Specified by:
        getURI in interface AttributeCollection
        Specified by:
        getURI in interface Attributes
        Parameters:
        index - The position of the attribute in the list.
        Returns:
        The local name of the attribute as a string, or null if there is no attribute at that position.
      • getType

        public String getType​(int index)
        Get the type of an attribute (by position). This is a SAX2 method, so it gets the type name as a DTD attribute type, mapped from the schema type code.
        Specified by:
        getType in interface Attributes
        Parameters:
        index - The position of the attribute in the list.
        Returns:
        The attribute type as a string ("NMTOKEN" for an enumeration, and "CDATA" if no declaration was read), or null if there is no attribute at that position.
      • getType

        public String getType​(String uri,
                              String localname)
        Get the type of an attribute (by name).
        Specified by:
        getType in interface Attributes
        Parameters:
        uri - The namespace uri of the attribute.
        localname - The local name of the attribute.
        Returns:
        The index position of the attribute
      • getValue

        public String getValue​(int index)
        Get the value of an attribute (by position).
        Specified by:
        getValue in interface AttributeCollection
        Specified by:
        getValue in interface Attributes
        Parameters:
        index - The position of the attribute in the list.
        Returns:
        The attribute value as a string, or null if there is no attribute at that position.
      • getValue

        public String getValue​(String uri,
                               String localname)
        Get the value of an attribute (by name).
        Specified by:
        getValue in interface AttributeCollection
        Specified by:
        getValue in interface Attributes
        Parameters:
        uri - The namespace uri of the attribute.
        localname - The local name of the attribute.
        Returns:
        The index position of the attribute
      • getIndex

        public int getIndex​(String qname)
        Get the index of an attribute, from its lexical QName
        Specified by:
        getIndex in interface Attributes
        Parameters:
        qname - The lexical QName of the attribute. The prefix must match.
        Returns:
        The index position of the attribute
      • getIndex

        public int getIndex​(String uri,
                            String localname)
        Get the index of an attribute (by name).
        Specified by:
        getIndex in interface AttributeCollection
        Specified by:
        getIndex in interface Attributes
        Parameters:
        uri - The namespace uri of the attribute.
        localname - The local name of the attribute.
        Returns:
        The index position of the attribute, or -1 if absent
      • getIndexByFingerprint

        public int getIndexByFingerprint​(int fingerprint)
        Get the index, given the fingerprint. Return -1 if not found.
        Specified by:
        getIndexByFingerprint in interface AttributeCollection
      • getType

        public String getType​(String name)
        Get the type of an attribute (by lexical QName).
        Specified by:
        getType in interface Attributes
        Parameters:
        name - The lexical QName of the attribute.
        Returns:
        The attribute type as a string (e.g. "NMTOKEN", or "CDATA" if no declaration was read).
      • getValue

        public String getValue​(String name)
        Get the value of an attribute (by lexnical QName).
        Specified by:
        getValue in interface Attributes
        Parameters:
        name - The attribute name (a lexical QName). The prefix must match the prefix originally used. This method is defined in SAX, but is not recommended except where the prefix is null.
      • hasAttributeInNamespace

        public boolean hasAttributeInNamespace​(String uri)
        Ask whether the attribute collection contains any attributes in a specified namespace
        Parameters:
        uri - the specified namespace
        Returns:
        true if there are one or more attributes in this namespace
      • findByNodeName

        public int findByNodeName​(NodeName nodeName)
        Find an attribute by node name
        Parameters:
        nodeName - the name of the required attribute
        Returns:
        the index of the attribute, or -1 if absent
      • isId

        public boolean isId​(int index)
        Determine whether a given attribute has the is-ID property set
        Specified by:
        isId in interface AttributeCollection
      • isIdref

        public boolean isIdref​(int index)
        Determine whether a given attribute has the is-idref property set
        Specified by:
        isIdref in interface AttributeCollection
      • removeAttribute

        public void removeAttribute​(int index)
        Delete the attribute at a given index position. Note that the index position will not be reused, to ensure that any new attributes added to the element have a distinct identity. Instead, the slot occupied by the attribute is nilled out.
        Parameters:
        index - The index position of the attribute to be removed
      • isDeleted

        public boolean isDeleted​(int index)
        Test whether the attribute at a given index has been deleted
        Parameters:
        index - the index position of the (ex-) attribute
        Returns:
        true if the attribute has been deleted
      • renameAttribute

        public void renameAttribute​(int index,
                                    NodeName newName)
        Rename an attribute
        Parameters:
        index - the index position of the attribute
        newName - the namecode of the new name
      • replaceAttribute

        public void replaceAttribute​(int index,
                                     CharSequence newValue)
        Replace the value of an attribute
        Parameters:
        index - position of the attribute
        newValue - the new string value of the attribute
      • setTypeAnnotation

        public void setTypeAnnotation​(int index,
                                      SimpleType type)
        Set the type annotation of an attribute
        Parameters:
        index - the index position of the attribute node
        type - the new type for the attribute
      • swap

        public void swap​(int i,
                         int j)
        Swap two attributes (used for sorting)
        Parameters:
        i - the position of one value
        j - the position of the other value