## net.sf.saxon.om
Class AttributeCollectionImpl

    java.lang.Object
      net.sf.saxon.om.AttributeCollectionImpl

All Implemented Interfaces:
  AttributeCollection, org.xml.sax.Attributes

    public final class AttributeCollectionImpl

extends java.lang.Object
implements org.xml.sax.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.

Field Summary
`static AttributeCollection` `EMPTY_ATTRIBUTE_COLLECTION`

Constructor Summary
`AttributeCollectionImpl(Configuration config)` Create an empty attribute list.

Method Summary
`void` `addAttribute(int nameCode, int typeCode, java.lang.String value, long locationId, int properties)` Add an attribute to an attribute list.
`void` `clear()` Clear the attribute list.
`void` `compact()` Compact the attribute list to avoid wasting memory
`int` `getIndex(java.lang.String qname)` Get the index of an attribute, from its lexical QName
`int` `getIndex(java.lang.String uri, java.lang.String localname)` Get the index of an attribute (by name).
`int` `getIndexByFingerprint(int fingerprint)` Get the index, given the fingerprint.
`int` `getLength()` Return the number of attributes in the list.
`int` `getLineNumber(int index)` Get the line number part of the location of an attribute, at a given index.
`java.lang.String` `getLocalName(int index)` Get the local name of an attribute (by position).
`int` `getLocationId(int index)` Get the locationID of an attribute (by position)
`int` `getNameCode(int index)` Get the namecode of an attribute (by position).
`java.lang.String` `getPrefix(int index)` Get the prefix of the name of an attribute (by position).
`int` `getProperties(int index)` Get the properties of an attribute (by position)
`java.lang.String` `getQName(int index)` Get the lexical QName of an attribute (by position).
`java.lang.String` `getSystemId(int index)` Get the systemId part of the location of an attribute, at a given index.
`java.lang.String` `getType(int index)` Get the type of an attribute (by position).
`java.lang.String` `getType(java.lang.String name)` Get the type of an attribute (by lexical QName).
`java.lang.String` `getType(java.lang.String uri, java.lang.String localname)` Get the type of an attribute (by name).
`int` `getTypeAnnotation(int index)` Get the namecode of an attribute (by position).
`java.lang.String` `getURI(int index)` Get the namespace URI of an attribute (by position).
`java.lang.String` `getValue(int index)` Get the value of an attribute (by position).
`java.lang.String` `getValue(java.lang.String name)` Get the value of an attribute (by lexical QName).
`java.lang.String` `getValue(java.lang.String uri, java.lang.String localname)` Get the value of an attribute (by name).
`java.lang.String` `getValueByFingerprint(int fingerprint)` Get the attribute value using its fingerprint
`boolean` `isId(int index)` Determine whether a given attribute has the is-ID property set
`boolean` `isIdref(int index)` Determine whether a given attribute has the is-idref property set
`void` `removeAttribute(int fingerprint)` Delete the attribute with a given fingerprint
`void` `renameAttribute(int oldName, int newName)` Rename an attribute
`void` `replaceAttribute(int nameCode, java.lang.CharSequence newValue)` Replace the value of an attribute
`void` `setAttribute(int index, int nameCode, int typeCode, java.lang.String value, long locationId, int properties)` Set (overwrite) an attribute in the attribute list.
`void` `setLocationProvider(LocationProvider provider)` Set the location provider.
`void` `setTypeAnnotation(int nameCode, int typeCode)` Set the type annotation of an attribute

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### EMPTY_ATTRIBUTE_COLLECTION

    public static final AttributeCollection EMPTY_ATTRIBUTE_COLLECTION

Constructor Detail

### AttributeCollectionImpl

    public AttributeCollectionImpl(Configuration config)

  Create an empty attribute list.

  Parameters:
    `config` - the Saxon Configuration

Method Detail

### setLocationProvider

    public void setLocationProvider(LocationProvider provider)

  Set the location provider. This must be set if the methods getSystemId() and getLineNumber() are to be used to get location information for an attribute.

  Parameters:
    `provider` - the location provider

### addAttribute

    public void addAttribute(int nameCode,
                             int typeCode,
                             java.lang.String value,
                             long locationId,
                             int properties)

  Add an attribute to an attribute list. The parameters correspond to the parameters of the `Receiver.attribute(int,int,CharSequence,int,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:
    `nameCode` - Integer representing the attribute name.
    `typeCode` - The attribute type code
    `value` - The attribute value (must not be null)
    `locationId` - Identifies the attribtue location.
    `properties` - Attribute properties

### setAttribute

    public void setAttribute(int index,
                             int nameCode,
                             int typeCode,
                             java.lang.String value,
                             long locationId,
                             int properties)

  Set (overwrite) an attribute in the attribute list. The parameters correspond to the parameters of the `Receiver.attribute(int,int,CharSequence,int,int)` method.

  Parameters:
    `index` - Identifies the entry to be replaced
    `nameCode` - Integer representing the attribute name.
    `typeCode` - 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 `org.xml.sax.Attributes`
  Returns:
    The number of attributes in the list.

### getNameCode

    public int getNameCode(int index)

  Get the namecode of an attribute (by position).

  Specified by:
    `getNameCode` in interface `AttributeCollection`
  Parameters:
    `index` - The position of the attribute in the list.
  Returns:
    The display name of the attribute as a string, or null if there is no attribute at that position.

### getTypeAnnotation

    public int getTypeAnnotation(int index)

  Get the namecode 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, as the fingerprint of the type name. The bit `NodeInfo.IS_DTD_TYPE` represents a DTD-derived type.

### getLocationId

    public int getLocationId(int index)

  Get the locationID of an attribute (by position)

  Specified by:
    `getLocationId` in interface `AttributeCollection`
  Parameters:
    `index` - The position of the attribute in the list.
  Returns:
    The location identifier of the attribute. This can be supplied to a `LocationProvider` in order to obtain the actual system identifier and line number of the relevant location

### getSystemId

    public java.lang.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 java.lang.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 java.lang.String getQName(int index)

  Get the lexical QName of an attribute (by position).

  Specified by:
    `getQName` in interface `AttributeCollection`
  Specified by:
    `getQName` in interface `org.xml.sax.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 java.lang.String getLocalName(int index)

  Get the local name of an attribute (by position).

  Specified by:
    `getLocalName` in interface `AttributeCollection`
  Specified by:
    `getLocalName` in interface `org.xml.sax.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 java.lang.String getURI(int index)

  Get the namespace URI of an attribute (by position).

  Specified by:
    `getURI` in interface `AttributeCollection`
  Specified by:
    `getURI` in interface `org.xml.sax.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 java.lang.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 `org.xml.sax.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 java.lang.String getType(java.lang.String uri,
                                    java.lang.String localname)

  Get the type of an attribute (by name).

  Specified by:
    `getType` in interface `org.xml.sax.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 java.lang.String getValue(int index)

  Get the value of an attribute (by position).

  Specified by:
    `getValue` in interface `AttributeCollection`
  Specified by:
    `getValue` in interface `org.xml.sax.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 java.lang.String getValue(java.lang.String uri,
                                     java.lang.String localname)

  Get the value of an attribute (by name).

  Specified by:
    `getValue` in interface `AttributeCollection`
  Specified by:
    `getValue` in interface `org.xml.sax.Attributes`
  Parameters:
    `uri` - The namespace uri of the attribute.
    `localname` - The local name of the attribute.
  Returns:
    The index position of the attribute

### getValueByFingerprint

    public java.lang.String getValueByFingerprint(int fingerprint)

  Get the attribute value using its fingerprint

  Specified by:
    `getValueByFingerprint` in interface `AttributeCollection`

### getIndex

    public int getIndex(java.lang.String qname)

  Get the index of an attribute, from its lexical QName

  Specified by:
    `getIndex` in interface `org.xml.sax.Attributes`
  Parameters:
    `qname` - The lexical QName of the attribute. The prefix must match.
  Returns:
    The index position of the attribute

### getIndex

    public int getIndex(java.lang.String uri,
                        java.lang.String localname)

  Get the index of an attribute (by name).

  Specified by:
    `getIndex` in interface `AttributeCollection`
  Specified by:
    `getIndex` in interface `org.xml.sax.Attributes`
  Parameters:
    `uri` - The namespace uri of the attribute.
    `localname` - The local name of the attribute.
  Returns:
    The index position of the attribute

### 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 java.lang.String getType(java.lang.String name)

  Get the type of an attribute (by lexical QName).

  Specified by:
    `getType` in interface `org.xml.sax.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 java.lang.String getValue(java.lang.String name)

  Get the value of an attribute (by lexical QName).

  Specified by:
    `getValue` in interface `org.xml.sax.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.

### 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 fingerprint)

  Delete the attribute with a given fingerprint

  Parameters:
    `fingerprint` - The fingerprint of the attribute to be removed

### renameAttribute

    public void renameAttribute(int oldName,
                                int newName)

  Rename an attribute

  Parameters:
    `oldName` - the namecode of the existing name
    `newName` - the namecode of the new name

### replaceAttribute

    public void replaceAttribute(int nameCode,
                                 java.lang.CharSequence newValue)

  Replace the value of an attribute

  Parameters:
    `nameCode` - the name code of the attribute name
    `newValue` - the new string value of the attribute

### setTypeAnnotation

    public void setTypeAnnotation(int nameCode,
                                  int typeCode)

  Set the type annotation of an attribute

  Parameters:
    `nameCode` - the name code of the attribute name
    `typeCode` - the new type code for the attribute

Copyright (c) Saxonica Limited. All rights reserved.