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 Map
namespaces
map containing bound namespaces, keyed by their prefix.protected NamespaceContext
parent
The 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 int
getDeclaredPrefixCount()
Returns the number of namespace prefixes declared in this context.Iterator
getDeclaredPrefixes()
Returns anIterator
of all namespace prefixes declared within this context, irrespective of any ancestor contexts.String
getNamespaceURI(String prefix)
NamespaceContext
getParent()
Returns a reference to the parent of this context.String
getPrefix(String nsURI)
Iterator
getPrefixes()
Returns anIterator
of all namespace prefixes in scope within this context, including those inherited from ancestor contexts.Iterator
getPrefixes(String nsURI)
boolean
isPrefixDeclared(String prefix)
Determines if the specified prefix is declared within this context, irrespective of any ancestor contexts.boolean
isRootContext()
Determines if this is a root context.String
setDefaultNamespace(String nsURI)
Sets the default namespace in this context.void
setParent(NamespaceContext parent)
Sets the parent context used to inherit namespace bindings.String
setPrefix(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:
getParent
in interfaceExtendedNamespaceContext
- Returns:
- The parent context, or
null
if 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:
true
if this is a root context,false
otherwise.
-
getNamespaceURI
public String getNamespaceURI(String prefix)
- Specified by:
getNamespaceURI
in interfaceNamespaceContext
-
getPrefix
public String getPrefix(String nsURI)
- Specified by:
getPrefix
in interfaceNamespaceContext
-
isPrefixDeclared
public boolean isPrefixDeclared(String prefix)
Determines if the specified prefix is declared within this context, irrespective of any ancestor contexts.- Specified by:
isPrefixDeclared
in interfaceExtendedNamespaceContext
- Parameters:
prefix
- The prefix to check.- Returns:
true
if the prefix is declared in this context,false
otherwise.
-
getDeclaredPrefixes
public Iterator getDeclaredPrefixes()
Description copied from interface:ExtendedNamespaceContext
Returns anIterator
of all namespace prefixes declared within this context, irrespective of any ancestor contexts.- Specified by:
getDeclaredPrefixes
in interfaceExtendedNamespaceContext
- Returns:
- An
Iterator
of prefixString
s.
-
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:ExtendedNamespaceContext
Returns anIterator
of all namespace prefixes in scope within this context, including those inherited from ancestor contexts.- Specified by:
getPrefixes
in interfaceExtendedNamespaceContext
- Returns:
- An
Iterator
of prefixString
s.
-
getPrefixes
public Iterator getPrefixes(String nsURI)
- Specified by:
getPrefixes
in 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
null
if the default prefix wasn't previously declared in this context.
-
-