public final class AttributeCollector
extends java.lang.Object
TextBuilder
s that
are used to create efficient semi-shared value Strings.Modifier and Type | Field and Description |
---|---|
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 |
EXP_NS_COUNT |
(package private) static int |
INT_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 Attribute[] |
mAttributes
Array of attributes collected for this element.
|
protected int[] |
mAttrMap
Encoding of a data structure that contains mapping from
attribute names to attribute index in main attribute name arrays.
|
protected int |
mAttrSpillEnd
Pointer to int slot right after last spill entr, in
mAttrMap array. |
protected boolean |
mDefaultNsDeclared
Flag to indicate whether the default namespace has already been declared
for the current element.
|
protected int |
mMaxAttributeSize |
protected int |
mMaxAttributesPerElement |
private TextBuilder |
mNamespaceBuilder
TextBuilder into which values of namespace URIs are added (including
URI for the default namespace, if one defined).
|
protected Attribute[] |
mNamespaces
Array of namespace declaration attributes collected for this element;
not used in non-namespace-aware mode
|
protected int |
mNonDefCount
Number of attribute values actually parsed, not including
ones created via default value expansion.
|
protected int |
mNsCount
Number of valid namespace declarations in
mNamespaces . |
protected TextBuilder |
mValueBuilder
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. |
(package private) java.lang.String |
mXmlIdLocalName |
(package private) java.lang.String |
mXmlIdPrefix |
protected static InternCache |
sInternCache |
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 |
Modifier | Constructor and Description |
---|---|
protected |
AttributeCollector(ReaderConfig cfg,
boolean nsAware) |
Modifier and Type | Method and Description |
---|---|
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.
|
protected void |
allocBuffers()
Method called to initialize buffers that need not be immediately
initialized
|
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).
|
private static boolean |
checkExpand(org.codehaus.stax2.typed.TypedArrayDecoder tad)
Internal method used to see if we can expand the buffer that
the array decoder has.
|
byte[] |
decodeBinary(int index,
org.codehaus.stax2.typed.Base64Variant v,
org.codehaus.stax2.ri.typed.CharArrayBase64Decoder dec,
InputProblemReporter rep) |
void |
decodeValue(int index,
org.codehaus.stax2.typed.TypedValueDecoder tvd)
Method called to decode the whole attribute value as a single
typed value.
|
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 int |
decodeValues(org.codehaus.stax2.typed.TypedArrayDecoder tad,
InputProblemReporter rep,
char[] buf,
int ptr,
int end) |
int |
findIndex(java.lang.String localName) |
int |
findIndex(java.lang.String nsURI,
java.lang.String localName) |
TextBuilder |
getAttrBuilder(java.lang.String attrPrefix,
java.lang.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.
|
int |
getCount() |
TextBuilder |
getDefaultNsBuilder() |
java.lang.String |
getLocalName(int index) |
int |
getMaxAttributesPerElement() |
TextBuilder |
getNsBuilder(java.lang.String prefix) |
protected int |
getNsCount() |
java.lang.String |
getNsPrefix(int index) |
java.lang.String |
getNsURI(int index) |
java.lang.String |
getPrefix(int index) |
javax.xml.namespace.QName |
getQName(int index) |
protected char[] |
getSharedValueBuffer() |
int |
getSpecifiedCount() |
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.
|
java.lang.String |
getValue(java.lang.String nsURI,
java.lang.String localName) |
java.lang.String |
getValueByLocalName(java.lang.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.
|
int |
getXmlIdAttrIndex() |
boolean |
hasDefaultNs() |
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.
|
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 declaration
|
int |
resolveNamespaces(InputProblemReporter rep,
StringVector ns)
Method called to resolve namespace URIs from attribute prefixes.
|
void |
setMaxAttributesPerElement(int maxAttributesPerElement) |
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.
|
private int[] |
spillAttr(java.lang.String uri,
java.lang.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.3
|
void |
writeAttribute(int index,
XmlWriter xw,
org.codehaus.stax2.validation.XMLValidator validator)
Method that basically serializes the specified (read-in) attribute
using Writers provided.
|
static final int INT_SPACE
protected static final int LONG_ATTR_LIST_LEN
protected static final int EXP_ATTR_COUNT
protected static final int EXP_NS_COUNT
protected static final int XMLID_IX_DISABLED
protected static final int XMLID_IX_NONE
protected static final InternCache sInternCache
final java.lang.String mXmlIdPrefix
final java.lang.String mXmlIdLocalName
protected Attribute[] mAttributes
protected int mAttrCount
protected int mNonDefCount
mAttrCount
.protected Attribute[] mNamespaces
protected int mNsCount
mNamespaces
.protected boolean mDefaultNsDeclared
protected int mXmlIdAttrIndex
XMLID_IX_NONE
if none.protected TextBuilder mValueBuilder
private final TextBuilder mNamespaceBuilder
protected int[] mAttrMap
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.
protected int mAttrHashSize
mAttrMap
; generally at least 20%
more than number of attributes (mAttrCount
).protected int mAttrSpillEnd
mAttrMap
array.protected int mMaxAttributesPerElement
protected int mMaxAttributeSize
protected AttributeCollector(ReaderConfig cfg, boolean nsAware)
public void reset()
Note: public only so that it can be called by unit tests.
public void normalizeSpacesInValue(int index)
InputElementStack
to force
normalization of Xml:id attributeprotected int getNsCount()
public boolean hasDefaultNs()
public final int getCount()
public int getSpecifiedCount()
public java.lang.String getNsPrefix(int index)
public java.lang.String getNsURI(int index)
public java.lang.String getPrefix(int index)
public java.lang.String getLocalName(int index)
public java.lang.String getURI(int index)
public javax.xml.namespace.QName getQName(int index)
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.
public java.lang.String getValue(java.lang.String nsURI, java.lang.String localName)
public java.lang.String getValueByLocalName(java.lang.String localName)
public int getMaxAttributesPerElement()
public void setMaxAttributesPerElement(int maxAttributesPerElement)
public int findIndex(java.lang.String localName)
public int findIndex(java.lang.String nsURI, java.lang.String localName)
public final boolean isSpecified(int index)
public final int getXmlIdAttrIndex()
public final void decodeValue(int index, org.codehaus.stax2.typed.TypedValueDecoder tvd) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public final int decodeValues(int index, org.codehaus.stax2.typed.TypedArrayDecoder tad, InputProblemReporter rep) throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public final byte[] decodeBinary(int index, org.codehaus.stax2.typed.Base64Variant v, org.codehaus.stax2.ri.typed.CharArrayBase64Decoder dec, InputProblemReporter rep) throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
private static final int decodeValues(org.codehaus.stax2.typed.TypedArrayDecoder tad, InputProblemReporter rep, char[] buf, int ptr, int end) throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
private static final boolean checkExpand(org.codehaus.stax2.typed.TypedArrayDecoder tad)
protected int getValueStartOffset(int index)
protected char[] getSharedValueBuffer()
protected Attribute resolveNamespaceDecl(int index, boolean internURI)
public ElemAttrs buildAttrOb()
protected void validateAttribute(int index, org.codehaus.stax2.validation.XMLValidator vld) throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public final TextBuilder getAttrBuilder(java.lang.String attrPrefix, java.lang.String attrLocalName) throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public int addDefaultAttribute(java.lang.String localName, java.lang.String uri, java.lang.String prefix, java.lang.String value) throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public final void setNormalizedValue(int index, java.lang.String value)
public TextBuilder getDefaultNsBuilder() throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public TextBuilder getNsBuilder(java.lang.String prefix) throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public int resolveNamespaces(InputProblemReporter rep, StringVector ns) throws javax.xml.stream.XMLStreamException
Note: public only so that it can be called by unit tests.
rep
- Reporter to use for reporting well-formedness problemsns
- Namespace prefix/URI mappings active for this elementjavax.xml.stream.XMLStreamException
protected void throwIndex(int index)
@Deprecated public void writeAttribute(int index, XmlWriter xw) throws java.io.IOException, javax.xml.stream.XMLStreamException
java.io.IOException
javax.xml.stream.XMLStreamException
public void writeAttribute(int index, XmlWriter xw, org.codehaus.stax2.validation.XMLValidator validator) throws java.io.IOException, javax.xml.stream.XMLStreamException
java.io.IOException
javax.xml.stream.XMLStreamException
protected final void allocBuffers()
private int[] spillAttr(java.lang.String uri, java.lang.String name, int[] map, int currIndex, int spillIndex, int hash, int hashCount)
private void initHashArea()
protected void throwDupAttr(InputProblemReporter rep, int index) throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException