Class AttributeCollector
TextBuilder
s that
are used to create efficient semi-shared value Strings.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final int
Expected typical maximum number of attributes for any element; chosen to minimize need to resize, while trying not to waste space.protected static final int
protected static final int
protected static final int
Threshold value that indicates minimum length for lists instances that need a Map structure, for fast attribute access by fully-qualified name.protected int
Actual number of attributes collected, including attributes added via default values.protected int
Size of hash area inmAttrMap
; generally at least 20% more than number of attributes (mAttrCount
).protected Attribute[]
Array of attributes collected for this element.protected int[]
Encoding of a data structure that contains mapping from attribute names to attribute index in main attribute name arrays.protected int
Pointer to int slot right after last spill entr, inmAttrMap
array.protected boolean
Flag to indicate whether the default namespace has already been declared for the current element.protected int
private final TextBuilder
TextBuilder into which values of namespace URIs are added (including URI for the default namespace, if one defined).protected Attribute[]
Array of namespace declaration attributes collected for this element; not used in non-namespace-aware modeprotected int
Number of attribute values actually parsed, not including ones created via default value expansion.protected int
Number of valid namespace declarations inmNamespaces
.protected TextBuilder
TextBuilder into which values of all attributes are appended to, including default valued ones (defaults are added after explicit ones).protected int
Index of "xml:id" attribute, if one exists for the current element;XMLID_IX_NONE
if none.protected final String
protected final String
protected static final InternCache
protected static final int
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 disabledprotected static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
addDefaultAttribute
(String localName, String uri, String prefix, 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.protected final void
Method called to initialize buffers that need not be immediately initializedMethod needed by event creating code, to build a non-transient attribute container, to use with XMLEvent objects (specifically implementation of StartElement event).private static final boolean
checkExpand
(org.codehaus.stax2.typed.TypedArrayDecoder tad) Internal method used to see if we can expand the buffer that the array decoder has.final byte[]
decodeBinary
(int index, org.codehaus.stax2.typed.Base64Variant v, org.codehaus.stax2.ri.typed.CharArrayBase64Decoder dec, InputProblemReporter rep) final void
decodeValue
(int index, org.codehaus.stax2.typed.TypedValueDecoder tvd) Method called to decode the whole attribute value as a single typed value.final int
decodeValues
(int index, org.codehaus.stax2.typed.TypedArrayDecoder tad, InputProblemReporter rep) Method called to decode the attribute value that consists of zero or more space-separated tokens.private static final int
decodeValues
(org.codehaus.stax2.typed.TypedArrayDecoder tad, InputProblemReporter rep, char[] buf, int ptr, int end) int
int
final TextBuilder
getAttrBuilder
(String attrPrefix, String attrLocalName) Low-level accessor method that attribute validation code may call for certain types of attributes; generally only for id and idref/idrefs attributes.final int
getCount()
getLocalName
(int index) int
getNsBuilder
(String prefix) protected int
getNsPrefix
(int index) getNsURI
(int index) getPrefix
(int index) getQName
(int index) protected char[]
int
getURI
(int index) final String
getValue
(int index) Note: the main reason this method is defined at this level, and made final, is performance.getValueByLocalName
(String localName) Specialized version in which namespace information is completely ignored.protected int
getValueStartOffset
(int index) Method for getting start pointer within shared value buffer for given attribute.final int
boolean
private void
Method called to ensure hash area will be properly set up in cases where initially no room was needed, but default attribute(s) is being added.final boolean
isSpecified
(int index) void
normalizeSpacesInValue
(int index) Method that can be called to force space normalization (remove leading/trailing spaces, replace non-spaces white space with spaces, collapse spaces to one) on specified attribute.void
reset()
Method called to allow reusing of collector, usually right before starting collecting attributes for a new start tag.protected Attribute
resolveNamespaceDecl
(int index, boolean internURI) Method called to resolve and initialize specified collected namespace declarationint
Method called to resolve namespace URIs from attribute prefixes.void
setMaxAttributesPerElement
(int maxAttributesPerElement) final void
setNormalizedValue
(int index, 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.private int[]
spillAttr
(String uri, String name, int[] map, int currIndex, int spillIndex, int hash, int hashCount) protected void
throwDupAttr
(InputProblemReporter rep, int index) Method that can be used to get the specified attribute value, by getting it written using Writer passed in.protected void
throwIndex
(int index) protected void
validateAttribute
(int index, org.codehaus.stax2.validation.XMLValidator vld) void
writeAttribute
(int index, XmlWriter xw) Deprecated.Since 5.0.3void
writeAttribute
(int index, XmlWriter xw, org.codehaus.stax2.validation.XMLValidator validator) Method that basically serializes the specified (read-in) attribute using Writers provided.
-
Field Details
-
INT_SPACE
protected static final int INT_SPACE- See Also:
-
LONG_ATTR_LIST_LEN
protected static final int LONG_ATTR_LIST_LENThreshold value that indicates minimum length for lists instances that need a Map structure, for fast attribute access by fully-qualified name.- See Also:
-
EXP_ATTR_COUNT
protected static final int EXP_ATTR_COUNTExpected 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:
-
EXP_NS_COUNT
protected static final int EXP_NS_COUNT- See Also:
-
XMLID_IX_DISABLED
protected static final int XMLID_IX_DISABLEDThis 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:
-
XMLID_IX_NONE
protected static final int XMLID_IX_NONE- See Also:
-
sInternCache
-
mXmlIdPrefix
-
mXmlIdLocalName
-
mAttributes
Array of attributes collected for this element. -
mAttrCount
protected int mAttrCountActual number of attributes collected, including attributes added via default values. -
mNonDefCount
protected int mNonDefCountNumber of attribute values actually parsed, not including ones created via default value expansion. Equal to or less thanmAttrCount
. -
mNamespaces
Array of namespace declaration attributes collected for this element; not used in non-namespace-aware mode -
mNsCount
protected int mNsCountNumber of valid namespace declarations inmNamespaces
. -
mDefaultNsDeclared
protected boolean mDefaultNsDeclaredFlag to indicate whether the default namespace has already been declared for the current element. -
mXmlIdAttrIndex
protected int mXmlIdAttrIndexIndex of "xml:id" attribute, if one exists for the current element;XMLID_IX_NONE
if none. -
mValueBuilder
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) -
mNamespaceBuilder
TextBuilder into which values of namespace URIs are added (including URI for the default namespace, if one defined). -
mAttrMap
protected int[] mAttrMapEncoding 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 mAttrHashSizeSize of hash area inmAttrMap
; generally at least 20% more than number of attributes (mAttrCount
). -
mAttrSpillEnd
protected int mAttrSpillEndPointer to int slot right after last spill entr, inmAttrMap
array. -
mMaxAttributesPerElement
protected int mMaxAttributesPerElement
-
-
Constructor Details
-
AttributeCollector
-
-
Method Details
-
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.
-
normalizeSpacesInValue
public void normalizeSpacesInValue(int index) Method that can be called to force space normalization (remove leading/trailing spaces, replace non-spaces white space with spaces, collapse spaces to one) on specified attribute. Currently called byInputElementStack
to force normalization of Xml:id attribute -
getNsCount
protected int getNsCount()- Returns:
- Number of namespace declarations collected, including possible default namespace declaration
-
hasDefaultNs
public boolean hasDefaultNs() -
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
-
getNsPrefix
-
getNsURI
-
getPrefix
-
getLocalName
-
getURI
-
getQName
-
getValue
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
-
getValueByLocalName
Specialized version in which namespace information is completely ignored.- Since:
- 5.2
-
getMaxAttributesPerElement
public int getMaxAttributesPerElement() -
setMaxAttributesPerElement
public void setMaxAttributesPerElement(int maxAttributesPerElement) -
findIndex
-
findIndex
-
isSpecified
public final boolean isSpecified(int index) -
getXmlIdAttrIndex
public final int getXmlIdAttrIndex() -
decodeValue
public final void decodeValue(int index, org.codehaus.stax2.typed.TypedValueDecoder tvd) throws IllegalArgumentException Method called to decode the whole attribute value as a single typed value. Decoding is done using the decoder provided.- Throws:
IllegalArgumentException
-
decodeValues
public final int decodeValues(int index, org.codehaus.stax2.typed.TypedArrayDecoder tad, InputProblemReporter rep) throws XMLStreamException Method called to decode the attribute value that consists of zero or more space-separated tokens. Decoding is done using the decoder provided.- Returns:
- Number of tokens decoded
- Throws:
XMLStreamException
-
decodeBinary
public final byte[] decodeBinary(int index, org.codehaus.stax2.typed.Base64Variant v, org.codehaus.stax2.ri.typed.CharArrayBase64Decoder dec, InputProblemReporter rep) throws XMLStreamException - Throws:
XMLStreamException
-
decodeValues
private static final int decodeValues(org.codehaus.stax2.typed.TypedArrayDecoder tad, InputProblemReporter rep, char[] buf, int ptr, int end) throws XMLStreamException - Throws:
XMLStreamException
-
checkExpand
private static final boolean checkExpand(org.codehaus.stax2.typed.TypedArrayDecoder tad) Internal method used to see if we can expand the buffer that the array decoder has. Bit messy, but simpler than having separately typed instances; and called rarely so that performance downside of instanceof is irrelevant. -
getValueStartOffset
protected int getValueStartOffset(int index) Method for getting start pointer within shared value buffer for given attribute. It is also the same as end pointer for preceding attribute, if any. -
resolveNamespaceDecl
Method called to resolve and initialize specified collected namespace declaration- Returns:
- Attribute that contains specified namespace declaration
-
buildAttrOb
Method needed by event creating code, to build a non-transient attribute container, to use with XMLEvent objects (specifically implementation of StartElement event). -
validateAttribute
protected void validateAttribute(int index, org.codehaus.stax2.validation.XMLValidator vld) throws XMLStreamException - Throws:
XMLStreamException
-
getAttrBuilder
public final TextBuilder getAttrBuilder(String attrPrefix, String attrLocalName) throws XMLStreamException 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.- Throws:
XMLStreamException
-
addDefaultAttribute
public int addDefaultAttribute(String localName, String uri, String prefix, String value) throws XMLStreamException 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
- Throws:
XMLStreamException
-
setNormalizedValue
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. -
getDefaultNsBuilder
- Returns:
- null if the default namespace URI has been already declared for the current element; TextBuilder to add URI to if not.
- Throws:
XMLStreamException
-
getNsBuilder
- Returns:
- null if prefix has been already declared; TextBuilder to add value to if not.
- Throws:
XMLStreamException
-
resolveNamespaces
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 problemsns
- Namespace prefix/URI mappings active for this element- Returns:
- Index of xml:id attribute, if any, -1 if not
- Throws:
XMLStreamException
-
throwIndex
protected void throwIndex(int index) -
writeAttribute
@Deprecated public void writeAttribute(int index, XmlWriter xw) throws IOException, XMLStreamException Deprecated.Since 5.0.3- Throws:
IOException
XMLStreamException
-
writeAttribute
public void writeAttribute(int index, XmlWriter xw, org.codehaus.stax2.validation.XMLValidator validator) throws IOException, 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:
IOException
XMLStreamException
-
allocBuffers
protected final void allocBuffers()Method called to initialize buffers that need not be immediately initialized -
spillAttr
private int[] spillAttr(String uri, String name, int[] map, int currIndex, int spillIndex, int hash, int hashCount) - Returns:
- Null, if attribute is a duplicate (to indicate error); map itself, or resized version, otherwise.
-
initHashArea
private void initHashArea()Method called to ensure hash area will be properly set up in cases where initially no room was needed, but default attribute(s) is being added. -
throwDupAttr
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.- Throws:
XMLStreamException
-