com.ctc.wstx.sr
Class AttributeCollector

java.lang.Object
  extended by com.ctc.wstx.sr.AttributeCollector
Direct Known Subclasses:
NonNsAttributeCollector, NsAttributeCollector

public abstract class AttributeCollector
extends java.lang.Object

Shared base class that defines API stream reader uses to communicate with the attribute collector implementation, independent of whether it's operating in namespace-aware or non-namespace modes. Collector class is used to build up attribute lists; for the most part will just hold references to few specialized TextBuilders that are used to create efficient semi-shared value Strings.


Field Summary
protected static int EXP_ATTR_COUNT
          Expected typical maximum number of attributes for any element; chosen to minimize need to resize, while trying not to waste space.
protected static int LONG_ATTR_LIST_LEN
          Threshold value that indicates minimum length for lists instances that need a Map structure, for fast attribute access by fully-qualified name.
protected  int mAttrCount
          Actual number of attributes collected, including attributes added via default values.
protected  int mAttrHashSize
          Size of hash area in mAttrMap; generally at least 20% more than number of attributes (mAttrCount).
protected  int[] mAttrMap
          Encoding of a data structure that contains mapping from attribute names to attribute index in main attribute name arrays.
protected  StringVector mAttrNames
          Vector in which attribute names are added; exact number of elements per attribute depends on whether namespace support is enabled or not (non-namespace mode only needs one entry; namespace mode two, one for prefix, one for local name).
protected  int mAttrSpillEnd
          Pointer to int slot right after last spill entr, in mAttrMap array.
protected  java.lang.String[] mAttrValues
          Array in which attribute value Strings are added, first time they are requested.
protected  int mNonDefCount
          Number of attribute values actually parsed, not including ones created via default value expansion.
protected  TextBuilder mValueBuffer
          TextBuilder into which values of all attributes are appended to, including default valued ones (defaults are added after explicit ones).
protected  int mXmlIdAttrIndex
          Index of "xml:id" attribute, if one exists for the current element; XMLID_IX_NONE if none.
protected static int XMLID_IX_DISABLED
          This value is used to indicate that we shouldn't keep track of index of xml:id attribute -- generally done when Xml:id support is disabled
protected static int XMLID_IX_NONE
           
 
Constructor Summary
protected AttributeCollector(ReaderConfig cfg)
           
 
Method Summary
protected  void allocBuffers()
          Method called to initialize buffers that need not be immediately initialized
abstract  ElemAttrs buildAttrOb()
          Method needed by event builder code; called to build a non-transient attribute container to use by a start element event.
 TextBuilder getAttrBuilder()
          Low-level accessor method that attribute validation code may call for certain types of attributes; generally only for id and idref/idrefs attributes.
abstract  TextBuilder getAttrBuilder(java.lang.String attrPrefix, java.lang.String attrLocalName)
           
 int getCount()
           
abstract  TextBuilder getDefaultNsBuilder()
           
abstract  java.lang.String getLocalName(int index)
           
 StringVector getNameList()
          Method called by InputElementStack instance that "owns" this attribute collector;
abstract  TextBuilder getNsBuilder(java.lang.String localName)
           
abstract  int getNsCount()
           
abstract  java.lang.String getNsPrefix(int index)
           
abstract  java.lang.String getNsURI(int index)
           
abstract  java.lang.String getPrefix(int index)
           
abstract  javax.xml.namespace.QName getQName(int index)
           
 int getSpecifiedCount()
           
abstract  java.lang.String getURI(int index)
           
 java.lang.String getValue(int index)
           Note: the main reason this method is defined at this level, and made final, is performance.
abstract  java.lang.String getValue(java.lang.String nsURI, java.lang.String localName)
           
 int getXmlIdAttrIndex()
           
 boolean isSpecified(int index)
           
protected abstract  void reset()
          Method called to allow reusing of collector, usually right before starting collecting attributes for a new start tag.
protected static java.lang.String[] resize(java.lang.String[] old)
          Method that can be used to get the specified attribute value, by getting it written using Writer passed in.
 void setNormalizedValue(int index, java.lang.String value)
          Low-level mutator method that attribute validation code may call for certain types of attributes, when it wants to handle the whole validation and normalization process by itself.
protected  void throwDupAttr(InputProblemReporter rep, int index)
           
protected  void throwIndex(int index)
           
abstract  void writeAttribute(int index, XmlWriter xw)
          Method that basically serializes the specified (read-in) attribute using Writers provided.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LONG_ATTR_LIST_LEN

protected static final int LONG_ATTR_LIST_LEN
Threshold value that indicates minimum length for lists instances that need a Map structure, for fast attribute access by fully-qualified name.

See Also:
Constant Field Values

EXP_ATTR_COUNT

protected static final int EXP_ATTR_COUNT
Expected typical maximum number of attributes for any element; chosen to minimize need to resize, while trying not to waste space. Dynamically grown; better not to set too high to avoid excessive overhead for small attribute-less documents.

See Also:
Constant Field Values

XMLID_IX_DISABLED

protected static final int XMLID_IX_DISABLED
This value is used to indicate that we shouldn't keep track of index of xml:id attribute -- generally done when Xml:id support is disabled

See Also:
Constant Field Values

XMLID_IX_NONE

protected static final int XMLID_IX_NONE
See Also:
Constant Field Values

mAttrCount

protected int mAttrCount
Actual number of attributes collected, including attributes added via default values.


mNonDefCount

protected int mNonDefCount
Number of attribute values actually parsed, not including ones created via default value expansion. Equal to or less than mAttrCount.


mValueBuffer

protected TextBuilder mValueBuffer
TextBuilder into which values of all attributes are appended to, including default valued ones (defaults are added after explicit ones). Constructed lazily, if and when needed (not needed for short attribute-less docs)


mAttrNames

protected StringVector mAttrNames
Vector in which attribute names are added; exact number of elements per attribute depends on whether namespace support is enabled or not (non-namespace mode only needs one entry; namespace mode two, one for prefix, one for local name). Constructed lazily, if and when needed (not needed for short attribute-less docs)


mXmlIdAttrIndex

protected int mXmlIdAttrIndex
Index of "xml:id" attribute, if one exists for the current element; XMLID_IX_NONE if none.


mAttrValues

protected java.lang.String[] mAttrValues
Array in which attribute value Strings are added, first time they are requested. Values are first added to mValueBuffer, from which a String is created, and finally substring created as needed and added to this array.


mAttrMap

protected int[] mAttrMap
Encoding of a data structure that contains mapping from attribute names to attribute index in main attribute name arrays.

Data structure contains two separate areas; main hash area (with size mAttrHashSize), and remaining spillover area that follows hash area up until (but not including) mAttrSpillEnd index. Main hash area only contains indexes (index+1; 0 signifying empty slot) to actual attributes; spillover area has both hash and index for any spilled entry. Spilled entries are simply stored in order added, and need to be searched using linear search. In case of both primary hash hits and spills, eventual comparison with the local name needs to be done with actual name array.


mAttrHashSize

protected int mAttrHashSize
Size of hash area in mAttrMap; generally at least 20% more than number of attributes (mAttrCount).


mAttrSpillEnd

protected int mAttrSpillEnd
Pointer to int slot right after last spill entr, in mAttrMap array.

Constructor Detail

AttributeCollector

protected AttributeCollector(ReaderConfig cfg)
Method Detail

reset

protected abstract void reset()
Method called to allow reusing of collector, usually right before starting collecting attributes for a new start tag.


getNsCount

public abstract int getNsCount()
Returns:
Number of namespace declarations collected, including possible default namespace declaration

getNsPrefix

public abstract java.lang.String getNsPrefix(int index)

getNsURI

public abstract java.lang.String getNsURI(int index)

getCount

public final int getCount()

getSpecifiedCount

public int getSpecifiedCount()
Returns:
Number of attributes that were explicitly specified; may be less than the total count due to attributes created using attribute default values

getPrefix

public abstract java.lang.String getPrefix(int index)

getLocalName

public abstract java.lang.String getLocalName(int index)

getURI

public abstract java.lang.String getURI(int index)

getQName

public abstract javax.xml.namespace.QName getQName(int index)

getValue

public final java.lang.String getValue(int index)

Note: the main reason this method is defined at this level, and made final, is performance. JIT may be able to fully inline this method, even when reference is via this base class. This is important since this is likely to be the most often called method of the collector instances.


getValue

public abstract java.lang.String getValue(java.lang.String nsURI,
                                          java.lang.String localName)

isSpecified

public final boolean isSpecified(int index)

getXmlIdAttrIndex

public final int getXmlIdAttrIndex()

getDefaultNsBuilder

public abstract TextBuilder getDefaultNsBuilder()

getNsBuilder

public abstract TextBuilder getNsBuilder(java.lang.String localName)

getAttrBuilder

public abstract TextBuilder getAttrBuilder(java.lang.String attrPrefix,
                                           java.lang.String attrLocalName)

buildAttrOb

public abstract ElemAttrs buildAttrOb()
Method needed by event builder code; called to build a non-transient attribute container to use by a start element event.


getAttrBuilder

public final TextBuilder getAttrBuilder()
Low-level accessor method that attribute validation code may call for certain types of attributes; generally only for id and idref/idrefs attributes. It returns the underlying 'raw' attribute value buffer for direct access.


setNormalizedValue

public final void setNormalizedValue(int index,
                                     java.lang.String value)
Low-level mutator method that attribute validation code may call for certain types of attributes, when it wants to handle the whole validation and normalization process by itself. It is generally only called for id and idref/idrefs attributes, as those values are usually normalized.


throwIndex

protected void throwIndex(int index)

getNameList

public final StringVector getNameList()
Method called by InputElementStack instance that "owns" this attribute collector;


writeAttribute

public abstract void writeAttribute(int index,
                                    XmlWriter xw)
                             throws java.io.IOException,
                                    javax.xml.stream.XMLStreamException
Method that basically serializes the specified (read-in) attribute using Writers provided. Serialization is done by writing out (fully-qualified) name of the attribute, followed by the equals sign and quoted value.

Throws:
java.io.IOException
javax.xml.stream.XMLStreamException

allocBuffers

protected final void allocBuffers()
Method called to initialize buffers that need not be immediately initialized


resize

protected static java.lang.String[] resize(java.lang.String[] old)
Method that can be used to get the specified attribute value, by getting it written using Writer passed in. Can potentially save one String allocation, since no (temporary) Strings need to be created.


throwDupAttr

protected void throwDupAttr(InputProblemReporter rep,
                            int index)
                     throws WstxException
Throws:
WstxException