com.ctc.wstx.sr
Class NsAttributeCollector

java.lang.Object
  extended by com.ctc.wstx.sr.AttributeCollector
      extended by com.ctc.wstx.sr.NsAttributeCollector

public final class NsAttributeCollector
extends AttributeCollector

Attribute collector class used in namespace-aware parsing mode.

Some notes about low-level raw hashing map implementation. Hash area is divided into two sections: first (of size 2^N) is somewhat usual set of indexes to actual attribute names (values in these slots are 'entry + 1', since 0 means 'empty'). There is just one int entry per name; actual name comparison is done using secondary tables that contain (interned) name components. Secondary area will be used for spills, and it is initially sized to have N/8 entries; and since there are 2 ints per entry, size will actually be N/4, following right after the primary hash area.

Note: only public for testing purposes


Field Summary
protected static int ATTR_URI_BUF_SIZE
          Initial size for attribute NS URI buffer
protected static java.lang.String DEFAULT_NS_URI
          Default URI that root element has, if none is explicitly defined.
 
Fields inherited from class com.ctc.wstx.sr.AttributeCollector
EXP_ATTR_COUNT, LONG_ATTR_LIST_LEN, mAttrCount, mAttrHashSize, mAttrMap, mAttrNames, mAttrSpillEnd, mAttrValues, mNonDefCount, mValueBuffer, mXmlIdAttrIndex, XMLID_IX_DISABLED, XMLID_IX_NONE
 
Constructor Summary
NsAttributeCollector(ReaderConfig cfg)
           
 
Method Summary
 int addDefaultAttribute(java.lang.String localName, java.lang.String uri, java.lang.String prefix, java.lang.String value)
          Method called by validator to insert an attribute that has a default value and wasn't yet included in collector's attribute set.
 ElemAttrs buildAttrOb()
          Method needed by event creating code, to build a non-transient attribute container, to use with XMLEvent objects (specifically implementation of StartElement event).
 int findIndex(java.lang.String nsURI, java.lang.String localName)
           
 TextBuilder getAttrBuilder(java.lang.String attrPrefix, java.lang.String attrLocalName)
          Method called to get TextBuilder instance, into which value String should be built, when starting to read attribute value.
protected  java.lang.String[] getAttrURIs()
           Note: only called by InputElementStack
 TextBuilder getDefaultNsBuilder()
           
 java.lang.String getLocalName(int index)
           
 TextBuilder getNsBuilder(java.lang.String prefix)
           
 int getNsCount()
           
 java.lang.String getNsPrefix(int index)
           
protected  java.lang.String[] getNsPrefixes()
           Note: only called by InputElementStack
 java.lang.String getNsURI(int index)
           
 TextBuilder getNsURIs()
           Note: only called by InputElementStack
 java.lang.String getPrefix(int index)
           
 javax.xml.namespace.QName getQName(int index)
          Note: caller must check validity of the index prior to calling this method.
 java.lang.String getURI(int index)
           
 java.lang.String getValue(java.lang.String nsURI, java.lang.String localName)
           
 boolean hasDefaultNs()
           
 void reset()
          Method called to allow reusing of collector, usually right before starting collecting attributes for a new start tag.
 int resolveNamespaces(InputProblemReporter rep, StringVector ns)
          Method called to resolve namespace URIs from attribute prefixes.
 void writeAttribute(int index, XmlWriter xw)
          Method that basically serializes the specified (read-in) attribute using Writers provided
 
Methods inherited from class com.ctc.wstx.sr.AttributeCollector
allocBuffers, getAttrBuilder, getCount, getNameList, getSpecifiedCount, getValue, getXmlIdAttrIndex, isSpecified, resize, setNormalizedValue, throwDupAttr, throwIndex
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_NS_URI

protected static final java.lang.String DEFAULT_NS_URI
Default URI that root element has, if none is explicitly defined.


ATTR_URI_BUF_SIZE

protected static final int ATTR_URI_BUF_SIZE
Initial size for attribute NS URI buffer

See Also:
Constant Field Values
Constructor Detail

NsAttributeCollector

public NsAttributeCollector(ReaderConfig cfg)
Method Detail

reset

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

Note: public only so that it can be called by unit tests.

Specified by:
reset in class AttributeCollector

resolveNamespaces

public int resolveNamespaces(InputProblemReporter rep,
                             StringVector ns)
                      throws WstxException
Method called to resolve namespace URIs from attribute prefixes.

Note: public only so that it can be called by unit tests.

Parameters:
rep - Reporter to use for reporting well-formedness problems
ns - Namespace prefix/URI mappings active for this element
Returns:
Index of xml:id attribute, if any, -1 if not
Throws:
WstxException

getNsCount

public int getNsCount()
Specified by:
getNsCount in class AttributeCollector
Returns:
Number of 'new' namespace declarations collected

hasDefaultNs

public boolean hasDefaultNs()

getNsPrefix

public java.lang.String getNsPrefix(int index)
Specified by:
getNsPrefix in class AttributeCollector

getNsURI

public java.lang.String getNsURI(int index)
Specified by:
getNsURI in class AttributeCollector

getPrefix

public java.lang.String getPrefix(int index)
Specified by:
getPrefix in class AttributeCollector

getLocalName

public java.lang.String getLocalName(int index)
Specified by:
getLocalName in class AttributeCollector

getURI

public java.lang.String getURI(int index)
Specified by:
getURI in class AttributeCollector

getQName

public javax.xml.namespace.QName getQName(int index)
Note: caller must check validity of the index prior to calling this method.

Specified by:
getQName in class AttributeCollector

getValue

public java.lang.String getValue(java.lang.String nsURI,
                                 java.lang.String localName)
Specified by:
getValue in class AttributeCollector

findIndex

public int findIndex(java.lang.String nsURI,
                     java.lang.String localName)

getDefaultNsBuilder

public TextBuilder getDefaultNsBuilder()
Specified by:
getDefaultNsBuilder in class AttributeCollector
Returns:
null if the default namespace URI has been already declared for the current element; TextBuilder to add URI to if not.

getNsBuilder

public TextBuilder getNsBuilder(java.lang.String prefix)
Specified by:
getNsBuilder in class AttributeCollector
Returns:
null if prefix has been already declared; TextBuilder to add value to if not.

getAttrBuilder

public TextBuilder getAttrBuilder(java.lang.String attrPrefix,
                                  java.lang.String attrLocalName)
Method called to get TextBuilder instance, into which value String should be built, when starting to read attribute value.

Note: It is assumed that all Strings have been canonicalized via default symbol table

Specified by:
getAttrBuilder in class AttributeCollector
Parameters:
attrPrefix - canonicalized attribute prefix
attrLocalName - canonicalized local name of attribute

getNsPrefixes

protected java.lang.String[] getNsPrefixes()

Note: only called by InputElementStack


getNsURIs

public TextBuilder getNsURIs()

Note: only called by InputElementStack


getAttrURIs

protected java.lang.String[] getAttrURIs()

Note: only called by InputElementStack


buildAttrOb

public ElemAttrs buildAttrOb()
Method needed by event creating code, to build a non-transient attribute container, to use with XMLEvent objects (specifically implementation of StartElement event).

Specified by:
buildAttrOb in class AttributeCollector

addDefaultAttribute

public int addDefaultAttribute(java.lang.String localName,
                               java.lang.String uri,
                               java.lang.String prefix,
                               java.lang.String value)
Method called by validator to insert an attribute that has a default value and wasn't yet included in collector's attribute set.

Returns:
Index of the newly added attribute, if added; -1 to indicate this was a duplicate

writeAttribute

public 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

Specified by:
writeAttribute in class AttributeCollector
Throws:
java.io.IOException
javax.xml.stream.XMLStreamException