## 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
`protected Map` `namespaces` map containing bound namespaces, keyed by their prefix.
`protected NamespaceContext` `parent` The parent context, which may be `null`

Constructor Summary
`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
`int` `getDeclaredPrefixCount()` Returns the number of namespace prefixes declared in this context.
`Iterator` `getDeclaredPrefixes()` Returns an `Iterator` 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 an `Iterator` 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.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### parent

    protected NamespaceContext parent

  The parent context, which may be `null`

### namespaces

    protected Map namespaces

  map containing bound namespaces, keyed by their prefix. A LinkedHashMap is used to ensure that `getPrefix(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 interface `ExtendedNamespaceContext`
  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 interface `NamespaceContext`

### getPrefix

    public String getPrefix(String nsURI)

  Specified by:
    `getPrefix` in interface `NamespaceContext`

### 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 interface `ExtendedNamespaceContext`
  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 an `Iterator` of all namespace prefixes declared within this context, irrespective of any ancestor contexts.

  Specified by:
    `getDeclaredPrefixes` in interface `ExtendedNamespaceContext`
  Returns:
    An `Iterator` of prefix `String`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 an `Iterator` of all namespace prefixes in scope within this context, including those inherited from ancestor contexts.

  Specified by:
    `getPrefixes` in interface `ExtendedNamespaceContext`
  Returns:
    An `Iterator` of prefix `String`s.

### getPrefixes

    public Iterator getPrefixes(String nsURI)

  Specified by:
    `getPrefixes` in interface `NamespaceContext`

### 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.

### setPrefix

    public String setPrefix(String prefix,
                            String nsURI)

  Declares a namespace binding in this context.

  Parameters:
    `prefix` - The namespace prefix.
    `nsURI` - The namespace URI.
  Returns:
    The previously declared namespace uri, or `null` if the prefix wasn't previously declared in this context.