org.deegree.commons.xml
Class NamespaceBindings

java.lang.Object
  extended by org.deegree.commons.xml.NamespaceBindings
All Implemented Interfaces:
NamespaceContext

public class NamespaceBindings
extends Object
implements org.jaxen.NamespaceContext, NamespaceContext

Modifiable prefix to namespace (and namespace to prefix) mappings for dealing with qualified names and XPath expressions.

This class implements both org.jaxen.NamespaceContext and the javax.xml.namespace.NamespaceContext interfaces.

Version:
$Revision: 24581 $, $Date: 2010-05-26 17:05:14 +0200 (Mi, 26. Mai 2010) $
Author:
Markus Schneider , last edited by: $Author: mschneider $

Constructor Summary
NamespaceBindings()
          Creates a new instance of NamespaceContext with no bindings.
NamespaceBindings(NamespaceBindings nsContext)
          Creates a new instance of NamespaceContext that contains all the bindings from the argument context.
NamespaceBindings(NamespaceContext nsContext, Collection<String> prefixes)
          Creates a new instance of NamespaceContext that contains all the bindings from the given XML namespace context.
 
Method Summary
 NamespaceBindings addNamespace(String prefix, String namespace)
          Registers a new prefix with an assigned namespace URI.
 String getNamespaceURI(String prefix)
           
 Iterator<String> getNamespaceURIs()
          Returns all bound namespaces.
 String getPrefix(String ns)
           
 Iterator<String> getPrefixes()
          Returns all bound prefixes.
 Iterator<String> getPrefixes(String ns)
           
 String toString()
           
 String translateNamespacePrefixToUri(String prefix)
          Returns the namespace mapping for the given prefix (Jaxen method).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NamespaceBindings

public NamespaceBindings()
Creates a new instance of NamespaceContext with no bindings.


NamespaceBindings

public NamespaceBindings(NamespaceBindings nsContext)
Creates a new instance of NamespaceContext that contains all the bindings from the argument context.

Parameters:
nsContext - bindings to copy, must not be null

NamespaceBindings

public NamespaceBindings(NamespaceContext nsContext,
                         Collection<String> prefixes)
Creates a new instance of NamespaceContext that contains all the bindings from the given XML namespace context.

Parameters:
nsContext - bindings to copy, must not be null
Method Detail

addNamespace

public NamespaceBindings addNamespace(String prefix,
                                      String namespace)
Registers a new prefix with an assigned namespace URI.

Parameters:
prefix - prefix, must not be null
namespace - namespace, may be null
Returns:
this: new XPath(..., new NamespaceContext().addNamespace(...)

translateNamespacePrefixToUri

public String translateNamespacePrefixToUri(String prefix)
Returns the namespace mapping for the given prefix (Jaxen method).

Taken from the Jaxen Javadoc: In XPath, there is no such thing as a 'default namespace'. The empty prefix always resolves to the empty namespace URI. This method should return null for the empty prefix. Similarly, the prefix "xml" always resolves to the URI "http://www.w3.org/XML/1998/namespace".

Parameters:
prefix - prefix, may be null
Returns:
namespace uri, may be null (unbound)

getNamespaceURIs

public Iterator<String> getNamespaceURIs()
Returns all bound namespaces.

Returns:
bound namespaces, never null

getNamespaceURI

public String getNamespaceURI(String prefix)
Specified by:
getNamespaceURI in interface NamespaceContext

getPrefix

public String getPrefix(String ns)
Specified by:
getPrefix in interface NamespaceContext

getPrefixes

public Iterator<String> getPrefixes(String ns)
Specified by:
getPrefixes in interface NamespaceContext

getPrefixes

public Iterator<String> getPrefixes()
Returns all bound prefixes.

Returns:
bound prefixes, never null

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2011. All Rights Reserved.