Package com.ctc.wstx.sw
Class SimpleOutputElement
- java.lang.Object
-
- com.ctc.wstx.sw.OutputElementBase
-
- com.ctc.wstx.sw.SimpleOutputElement
-
- All Implemented Interfaces:
javax.xml.namespace.NamespaceContext
public final class SimpleOutputElement extends OutputElementBase
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 Classes Modifier and Type Class Description (package private) static classSimpleOutputElement.AttributeSimple key class used to represent two-piece (attribute) names; first part being optional (URI), and second non-optional (local name).(package private) classSimpleOutputElement.AttributeCollector
-
Field Summary
Fields Modifier and Type Field Description private SimpleOutputElement.AttributeCollectormAttributeCollectorprivate java.util.ArrayList<SimpleOutputElement.Attribute>mAttrListprivate java.util.HashMap<SimpleOutputElement.Attribute,SimpleOutputElement.Attribute>mAttrMapMap used to check for duplicate attribute declarations, if feature is enabled.protected java.lang.StringmLocalNameLocal name of the element.protected SimpleOutputElementmParentReference to the parent element, element enclosing this element.protected java.lang.StringmPrefixPrefix that is used for the element.protected java.lang.StringmURINamespace of the element, whatevermPrefixmaps to.private org.codehaus.stax2.validation.XMLValidatormValidator-
Fields 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
Constructors Modifier Constructor Description privateSimpleOutputElement()Constructor for the virtual root elementprivateSimpleOutputElement(SimpleOutputElement parent, java.lang.String prefix, java.lang.String localName, java.lang.String uri, BijectiveNsMap ns)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAttribute(java.lang.String nsURI, java.lang.String localName, java.lang.String prefix, java.lang.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(java.lang.String localName)Simplest factory method, which gets called when a 1-argument element output method is called.protected SimpleOutputElementcreateChild(java.lang.String prefix, java.lang.String localName, java.lang.String uri)Full factory method, used for 'normal' namespace qualified output methods.static SimpleOutputElementcreateRoot()intfindAttributeIndex(java.lang.String nsURI, java.lang.String localName)(package private) org.codehaus.stax2.validation.XMLValidatorgetAttributeCollector()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).intgetAttributeCount()java.lang.StringgetAttributeLocalName(int index)java.lang.StringgetAttributeNamespace(int index)java.lang.StringgetAttributePrefix(int index)java.lang.StringgetAttributeType(int index)java.lang.StringgetAttributeValue(int index)java.lang.StringgetAttributeValue(java.lang.String nsURI, java.lang.String localName)java.lang.StringgetLocalName()javax.xml.namespace.QNamegetName()java.lang.StringgetNameDesc()java.lang.StringgetNamespaceURI()SimpleOutputElementgetParent()java.lang.StringgetPrefix()booleanisRoot()private voidrelink(SimpleOutputElement parent, java.lang.String prefix, java.lang.String localName, java.lang.String uri)Method called to reuse a pooled instance.protected SimpleOutputElementreuseAsChild(SimpleOutputElement parent, java.lang.String localName)protected SimpleOutputElementreuseAsChild(SimpleOutputElement parent, java.lang.String prefix, java.lang.String localName, java.lang.String uri)voidsetDefaultNsUri(java.lang.String uri)voidsetPrefix(java.lang.String prefix)protected voidsetRootNsContext(javax.xml.namespace.NamespaceContext ctxt)Note: 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.intvalidateElementStartAndAttributes()-
Methods inherited from class com.ctc.wstx.sw.OutputElementBase
addPrefix, generateMapping, getDefaultNsUri, getExplicitPrefix, getNamespaceURI, getPrefix, getPrefixes, isPrefixValid, relink, throwOutputError
-
-
-
-
Field Detail
-
mParent
protected SimpleOutputElement 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
protected java.lang.String 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
protected java.lang.String mLocalName
Local name of the element. Non-final only to allow reuse.
-
mURI
protected java.lang.String mURI
Namespace of the element, whatevermPrefixmaps to. Non-final only to allow reuse.
-
mAttrMap
private java.util.HashMap<SimpleOutputElement.Attribute,SimpleOutputElement.Attribute> mAttrMap
Map used to check for duplicate attribute declarations, if feature is enabled.
-
mAttrList
private java.util.ArrayList<SimpleOutputElement.Attribute> mAttrList
-
mAttributeCollector
private SimpleOutputElement.AttributeCollector mAttributeCollector
-
mValidator
private org.codehaus.stax2.validation.XMLValidator mValidator
-
-
Constructor Detail
-
SimpleOutputElement
private SimpleOutputElement()
Constructor for the virtual root element
-
SimpleOutputElement
private SimpleOutputElement(SimpleOutputElement parent, java.lang.String prefix, java.lang.String localName, java.lang.String uri, BijectiveNsMap ns)
-
-
Method Detail
-
relink
private void relink(SimpleOutputElement parent, java.lang.String prefix, java.lang.String localName, java.lang.String uri)
Method called to reuse a pooled instance.
-
createRoot
public static SimpleOutputElement createRoot()
-
createChild
protected SimpleOutputElement createChild(java.lang.String localName)
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
protected SimpleOutputElement reuseAsChild(SimpleOutputElement parent, java.lang.String localName)
- Returns:
- New head of the recycle pool
-
reuseAsChild
protected SimpleOutputElement reuseAsChild(SimpleOutputElement parent, java.lang.String prefix, java.lang.String localName, java.lang.String uri)
-
createChild
protected SimpleOutputElement createChild(java.lang.String prefix, java.lang.String localName, java.lang.String uri)
Full factory method, used for 'normal' namespace qualified output methods.
-
addToPool
protected void addToPool(SimpleOutputElement poolHead)
Method called to temporarily link this instance to a pool, to allow reusing of instances with the same reader.
-
getParent
public SimpleOutputElement getParent()
-
isRoot
public boolean isRoot()
- Specified by:
isRootin classOutputElementBase
-
getNameDesc
public java.lang.String 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
public java.lang.String getPrefix()
-
getLocalName
public java.lang.String getLocalName()
-
getNamespaceURI
public java.lang.String getNamespaceURI()
-
getName
public javax.xml.namespace.QName getName()
-
addAttribute
public void addAttribute(java.lang.String nsURI, java.lang.String localName, java.lang.String prefix, java.lang.String value) throws javax.xml.stream.XMLStreamException- Throws:
javax.xml.stream.XMLStreamException
-
setPrefix
public void setPrefix(java.lang.String prefix)
-
setDefaultNsUri
public void setDefaultNsUri(java.lang.String uri)
- 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
protected final void setRootNsContext(javax.xml.namespace.NamespaceContext ctxt)
Note: this method can and will only be called before outputting the root element.- Specified by:
setRootNsContextin classOutputElementBase
-
getAttributeCount
public int getAttributeCount()
-
getAttributeLocalName
public java.lang.String getAttributeLocalName(int index)
-
getAttributeNamespace
public java.lang.String getAttributeNamespace(int index)
-
getAttributePrefix
public java.lang.String getAttributePrefix(int index)
-
getAttributeValue
public java.lang.String getAttributeValue(int index)
-
getAttributeValue
public java.lang.String getAttributeValue(java.lang.String nsURI, java.lang.String localName)
-
getAttributeType
public java.lang.String getAttributeType(int index)
-
findAttributeIndex
public int findAttributeIndex(java.lang.String nsURI, java.lang.String localName)
-
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
public int validateElementStartAndAttributes() throws javax.xml.stream.XMLStreamException- Throws:
javax.xml.stream.XMLStreamException
-
-