net.sf.saxon.om

Class AttributeCollectionImpl

public final 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 javax.xml.validation.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 AttributeCollectionEMPTY_ATTRIBUTE_COLLECTION
Constructor Summary
AttributeCollectionImpl(NamePool pool)
Create an empty attribute list.
Method Summary
voidaddAttribute(int nameCode, int typeCode, String value, int locationId, int properties)
Add an attribute to an attribute list.
voidclear()
Clear the attribute list.
voidcompact()
Compact the attribute list to avoid wasting memory
intgetIndex(String qname)
Get the index of an attribute, from its lexical QName
intgetIndex(String uri, String localname)
Get the index of an attribute (by name).
intgetIndexByFingerprint(int fingerprint)
Get the index, given the fingerprint.
intgetLength()
Return the number of attributes in the list.
intgetLineNumber(int index)
Get the line number part of the location of an attribute, at a given index.
StringgetLocalName(int index)
Get the local name of an attribute (by position).
intgetLocationId(int index)
Get the locationID of an attribute (by position)
intgetNameCode(int index)
Get the namecode of an attribute (by position).
StringgetPrefix(int index)
Get the prefix of the name of an attribute (by position).
intgetProperties(int index)
Get the properties of an attribute (by position)
StringgetQName(int index)
Get the lexical QName of an attribute (by position).
StringgetSystemId(int index)
Get the systemId part of the location of an attribute, at a given index.
StringgetType(int index)
Get the type of an attribute (by position).
StringgetType(String uri, String localname)
Get the type of an attribute (by name).
StringgetType(String name)
Get the type of an attribute (by lexical QName).
intgetTypeAnnotation(int index)
Get the namecode of an attribute (by position).
StringgetURI(int index)
Get the namespace URI of an attribute (by position).
StringgetValue(int index)
Get the value of an attribute (by position).
StringgetValue(String uri, String localname)
Get the value of an attribute (by name).
StringgetValue(String name)
Get the value of an attribute (by lexical QName).
StringgetValueByFingerprint(int fingerprint)
Get the attribute value using its fingerprint
booleanisId(int index)
Determine whether a given attribute has the is-ID property set
voidsetAttribute(int index, int nameCode, int typeCode, String value, int locationId, int properties)
Set (overwrite) an attribute in the attribute list.
voidsetLocationProvider(LocationProvider provider)
Set the location provider.

Field Detail

EMPTY_ATTRIBUTE_COLLECTION

public static final AttributeCollection EMPTY_ATTRIBUTE_COLLECTION

Constructor Detail

AttributeCollectionImpl

public AttributeCollectionImpl(NamePool pool)
Create an empty attribute list.

Method Detail

addAttribute

public void addAttribute(int nameCode, int typeCode, String value, int locationId, int properties)
Add an attribute to an attribute list. The parameters correspond to the parameters of the Receiver 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

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

getIndex

public int getIndex(String qname)
Get the index of an attribute, from its lexical QName

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).

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.

getLength

public int getLength()
Return the number of attributes in the list.

Returns: The number of attributes in the list.

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.

Parameters: index the required attribute

Returns: the line number of the location of the attribute

getLocalName

public String getLocalName(int index)
Get the local name of an attribute (by position).

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.

getLocationId

public int getLocationId(int index)
Get the locationID of an attribute (by position)

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

getNameCode

public int getNameCode(int index)
Get the namecode of an attribute (by position).

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.

getPrefix

public String getPrefix(int index)
Get the prefix of the name of an attribute (by position).

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.

getProperties

public int getProperties(int index)
Get the properties of an attribute (by position)

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 {DEFAULTED_ATTRIBUTE, which indicates an attribute that was added to an element as a result of schema validation.

getQName

public String getQName(int index)
Get the lexical QName of an attribute (by position).

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.

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.

Parameters: index the required attribute

Returns: the systemId of the location of the attribute

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.

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).

Parameters: uri The namespace uri of the attribute. localname The local name of the attribute.

Returns: The index position of the attribute

getType

public String getType(String name)
Get the type of an attribute (by lexical QName).

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).

getTypeAnnotation

public int getTypeAnnotation(int index)
Get the namecode of an attribute (by position).

Parameters: index The position of the attribute in the list.

Returns: The type annotation, as the fingerprint of the type name. The bit net.sf.saxon.om.NodeInfo.IS_DTD_TYPE represents a DTD-derived type.

getURI

public String getURI(int index)
Get the namespace URI of an attribute (by position).

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.

getValue

public String getValue(int index)
Get the value of an attribute (by position).

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).

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(String name)
Get the value of an attribute (by lexical QName).

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.

getValueByFingerprint

public String getValueByFingerprint(int fingerprint)
Get the attribute value using its fingerprint

isId

public boolean isId(int index)
Determine whether a given attribute has the is-ID property set

setAttribute

public void setAttribute(int index, int nameCode, int typeCode, String value, int locationId, int properties)
Set (overwrite) an attribute in the attribute list. The parameters correspond to the parameters of the Receiver 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

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.