Package javanet.staxutils
Class SimpleNamespaceContext
java.lang.Object
javanet.staxutils.SimpleNamespaceContext
- All Implemented Interfaces:
ExtendedNamespaceContext,StaticNamespaceContext,NamespaceContext
- Direct Known Subclasses:
ElementContext
public class SimpleNamespaceContext
extends Object
implements ExtendedNamespaceContext, StaticNamespaceContext
Simple NamespaceContext implementation backed by a HashMap.
- Version:
- $Revision: 1.7 $
- Author:
- Christian Niles
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Mapmap containing bound namespaces, keyed by their prefix.protected NamespaceContextThe parent context, which may benull -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a SimpleNamespaceContext with no parent context or namespace declarations.SimpleNamespaceContext(Map namespaces) Constructs a SimpleNamespaceContext with no parent context that contains the specified prefixes.Constructs an empty SimpleNamespaceContext with the given parent.SimpleNamespaceContext(NamespaceContext parent, Map namespaces) Constructs an empty SimpleNamespaceContext with the given parent. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of namespace prefixes declared in this context.Returns anIteratorof all namespace prefixes declared within this context, irrespective of any ancestor contexts.getNamespaceURI(String prefix) Returns a reference to the parent of this context.Returns anIteratorof all namespace prefixes in scope within this context, including those inherited from ancestor contexts.getPrefixes(String nsURI) booleanisPrefixDeclared(String prefix) Determines if the specified prefix is declared within this context, irrespective of any ancestor contexts.booleanDetermines if this is a root context.setDefaultNamespace(String nsURI) Sets the default namespace in this context.voidsetParent(NamespaceContext parent) Sets the parent context used to inherit namespace bindings.Declares a namespace binding in this context.
-
Field Details
-
parent
The parent context, which may benull -
namespaces
map containing bound namespaces, keyed by their prefix. A LinkedHashMap is used to ensure thatgetPrefix(String)always returns the same prefix, unless that prefix is removed.
-
-
Constructor Details
-
SimpleNamespaceContext
public SimpleNamespaceContext()Constructs a SimpleNamespaceContext with no parent context or namespace declarations. -
SimpleNamespaceContext
Constructs a SimpleNamespaceContext with no parent context that contains the specified prefixes.- Parameters:
namespaces- A Map of namespace URIs, keyed by their prefixes.
-
SimpleNamespaceContext
Constructs an empty SimpleNamespaceContext with the given parent. The parent context will be forwarded any requests for namespaces not declared in this context.- Parameters:
parent- The parent context.
-
SimpleNamespaceContext
Constructs an empty SimpleNamespaceContext with the given parent. The parent context will be forwarded any requests for namespaces not declared in this context.- Parameters:
parent- The parent context.namespaces- A Map of namespace URIs, keyed by their prefixes.
-
-
Method Details
-
getParent
Returns a reference to the parent of this context.- Specified by:
getParentin interfaceExtendedNamespaceContext- Returns:
- The parent context, or
nullif this is a root context.
-
setParent
Sets the parent context used to inherit namespace bindings.- Parameters:
parent- The new parent context.
-
isRootContext
public boolean isRootContext()Determines if this is a root context.- Returns:
trueif this is a root context,falseotherwise.
-
getNamespaceURI
- Specified by:
getNamespaceURIin interfaceNamespaceContext
-
getPrefix
- Specified by:
getPrefixin interfaceNamespaceContext
-
isPrefixDeclared
Determines if the specified prefix is declared within this context, irrespective of any ancestor contexts.- Specified by:
isPrefixDeclaredin interfaceExtendedNamespaceContext- Parameters:
prefix- The prefix to check.- Returns:
trueif the prefix is declared in this context,falseotherwise.
-
getDeclaredPrefixes
Description copied from interface:ExtendedNamespaceContextReturns anIteratorof all namespace prefixes declared within this context, irrespective of any ancestor contexts.- Specified by:
getDeclaredPrefixesin interfaceExtendedNamespaceContext- Returns:
- An
Iteratorof prefixStrings.
-
getDeclaredPrefixCount
public int getDeclaredPrefixCount()Returns the number of namespace prefixes declared in this context.- Returns:
- The number of namespace prefixes declared in this context.
-
getPrefixes
Description copied from interface:ExtendedNamespaceContextReturns anIteratorof all namespace prefixes in scope within this context, including those inherited from ancestor contexts.- Specified by:
getPrefixesin interfaceExtendedNamespaceContext- Returns:
- An
Iteratorof prefixStrings.
-
getPrefixes
- Specified by:
getPrefixesin interfaceNamespaceContext
-
setDefaultNamespace
Sets the default namespace in this context.- Parameters:
nsURI- The default namespace URI.- Returns:
- The previously declared namespace uri, or
nullif the default prefix wasn't previously declared in this context.
-
setPrefix
Declares a namespace binding in this context.- Parameters:
prefix- The namespace prefix.nsURI- The namespace URI.- Returns:
- The previously declared namespace uri, or
nullif the prefix wasn't previously declared in this context.
-