org.apache.xerces.framework
Class XMLAttrList

java.lang.Object
  |
  +--org.apache.xerces.framework.XMLAttrList
All Implemented Interfaces:
AttributeList

public final class XMLAttrList
extends java.lang.Object
implements AttributeList

An instance of this class is used to represent the set of attributes for an element that are either directly specified or provided through a default value in the grammar for the document. XMLAttrList carries the attributes associated with an element from the scanner up to the application level (via the SAX AtributeList). Because all the attributes are bundled up together before being presented to the application, we don't have a way to build up an attribute value from pieces, most notably entity references.

There is typically one instance of this class for each instance of a parser. The parser may either use this object to hold the attributes of a single element, calling releaseAttrList() before each new element, or it may use this object to hold the attributes of all of the elements in the document.

To start saving a new set of attributes, the startAttrList() method is called, returning a handle for the attribute list. All addAttr() calls will be added to the set until a call is made to endAttrList(). A handle of -1 is used to indicate that there are no attributes in the set.

When an attribute is added to the set, the type of the attribute and an indicator of whether it was specified explicitly or through a default is provided.

The attributes in the set may be accessed either through the getFirstAttr() and getNextAttr() iteration interface, or the getAttributeList() method may be used to access the attribute list through the SAX AttributeList interface.

Version:
$Id: XMLAttrList.java 317378 2001-07-20 17:27:54Z lmartin $

Constructor Summary
XMLAttrList(StringPool stringPool)
          Constructor
 
Method Summary
 int addAttr(int attrName, int attValue, int attType, boolean specified, boolean search)
           
 int addAttr(QName attribute, int attValue, int attType, boolean specified, boolean search)
          Add an attribute to the current set.
 int[] endAttrList()
          Terminate the current set of attributes.
 AttributeList getAttributeList(int attrListHandle)
          Setup this instance to respond as an AttributeList implementation.
 int getAttrLocalpart(int attrIndex)
          Return the localpart of the attribute.
 int getAttrName(int attrIndex)
          Get the name of the attribute
 int getAttrPrefix(int attrIndex)
          Get the prefix of the attribute.
 int getAttrURI(int attrIndex)
          Return the uri of the attribute.
 int getAttType(int attrIndex)
          Get the type of the attribute
 int getAttValue(int attrIndex)
          Get the value of the attribute
 int getFirstAttr(int attrListHandle)
          Get the first attribute in the attribute list.
 int getLength()
          Return the number of attributes in this list.
 java.lang.String getLocalpart(int i)
          Return the local part of an attribute in this list (by position).
 java.lang.String getName(int i)
          Return the name of an attribute in this list (by position).
 int getNextAttr(int attrIndex)
          Get the next attribute in the attribute list.
 java.lang.String getPrefix(int i)
          Return the prefix of an attribute in this list (by position).
 java.lang.String getType(int i)
          Return the type of an attribute in the list (by position).
 java.lang.String getType(java.lang.String name)
          Return the type of an attribute in the list (by name).
 java.lang.String getURI(int i)
          Returns the URI of an attribute in this list (by position).
 java.lang.String getValue(int i)
          Return the value of an attribute in the list (by position).
 java.lang.String getValue(java.lang.String name)
          Return the value of an attribute in the list (by name).
 boolean isSpecified(int attrIndex)
          Was the attribute explicitly supplied or was it provided through a default?
 void releaseAttrList(int attrListHandle)
          Make the resources of the current attribute list available for reuse.
 void reset(StringPool stringPool)
          Reset this instance to an "empty" state.
 void setAttrURI(int attrIndex, int uri)
          Sets the uri of the attribute.
 void setAttType(int attrIndex, int attTypeIndex)
          Sets the type of the attribute.
 void setAttValue(int attrIndex, int attrValue)
          Sets the value of the attribute.
 int startAttrList()
          Start a new set of attributes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLAttrList

public XMLAttrList(StringPool stringPool)
Constructor
Parameters:
stringPool - The string pool instance to use.
Method Detail

reset

public void reset(StringPool stringPool)
Reset this instance to an "empty" state.
Parameters:
stringPool - The string pool instance to use.

addAttr

public int addAttr(int attrName,
                   int attValue,
                   int attType,
                   boolean specified,
                   boolean search)
            throws java.lang.Exception

addAttr

public int addAttr(QName attribute,
                   int attValue,
                   int attType,
                   boolean specified,
                   boolean search)
            throws java.lang.Exception
Add an attribute to the current set.
Parameters:
attrName - The name of the attribute, an index in the string pool.
attValue - The value of the attribute, an index in the string pool.
attType - The type of the attribute, an index in the string pool.
specified - true if the attribute is specified directly; otherwise false is the attribute is provided through a default.
search - true if the list should be searched for a duplicate.
Returns:
The index of this attribute; or -1 is search was true and attrName was already present.

startAttrList

public int startAttrList()
Start a new set of attributes.
Returns:
The handle for the new set of attributes.

endAttrList

public int[] endAttrList()
Terminate the current set of attributes.

getAttrPrefix

public int getAttrPrefix(int attrIndex)
Get the prefix of the attribute.

getAttrLocalpart

public int getAttrLocalpart(int attrIndex)
Return the localpart of the attribute.

getAttrName

public int getAttrName(int attrIndex)
Get the name of the attribute
Parameters:
attrIndex - The index of the attribute.
Returns:
The name of the attribute, an index in the string pool.

setAttrURI

public void setAttrURI(int attrIndex,
                       int uri)
Sets the uri of the attribute.

getAttrURI

public int getAttrURI(int attrIndex)
Return the uri of the attribute.

getAttValue

public int getAttValue(int attrIndex)
Get the value of the attribute
Parameters:
attrIndex - The index of the attribute.
Returns:
The value of the attribute, an index in the string pool.

setAttValue

public void setAttValue(int attrIndex,
                        int attrValue)
Sets the value of the attribute.

setAttType

public void setAttType(int attrIndex,
                       int attTypeIndex)
Sets the type of the attribute.

getAttType

public int getAttType(int attrIndex)
Get the type of the attribute
Parameters:
attrIndex - The index of the attribute.
Returns:
The type of the attribute, an index in the string pool.

isSpecified

public boolean isSpecified(int attrIndex)
Was the attribute explicitly supplied or was it provided through a default?
Parameters:
attrIndex - The index of the attribute.
Returns:
true if the attribute was specified directly; otherwise false is the attribute was provided through a default.

releaseAttrList

public void releaseAttrList(int attrListHandle)
Make the resources of the current attribute list available for reuse.
Parameters:
The - attribute list handle.

getFirstAttr

public int getFirstAttr(int attrListHandle)
Get the first attribute in the attribute list.
Parameters:
attrListHandle - The attribute list handle.
Returns:
The index of the first attribute in the specified attribute list or -1 if the handle is invalid.

getNextAttr

public int getNextAttr(int attrIndex)
Get the next attribute in the attribute list.
Parameters:
attrIndex - The attribute index.
Returns:
The index of the next attribute after attrIndex in the same attribute list or -1 if there is no next index.

getAttributeList

public AttributeList getAttributeList(int attrListHandle)
Setup this instance to respond as an AttributeList implementation.
Returns:
This instance as an AttributeList.

getLength

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

The SAX parser may provide attributes in any arbitrary order, regardless of the order in which they were declared or specified. The number of attributes may be zero.

Specified by:
getLength in interface AttributeList
Returns:
The number of attributes in the list.

getPrefix

public java.lang.String getPrefix(int i)
Return the prefix of an attribute in this list (by position).

getLocalpart

public java.lang.String getLocalpart(int i)
Return the local part of an attribute in this list (by position).

getName

public java.lang.String getName(int i)
Return the name of an attribute in this list (by position).

The names must be unique: the SAX parser shall not include the same attribute twice. Attributes without values (those declared #IMPLIED without a value specified in the start tag) will be omitted from the list.

If the attribute name has a namespace prefix, the prefix will still be attached.

Specified by:
getName in interface AttributeList
Parameters:
i - The index of the attribute in the list (starting at 0).
Returns:
The name of the indexed attribute, or null if the index is out of range.
See Also:
getLength()

getURI

public java.lang.String getURI(int i)
Returns the URI of an attribute in this list (by position).

getType

public java.lang.String getType(int i)
Return the type of an attribute in the list (by position).

The attribute type is one of the strings "CDATA", "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES", or "NOTATION" (always in upper case).

If the parser has not read a declaration for the attribute, or if the parser does not report attribute types, then it must return the value "CDATA" as stated in the XML 1.0 Recommentation (clause 3.3.3, "Attribute-Value Normalization").

For an enumerated attribute that is not a notation, the parser will report the type as "NMTOKEN".

Specified by:
getType in interface AttributeList
Parameters:
i - The index of the attribute in the list (starting at 0).
Returns:
The attribute type as a string, or null if the index is out of range.
See Also:
getLength(), getType(java.lang.String)

getValue

public java.lang.String getValue(int i)
Return the value of an attribute in the list (by position).

If the attribute value is a list of tokens (IDREFS, ENTITIES, or NMTOKENS), the tokens will be concatenated into a single string separated by whitespace.

Specified by:
getValue in interface AttributeList
Parameters:
i - The index of the attribute in the list (starting at 0).
Returns:
The attribute value as a string, or null if the index is out of range.
See Also:
getLength(), getValue(java.lang.String)

getType

public java.lang.String getType(java.lang.String name)
Return the type of an attribute in the list (by name).

The return value is the same as the return value for getType(int).

If the attribute name has a namespace prefix in the document, the application must include the prefix here.

Specified by:
getType in interface AttributeList
Parameters:
name - The name of the attribute.
Returns:
The attribute type as a string, or null if no such attribute exists.
See Also:
getType(int)

getValue

public java.lang.String getValue(java.lang.String name)
Return the value of an attribute in the list (by name).

The return value is the same as the return value for getValue(int).

If the attribute name has a namespace prefix in the document, the application must include the prefix here.

Specified by:
getValue in interface AttributeList
Parameters:
i - The index of the attribute in the list.
Returns:
The attribute value as a string, or null if no such attribute exists.
See Also:
getValue(int)


Copyright © 1999-2001 Apache XML Project. All Rights Reserved.