Class NamespaceContexHelper
- All Implemented Interfaces:
Iterable<org.jvnet.staxex.NamespaceContextEx.Binding>
,NamespaceContext
,org.jvnet.staxex.NamespaceContextEx
A namespace is declared on a namespace context. Namespace contexts are pushed on and popped off the namespace context stack.
A declared namespace will be in scope iff the context that it was declared on has not been popped off the stack.
When instantiated the namespace stack consists of the root namespace context, which contains, by default, the "xml" and "xmlns" declarations. Namespaces may be declarations may be declared on the root context. The root context cannot be popped but can be reset to contain just the "xml" and "xmlns" declarations.
Implementation note: determining the prefix from a namespace URI (or vice versa) is efficient when there are few namespace declarations i.e. what is considered to be the case for namespace declarations in 'average' XML documents. The look up of a namespace URI given a prefix is performed in O(n) time. The look up of a prefix given a namespace URI is performed in O(2n) time.
The implementation does not scale when there are many namespace declarations. TODO: Use a hash map when there are many namespace declarations.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface org.jvnet.staxex.NamespaceContextEx
org.jvnet.staxex.NamespaceContextEx.Binding
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
declareDefaultNamespace
(String namespaceURI) Declare a default namespace.void
declareNamespace
(String prefix, String namespaceURI) Declare a namespace.getNamespaceURI
(String prefix) getPrefixes
(String namespaceURI) Iterator<org.jvnet.staxex.NamespaceContextEx.Binding>
iterator()
void
Pop the namespace context off the stack.void
Push a namespace context on the stack.void
Reset namespace contexts.private void
private void
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
DEFAULT_SIZE
private static int DEFAULT_SIZE -
prefixes
-
namespaceURIs
-
namespacePosition
private int namespacePosition -
contexts
private int[] contexts -
contextPosition
private int contextPosition
-
-
Constructor Details
-
NamespaceContexHelper
public NamespaceContexHelper()Create a new NamespaceContexHelper.
-
-
Method Details
-
getNamespaceURI
- Specified by:
getNamespaceURI
in interfaceNamespaceContext
-
getPrefix
- Specified by:
getPrefix
in interfaceNamespaceContext
-
getPrefixes
- Specified by:
getPrefixes
in interfaceNamespaceContext
-
iterator
-
declareDefaultNamespace
Declare a default namespace.- Parameters:
namespaceURI
- the namespace URI to declare, may be null.
-
declareNamespace
Declare a namespace.The namespace will be declared on the current namespace context.
The namespace can be removed by popping the current namespace context, or, if the declaration occured in the root context, by reseting the namespace context.
A default namespace can be declared by passing
""
as the value of the prefix parameter. A namespace may be undeclared by passingnull
as the value of the namespaceURI parameter.- Parameters:
prefix
- the namespace prefix to declare, may not be null.namespaceURI
- the namespace URI to declare, may be null.
-
resizeNamespaces
private void resizeNamespaces() -
pushContext
public void pushContext()Push a namespace context on the stack. -
resizeContexts
private void resizeContexts() -
popContext
public void popContext()Pop the namespace context off the stack.Namespaces declared within the context (to be popped) will be removed and no longer be in scope.
-
resetContexts
public void resetContexts()Reset namespace contexts.Pop all namespace contexts and reset the root context.
-