org.apache.xml.serializer
Class AttributesImplSerializer

java.lang.Object
  extended by org.xml.sax.helpers.AttributesImpl
      extended by org.apache.xml.serializer.AttributesImplSerializer
All Implemented Interfaces:
org.xml.sax.Attributes

public final class AttributesImplSerializer
extends org.xml.sax.helpers.AttributesImpl

This class extends org.xml.sax.helpers.AttributesImpl which implements org. xml.sax.Attributes. But for optimization this class adds a Hashtable for faster lookup of an index by qName, which is commonly done in the stream serializer.

See Also:
Attributes

Field Summary
private  java.lang.StringBuffer m_buff
           
private  java.util.Hashtable m_indexFromQName
          Hash table of qName/index values to quickly lookup the index of an attributes qName.
private static int MAX
          This is the number of attributes before switching to the hash table, and can be tuned, but 12 seems good for now - Brian M.
private static int MAXMinus1
          One less than the number of attributes before switching to the Hashtable.
 
Constructor Summary
AttributesImplSerializer()
           
 
Method Summary
 void addAttribute(java.lang.String uri, java.lang.String local, java.lang.String qname, java.lang.String type, java.lang.String val)
          This method adds the attribute, but also records its qName/index pair in the hashtable for fast lookup by getIndex(qName).
 void clear()
          This method clears the accumulated attributes.
 int getIndex(java.lang.String qname)
          This method gets the index of an attribute given its qName.
 int getIndex(java.lang.String uri, java.lang.String localName)
          This method gets the index of an attribute given its uri and locanName.
 void setAttributes(org.xml.sax.Attributes atts)
          This method sets the attributes, previous attributes are cleared, it also keeps the hashtable up to date for quick lookup via getIndex(qName).
private  void switchOverToHash(int numAtts)
          We are switching over to having a hash table for quick look up of attributes, but up until now we haven't kept any information in the Hashtable, so we now update the Hashtable.
 
Methods inherited from class org.xml.sax.helpers.AttributesImpl
getLength, getLocalName, getQName, getType, getType, getType, getURI, getValue, getValue, getValue, removeAttribute, setAttribute, setLocalName, setQName, setType, setURI, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_indexFromQName

private final java.util.Hashtable m_indexFromQName
Hash table of qName/index values to quickly lookup the index of an attributes qName. qNames are in uppercase in the hash table to make the search case insensitive. The keys to the hashtable to find the index are either "prefix:localName" or "{uri}localName".


m_buff

private final java.lang.StringBuffer m_buff

MAX

private static final int MAX
This is the number of attributes before switching to the hash table, and can be tuned, but 12 seems good for now - Brian M.

See Also:
Constant Field Values

MAXMinus1

private static final int MAXMinus1
One less than the number of attributes before switching to the Hashtable.

See Also:
Constant Field Values
Constructor Detail

AttributesImplSerializer

public AttributesImplSerializer()
Method Detail

getIndex

public final int getIndex(java.lang.String qname)
This method gets the index of an attribute given its qName.

Specified by:
getIndex in interface org.xml.sax.Attributes
Overrides:
getIndex in class org.xml.sax.helpers.AttributesImpl
Parameters:
qname - the qualified name of the attribute, e.g. "prefix1:locName1"
Returns:
the integer index of the attribute.
See Also:
Attributes.getIndex(String)

addAttribute

public final void addAttribute(java.lang.String uri,
                               java.lang.String local,
                               java.lang.String qname,
                               java.lang.String type,
                               java.lang.String val)
This method adds the attribute, but also records its qName/index pair in the hashtable for fast lookup by getIndex(qName).

Overrides:
addAttribute in class org.xml.sax.helpers.AttributesImpl
Parameters:
uri - the URI of the attribute
local - the local name of the attribute
qname - the qualified name of the attribute
type - the type of the attribute
val - the value of the attribute
See Also:
AttributesImpl.addAttribute(String, String, String, String, String), getIndex(String)

switchOverToHash

private void switchOverToHash(int numAtts)
We are switching over to having a hash table for quick look up of attributes, but up until now we haven't kept any information in the Hashtable, so we now update the Hashtable. Future additional attributes will update the Hashtable as they are added.

Parameters:
numAtts -

clear

public final void clear()
This method clears the accumulated attributes.

Overrides:
clear in class org.xml.sax.helpers.AttributesImpl
See Also:
AttributesImpl.clear()

setAttributes

public final void setAttributes(org.xml.sax.Attributes atts)
This method sets the attributes, previous attributes are cleared, it also keeps the hashtable up to date for quick lookup via getIndex(qName).

Overrides:
setAttributes in class org.xml.sax.helpers.AttributesImpl
Parameters:
atts - the attributes to copy into these attributes.
See Also:
AttributesImpl.setAttributes(Attributes), getIndex(String)

getIndex

public final int getIndex(java.lang.String uri,
                          java.lang.String localName)
This method gets the index of an attribute given its uri and locanName.

Specified by:
getIndex in interface org.xml.sax.Attributes
Overrides:
getIndex in class org.xml.sax.helpers.AttributesImpl
Parameters:
uri - the URI of the attribute name.
localName - the local namer (after the ':' ) of the attribute name.
Returns:
the integer index of the attribute.
See Also:
Attributes.getIndex(String)