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
Fields Modifier and Type Field Description protected Mapnamespacesmap containing bound namespaces, keyed by their prefix.protected NamespaceContextparentThe parent context, which may benull
-
Constructor Summary
Constructors Constructor Description SimpleNamespaceContext()Constructs a SimpleNamespaceContext with no parent context or namespace declarations.SimpleNamespaceContext(Map namespaces)Constructs a SimpleNamespaceContext with no parent context that contains the specified prefixes.SimpleNamespaceContext(NamespaceContext parent)Constructs an empty SimpleNamespaceContext with the given parent.SimpleNamespaceContext(NamespaceContext parent, Map namespaces)Constructs an empty SimpleNamespaceContext with the given parent.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetDeclaredPrefixCount()Returns the number of namespace prefixes declared in this context.IteratorgetDeclaredPrefixes()Returns anIteratorof all namespace prefixes declared within this context, irrespective of any ancestor contexts.StringgetNamespaceURI(String prefix)NamespaceContextgetParent()Returns a reference to the parent of this context.StringgetPrefix(String nsURI)IteratorgetPrefixes()Returns anIteratorof all namespace prefixes in scope within this context, including those inherited from ancestor contexts.IteratorgetPrefixes(String nsURI)booleanisPrefixDeclared(String prefix)Determines if the specified prefix is declared within this context, irrespective of any ancestor contexts.booleanisRootContext()Determines if this is a root context.StringsetDefaultNamespace(String nsURI)Sets the default namespace in this context.voidsetParent(NamespaceContext parent)Sets the parent context used to inherit namespace bindings.StringsetPrefix(String prefix, String nsURI)Declares a namespace binding in this context.
-
-
-
Field Detail
-
parent
protected NamespaceContext parent
The parent context, which may benull
-
namespaces
protected Map 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 Detail
-
SimpleNamespaceContext
public SimpleNamespaceContext()
Constructs a SimpleNamespaceContext with no parent context or namespace declarations.
-
SimpleNamespaceContext
public SimpleNamespaceContext(Map namespaces)
Constructs a SimpleNamespaceContext with no parent context that contains the specified prefixes.- Parameters:
namespaces- A Map of namespace URIs, keyed by their prefixes.
-
SimpleNamespaceContext
public SimpleNamespaceContext(NamespaceContext parent)
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
public SimpleNamespaceContext(NamespaceContext parent, Map namespaces)
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 Detail
-
getParent
public NamespaceContext 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
public void setParent(NamespaceContext parent)
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
public String getNamespaceURI(String prefix)
- Specified by:
getNamespaceURIin interfaceNamespaceContext
-
getPrefix
public String getPrefix(String nsURI)
- Specified by:
getPrefixin interfaceNamespaceContext
-
isPrefixDeclared
public boolean isPrefixDeclared(String prefix)
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
public Iterator 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
public Iterator 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
public Iterator getPrefixes(String nsURI)
- Specified by:
getPrefixesin interfaceNamespaceContext
-
setDefaultNamespace
public String setDefaultNamespace(String nsURI)
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.
-
-