Package com.ctc.wstx.sw
Class SimpleOutputElement
java.lang.Object
com.ctc.wstx.sw.OutputElementBase
com.ctc.wstx.sw.SimpleOutputElement
- All Implemented Interfaces:
NamespaceContext
Class that encapsulates information about a specific element in virtual
output stack for namespace-aware writers.
It provides support for URI-to-prefix mappings as well as namespace
mapping generation.
One noteworthy feature of the class is that it is designed to allow "short-term recycling", ie. instances can be reused within context of a simple document output. While reuse/recycling of such lightweight object is often useless or even counter productive, here it may be worth using, due to simplicity of the scheme (basically using a very simple free-elements linked list).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final classSimple key class used to represent two-piece (attribute) names; first part being optional (URI), and second non-optional (local name).(package private) final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ArrayList<SimpleOutputElement.Attribute> Map used to check for duplicate attribute declarations, if feature is enabled.protected StringLocal name of the element.protected SimpleOutputElementReference to the parent element, element enclosing this element.protected StringPrefix that is used for the element.protected StringNamespace of the element, whatevermPrefixmaps to.private org.codehaus.stax2.validation.XMLValidatorFields inherited from class com.ctc.wstx.sw.OutputElementBase
DEFAULT_XML_BINDINGS, mDefaultNsURI, mNsMapping, mNsMapShared, mRootNsContext, PREFIX_MISBOUND, PREFIX_OK, PREFIX_UNBOUND, sXmlNsPrefix, sXmlNsURI -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateConstructor for the virtual root elementprivateSimpleOutputElement(SimpleOutputElement parent, String prefix, String localName, String uri, BijectiveNsMap ns) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAttribute(String nsURI, String localName, String prefix, String value) protected voidaddToPool(SimpleOutputElement poolHead) Method called to temporarily link this instance to a pool, to allow reusing of instances with the same reader.protected SimpleOutputElementcreateChild(String localName) Simplest factory method, which gets called when a 1-argument element output method is called.protected SimpleOutputElementcreateChild(String prefix, String localName, String uri) Full factory method, used for 'normal' namespace qualified output methods.static SimpleOutputElementintfindAttributeIndex(String nsURI, String localName) (package private) org.codehaus.stax2.validation.XMLValidatorReturns theXMLValidatorset viasetValidator(XMLValidator)wrapped in aSimpleOutputElement.AttributeCollectorto be able to record the attribute values received throughXMLValidator.validateAttribute(String, String, String, char[], int, int)andXMLValidator.validateAttribute(String, String, String, String).intgetAttributeLocalName(int index) getAttributeNamespace(int index) getAttributePrefix(int index) getAttributeType(int index) getAttributeValue(int index) getAttributeValue(String nsURI, String localName) getName()booleanisRoot()private voidrelink(SimpleOutputElement parent, String prefix, String localName, String uri) Method called to reuse a pooled instance.protected SimpleOutputElementreuseAsChild(SimpleOutputElement parent, String localName) protected SimpleOutputElementreuseAsChild(SimpleOutputElement parent, String prefix, String localName, String uri) voidsetDefaultNsUri(String uri) voidprotected final voidNote: this method can and will only be called before outputting the root element.(package private) voidsetValidator(org.codehaus.stax2.validation.XMLValidator validator) Propagates the validator reference to this element and all ancestors.intMethods inherited from class com.ctc.wstx.sw.OutputElementBase
addPrefix, generateMapping, getDefaultNsUri, getExplicitPrefix, getNamespaceURI, getPrefix, getPrefixes, isPrefixValid, relink, throwOutputError
-
Field Details
-
mParent
Reference to the parent element, element enclosing this element. Null for root element. Non-final only to allow temporary pooling (on per-writer basis, to keep these short-lived). -
mPrefix
Prefix that is used for the element. Can not be final, since sometimes it needs to be dynamically generated and bound after creating the element instance. -
mLocalName
Local name of the element. Non-final only to allow reuse. -
mURI
Namespace of the element, whatevermPrefixmaps to. Non-final only to allow reuse. -
mAttrMap
Map used to check for duplicate attribute declarations, if feature is enabled. -
mAttrList
-
mAttributeCollector
-
mValidator
private org.codehaus.stax2.validation.XMLValidator mValidator
-
-
Constructor Details
-
SimpleOutputElement
private SimpleOutputElement()Constructor for the virtual root element -
SimpleOutputElement
private SimpleOutputElement(SimpleOutputElement parent, String prefix, String localName, String uri, BijectiveNsMap ns)
-
-
Method Details
-
relink
Method called to reuse a pooled instance. -
createRoot
-
createChild
Simplest factory method, which gets called when a 1-argument element output method is called. It is, then, assumed to use the default namespce. -
reuseAsChild
- Returns:
- New head of the recycle pool
-
reuseAsChild
protected SimpleOutputElement reuseAsChild(SimpleOutputElement parent, String prefix, String localName, String uri) -
createChild
Full factory method, used for 'normal' namespace qualified output methods. -
addToPool
Method called to temporarily link this instance to a pool, to allow reusing of instances with the same reader. -
getParent
-
isRoot
public boolean isRoot()- Specified by:
isRootin classOutputElementBase
-
getNameDesc
- Specified by:
getNameDescin classOutputElementBase- Returns:
- String presentation of the fully-qualified name, in "prefix:localName" format (no URI). Useful for error and debugging messages.
-
getPrefix
-
getLocalName
-
getNamespaceURI
-
getName
-
addAttribute
public void addAttribute(String nsURI, String localName, String prefix, String value) throws XMLStreamException - Throws:
XMLStreamException
-
setPrefix
-
setDefaultNsUri
- Specified by:
setDefaultNsUriin classOutputElementBase
-
setValidator
void setValidator(org.codehaus.stax2.validation.XMLValidator validator) Propagates the validator reference to this element and all ancestors. This is needed because both the active element tree (linked viamParent) and pooled elements (linked via the same field inaddToPool(com.ctc.wstx.sw.SimpleOutputElement)) must carry the current validator so that newly created or reused children inherit it automatically. -
setRootNsContext
Note: this method can and will only be called before outputting the root element.- Specified by:
setRootNsContextin classOutputElementBase
-
getAttributeCount
public int getAttributeCount() -
getAttributeLocalName
-
getAttributeNamespace
-
getAttributePrefix
-
getAttributeValue
-
getAttributeValue
-
getAttributeType
-
findAttributeIndex
-
getAttributeCollector
org.codehaus.stax2.validation.XMLValidator getAttributeCollector()Returns theXMLValidatorset viasetValidator(XMLValidator)wrapped in aSimpleOutputElement.AttributeCollectorto be able to record the attribute values received throughXMLValidator.validateAttribute(String, String, String, char[], int, int)andXMLValidator.validateAttribute(String, String, String, String).- Returns:
- an instance of
SimpleOutputElement.AttributeCollector
-
validateElementStartAndAttributes
- Throws:
XMLStreamException
-