global.sandbox.xmlutilities
Class NamespaceContextImpl

java.lang.Object
  extended by global.sandbox.xmlutilities.NamespaceContextImpl
All Implemented Interfaces:
javax.xml.namespace.NamespaceContext

public class NamespaceContextImpl
extends java.lang.Object
implements javax.xml.namespace.NamespaceContext

Simple implementation of the NamespaceContext.

Version:
1.1
Author:
Petr Hadraba

Field Summary
private  java.util.Map<java.lang.String,java.lang.String> namespaces
          stores namespace mappings
 
Constructor Summary
NamespaceContextImpl()
          Creates a new instance of NamespaceContextImpl and adds default namespace URIs
 
Method Summary
 void addDefaultNamespaces()
          adds default namespace URIs Default namespace URIs are DEFAULT_NS_PREFIX, XML_NS_PREFIX and XMLNS_ATTRIBUTE.
 void addNamespace(java.lang.String prefix, java.lang.String namespaceURI)
          adds namespace URI specified with prefix and URI
 void addNamespaces(java.util.Map<java.lang.String,java.lang.String> namespaceURIs)
          adds all the namespace URIs that are stored in the specified Map
 java.lang.String getNamespaceURI(java.lang.String prefix)
          returnes namespace URI that corresponds to the specified prefix
 java.lang.String getPrefix(java.lang.String namespaceURI)
          returnes the prefix for the corresponding namespace URI this method returnes the first occurrence of the prefix for given URI
 java.util.Iterator getPrefixes(java.lang.String namespaceURI)
          returnes iterator for the set of all the prefixes that correspond to the specified URI
 void removeAllNamespaces()
          removes all the namespace URIs incl. default ones
 void removeNamespaceByPrefix(java.lang.String prefix)
          removes specified namespace using prefix
 void removeNamespaceByURI(java.lang.String uri)
          removes specified namespace using URI
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

namespaces

private final java.util.Map<java.lang.String,java.lang.String> namespaces
stores namespace mappings

Constructor Detail

NamespaceContextImpl

public NamespaceContextImpl()
Creates a new instance of NamespaceContextImpl and adds default namespace URIs

Method Detail

addNamespace

public void addNamespace(java.lang.String prefix,
                         java.lang.String namespaceURI)
adds namespace URI specified with prefix and URI

Parameters:
prefix - prefix of the namespace
namespaceURI - URI of the namespace

addNamespaces

public void addNamespaces(java.util.Map<java.lang.String,java.lang.String> namespaceURIs)
adds all the namespace URIs that are stored in the specified Map

Parameters:
namespaceURIs - URIs to add, key is prefix, value is URI

addDefaultNamespaces

public void addDefaultNamespaces()
adds default namespace URIs Default namespace URIs are DEFAULT_NS_PREFIX, XML_NS_PREFIX and XMLNS_ATTRIBUTE.


removeNamespaceByPrefix

public void removeNamespaceByPrefix(java.lang.String prefix)
removes specified namespace using prefix

Parameters:
prefix - of the namespace

removeNamespaceByURI

public void removeNamespaceByURI(java.lang.String uri)
removes specified namespace using URI

Parameters:
uri - URI of the namespace to remove

removeAllNamespaces

public void removeAllNamespaces()
removes all the namespace URIs incl. default ones


getNamespaceURI

public java.lang.String getNamespaceURI(java.lang.String prefix)
returnes namespace URI that corresponds to the specified prefix

Specified by:
getNamespaceURI in interface javax.xml.namespace.NamespaceContext
Parameters:
prefix - URI of the namespace to obtain
Returns:
URI of the namespace or NULL_NS_URI if not found

getPrefix

public java.lang.String getPrefix(java.lang.String namespaceURI)
returnes the prefix for the corresponding namespace URI this method returnes the first occurrence of the prefix for given URI

Specified by:
getPrefix in interface javax.xml.namespace.NamespaceContext
Parameters:
namespaceURI - namespace URI
Returns:
prefix for the URI or null if not found

getPrefixes

public java.util.Iterator getPrefixes(java.lang.String namespaceURI)
returnes iterator for the set of all the prefixes that correspond to the specified URI

Specified by:
getPrefixes in interface javax.xml.namespace.NamespaceContext
Parameters:
namespaceURI - namespace URI
Returns:
set of prefixes (iterator) or empty set