Class SimpleOutputElement

java.lang.Object
com.ctc.wstx.sw.OutputElementBase
com.ctc.wstx.sw.SimpleOutputElement
All Implemented Interfaces:
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).

  • Field Details

    • 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 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 String mLocalName
      Local name of the element. Non-final only to allow reuse.
    • mURI

      protected String mURI
      Namespace of the element, whatever mPrefix maps to. Non-final only to allow reuse.
    • mAttrMap

      Map used to check for duplicate attribute declarations, if feature is enabled.
    • mAttrList

    • mAttributeCollector

      private SimpleOutputElement.AttributeCollector mAttributeCollector
    • mValidator

      private org.codehaus.stax2.validation.XMLValidator mValidator
  • Constructor Details

  • Method Details

    • relink

      private void relink(SimpleOutputElement parent, String prefix, String localName, String uri)
      Method called to reuse a pooled instance.
    • createRoot

      public static SimpleOutputElement createRoot()
    • createChild

      protected SimpleOutputElement createChild(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, String localName)
      Returns:
      New head of the recycle pool
    • reuseAsChild

      protected SimpleOutputElement reuseAsChild(SimpleOutputElement parent, String prefix, String localName, String uri)
    • createChild

      protected SimpleOutputElement createChild(String prefix, String localName, 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:
      isRoot in class OutputElementBase
    • getNameDesc

      public String getNameDesc()
      Specified by:
      getNameDesc in class OutputElementBase
      Returns:
      String presentation of the fully-qualified name, in "prefix:localName" format (no URI). Useful for error and debugging messages.
    • getPrefix

      public String getPrefix()
    • getLocalName

      public String getLocalName()
    • getNamespaceURI

      public String getNamespaceURI()
    • getName

      public QName getName()
    • addAttribute

      public void addAttribute(String nsURI, String localName, String prefix, String value) throws XMLStreamException
      Throws:
      XMLStreamException
    • setPrefix

      public void setPrefix(String prefix)
    • setDefaultNsUri

      public void setDefaultNsUri(String uri)
      Specified by:
      setDefaultNsUri in class OutputElementBase
    • 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 via mParent) and pooled elements (linked via the same field in addToPool(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(NamespaceContext ctxt)
      Note: this method can and will only be called before outputting the root element.
      Specified by:
      setRootNsContext in class OutputElementBase
    • getAttributeCount

      public int getAttributeCount()
    • getAttributeLocalName

      public String getAttributeLocalName(int index)
    • getAttributeNamespace

      public String getAttributeNamespace(int index)
    • getAttributePrefix

      public String getAttributePrefix(int index)
    • getAttributeValue

      public String getAttributeValue(int index)
    • getAttributeValue

      public String getAttributeValue(String nsURI, String localName)
    • getAttributeType

      public String getAttributeType(int index)
    • findAttributeIndex

      public int findAttributeIndex(String nsURI, String localName)
    • getAttributeCollector

      org.codehaus.stax2.validation.XMLValidator getAttributeCollector()
      Returns the XMLValidator set via setValidator(XMLValidator) wrapped in a SimpleOutputElement.AttributeCollector to be able to record the attribute values received through XMLValidator.validateAttribute(String, String, String, char[], int, int) and XMLValidator.validateAttribute(String, String, String, String).
      Returns:
      an instance of SimpleOutputElement.AttributeCollector
    • validateElementStartAndAttributes

      public int validateElementStartAndAttributes() throws XMLStreamException
      Throws:
      XMLStreamException