Class NSStack

java.lang.Object
org.apache.axis.utils.NSStack

public class NSStack extends Object
The abstraction this class provides is a push down stack of variable length frames of prefix to namespace mappings. Used for keeping track of what namespaces are active at any given point as an XML document is traversed or produced. From a performance point of view, this data will both be modified frequently (at a minimum, there will be one push and pop per XML element processed), and scanned frequently (many of the "good" mappings will be at the bottom of the stack). The one saving grace is that the expected maximum cardinalities of the number of frames and the number of total mappings is only in the dozens, representing the nesting depth of an XML document and the number of active namespaces at any point in the processing. Accordingly, this stack is implemented as a single array, will null values used to indicate frame boundaries.
Author:
James Snell, Glen Daniels (gdaniels@apache.org), Sam Ruby (rubys@us.ibm.com)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static org.apache.commons.logging.Log
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    NSStack(boolean optimizePrefixes)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(String namespaceURI, String prefix)
    Add a mapping for a namespaceURI to the specified prefix to the top frame in the stack.
    Return a copy of the current frame.
    void
    dump(String dumpPrefix)
    Produce a trace dump of the entire stack, starting from the top and including frame markers.
    Given a prefix, return the associated namespace (if any).
    getPrefix(String namespaceURI)
    Return an active prefix for the given namespaceURI, including the default prefix ("").
    getPrefix(String namespaceURI, boolean noDefault)
    Return an active prefix for the given namespaceURI.
    Return the next namespace mapping in the top frame.
    void
    pop()
    Remove the top frame from the stack.
    void
    Create a new frame at the top of the stack.
    Reset the embedded iterator in this class to the top of the current (i.e., last) frame.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • log

      protected static org.apache.commons.logging.Log log
  • Constructor Details

    • NSStack

      public NSStack(boolean optimizePrefixes)
    • NSStack

      public NSStack()
  • Method Details

    • push

      public void push()
      Create a new frame at the top of the stack.
    • pop

      public void pop()
      Remove the top frame from the stack.
    • cloneFrame

      public ArrayList cloneFrame()
      Return a copy of the current frame. Returns null if none are present.
    • topOfFrame

      public Mapping topOfFrame()
      Reset the embedded iterator in this class to the top of the current (i.e., last) frame. Note that this is not threadsafe, nor does it provide multiple iterators, so don't use this recursively. Nor should you modify the stack while iterating over it.
    • next

      public Mapping next()
      Return the next namespace mapping in the top frame.
    • add

      public void add(String namespaceURI, String prefix)
      Add a mapping for a namespaceURI to the specified prefix to the top frame in the stack. If the prefix is already mapped in that frame, remap it to the (possibly different) namespaceURI.
    • getPrefix

      public String getPrefix(String namespaceURI, boolean noDefault)
      Return an active prefix for the given namespaceURI. NOTE : This may return null even if the namespaceURI was actually mapped further up the stack IF the prefix which was used has been repeated further down the stack. I.e.: <pre:outer xmlns:pre="namespace"> <pre:inner xmlns:pre="otherNamespace"> *here's where we're looking* </pre:inner> </pre:outer> If we look for a prefix for "namespace" at the indicated spot, we won't find one because "pre" is actually mapped to "otherNamespace"
    • getPrefix

      public String getPrefix(String namespaceURI)
      Return an active prefix for the given namespaceURI, including the default prefix ("").
    • getNamespaceURI

      public String getNamespaceURI(String prefix)
      Given a prefix, return the associated namespace (if any).
    • dump

      public void dump(String dumpPrefix)
      Produce a trace dump of the entire stack, starting from the top and including frame markers.