global.sandbox.xmlutilities
Class NamespaceContextImpl

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

public class NamespaceContextImpl
extends Object
implements NamespaceContext

Simple implementation of the NamespaceContext.

Version:
1.1
Author:
Petr Hadraba

Field Summary
private  Map<String,String> namespaces
          Stores name space mappings.
 
Constructor Summary
  NamespaceContextImpl()
          Creates a new instance of NamespaceContextImpl and adds default name space URIs.
private NamespaceContextImpl(Void v)
          Internal constructor for empty context without defaults.
 
Method Summary
 void addDefaultNamespaces()
          Adds default name space URIs.
private  void addDefaultNamespaces0()
          Adds default name space URIs.
 void addNamespace(String prefix, String namespaceURI)
          Adds name space URI specified with prefix and URI.
 void addNamespaces(Map<String,String> namespaceURIs)
          Adds all the name space URIs that are stored in the specified Map.
static NamespaceContextImpl emptyNamespaceContext()
          Factory method which creates empty name space context without defaults.
 String getNamespaceURI(String prefix)
          Returns name space URI that corresponds to the specified prefix.
 String getPrefix(String namespaceURI)
          Returns the prefix for the corresponding name space URI.
 Iterator<String> getPrefixes(String namespaceURI)
          Returns iterator for the set of all the prefixes that correspond to the specified URI.
static NamespaceContextImpl namespaceContextWithDefaults()
          Factory method which creates empty name space context with defaults.
 void removeAllNamespaces()
          Removes all the name space URIs including default ones.
 void removeNamespaceByPrefix(String prefix)
          Removes specified name space specified by prefix.
 void removeNamespaceByURI(String uri)
          Removes specified name space specified by URI.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

namespaces

private final Map<String,String> namespaces
Stores name space mappings.

Constructor Detail

NamespaceContextImpl

public NamespaceContextImpl()
Creates a new instance of NamespaceContextImpl and adds default name space URIs.


NamespaceContextImpl

private NamespaceContextImpl(Void v)
Internal constructor for empty context without defaults.

Parameters:
v - null
Method Detail

emptyNamespaceContext

public static NamespaceContextImpl emptyNamespaceContext()
Factory method which creates empty name space context without defaults.

Returns:
empty name space context

namespaceContextWithDefaults

public static NamespaceContextImpl namespaceContextWithDefaults()
Factory method which creates empty name space context with defaults.

Returns:
new name space context with defaults

addNamespace

public void addNamespace(String prefix,
                         String namespaceURI)
Adds name space URI specified with prefix and URI.

Parameters:
prefix - prefix of the name space
namespaceURI - URI of the name space

addNamespaces

public void addNamespaces(Map<String,String> namespaceURIs)
Adds all the name space 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 name space URIs. Default name space URIs are DEFAULT_NS_PREFIX, XML_NS_PREFIX and XMLNS_ATTRIBUTE.


addDefaultNamespaces0

private void addDefaultNamespaces0()
Adds default name space URIs. Default name space URIs are DEFAULT_NS_PREFIX, XML_NS_PREFIX and XMLNS_ATTRIBUTE.


removeNamespaceByPrefix

public void removeNamespaceByPrefix(String prefix)
Removes specified name space specified by prefix.

Parameters:
prefix - of the name space

removeNamespaceByURI

public void removeNamespaceByURI(String uri)
Removes specified name space specified by URI.

Parameters:
uri - URI of the name space to remove

removeAllNamespaces

public void removeAllNamespaces()
Removes all the name space URIs including default ones.


getNamespaceURI

public String getNamespaceURI(String prefix)
Returns name space URI that corresponds to the specified prefix.

Specified by:
getNamespaceURI in interface NamespaceContext
Parameters:
prefix - URI of the name space to obtain
Returns:
URI of the name space or NULL_NS_URI if not found

getPrefix

public String getPrefix(String namespaceURI)
Returns the prefix for the corresponding name space URI.

Specified by:
getPrefix in interface NamespaceContext
Parameters:
namespaceURI - name space URI
Returns:
prefix for the URI or null if not found

getPrefixes

public Iterator<String> getPrefixes(String namespaceURI)
Returns iterator for the set of all the prefixes that correspond to the specified URI.

Specified by:
getPrefixes in interface NamespaceContext
Parameters:
namespaceURI - name space URI
Returns:
set of prefixes (iterator) or empty set


Copyright © 2006–2017. All rights reserved.