All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class org.apache.soap.util.xml.NSStack

java.lang.Object
   |
   +----org.apache.soap.util.xml.NSStack

public class NSStack
extends Object
This class implements a namespace stack for XML apps to use. If you need to keep track of namespaces in scope, then this class is for you. Every time you enter a new element and wish to add some namespace declarations that are to be visible within that element, you should call pushScope to create a new scope. Then, call addNSDeclaration any number of times to add new declarations for that scope. Scopes nest inside out; that is, any NS declaration added into a scope is visible from any scopes that are pushed later. When you want to see whether an NS declaration has already been made for a certain URI, you should call getPrefixInScopeForURI to get the prefix that has been bound to that URI. There is a covenience version of addNSDecalration which can be used if you want me to give you a not-so-random, yet unique, prefix for your namespace declaration.

Author:
Sanjiva Weerawarana ([email protected])

Constructor Index

 o NSStack()

Method Index

 o addNSDeclaration(String)
Add a new declaration to the current scope using a unique prefix and return the prefix.
 o addNSDeclaration(String, String)
Add a new declaration to the current scope.
 o getPrefixFromURI(String)
Return the prefix associated with the given namespace name by looking thru all the namespace declarations that are in scope.
 o getPrefixFromURI(String, Writer)
Return the prefix associated with the given namespace name by looking thru all the namespace declarations that are in scope.
 o getURIFromPrefix(String)
Return the namespace name associated with the given prefix by looking thru all the namespace declarations that are in scope.
 o popScope()
Leave a scope: this removes any NS declarations that were added in the last scope.
 o pushScope()
Enter a new scope: after calling this I'm ready to accept new declarations into that scope.
 o toString()

Constructors

 o NSStack
 public NSStack()

Methods

 o pushScope
 public void pushScope()
Enter a new scope: after calling this I'm ready to accept new declarations into that scope.

 o popScope
 public void popScope()
Leave a scope: this removes any NS declarations that were added in the last scope. Note that I don't bother to validate that you don't call popScope too many times; that's your problem.

 o addNSDeclaration
 public synchronized void addNSDeclaration(String prefix,
                                           String URI)
Add a new declaration to the current scope. This is visible within the current scope as well as from any nested scopes.

Parameters:
prefix - the prefix to be used for this namespace
URI - the namespace name of this namespace.
 o addNSDeclaration
 public synchronized String addNSDeclaration(String URI)
Add a new declaration to the current scope using a unique prefix and return the prefix. This is useful when one just wants to add a decl and doesn't want to have to deal with creating unique prefixes. If the namespace name is already declared and in scope, then the previously declared prefix is returned.

Parameters:
URI - the namespace name of this namespace
Returns:
the unique prefix created or previously declared for this namespace
 o getPrefixFromURI
 public String getPrefixFromURI(String URI)
Return the prefix associated with the given namespace name by looking thru all the namespace declarations that are in scope.

Parameters:
URI - the namespace name for whom a declared prefix is desired
Returns:
the prefix or null if namespace name not found
 o getPrefixFromURI
 public synchronized String getPrefixFromURI(String namespaceURI,
                                             Writer sink) throws IOException
Return the prefix associated with the given namespace name by looking thru all the namespace declarations that are in scope. If the namespace declaration is not found, create one and return the generated prefix.

Parameters:
URI - the namespace name for whom a declared prefix is desired
Returns:
the prefix (will never return null)
 o getURIFromPrefix
 public String getURIFromPrefix(String prefix)
Return the namespace name associated with the given prefix by looking thru all the namespace declarations that are in scope.

Parameters:
prefix - the prefix for whom a declared namespace name is desired
Returns:
the namespace name or null if prefix not found
 o toString
 public String toString()
Overrides:
toString in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index