org.exist.fluent
Class NamespaceMap

java.lang.Object
  extended by org.exist.fluent.NamespaceMap
All Implemented Interfaces:
Cloneable

public class NamespaceMap
extends Object
implements Cloneable

A map of short keys to namespace uris that can be cascaded. Use the empty string as the key for the default namespace.

Author:
Piotr Kaminski

Constructor Summary
NamespaceMap(String... args)
          Create a new namespace map with no inherited bindings.
 
Method Summary
 void clear()
          Clear all bindings from this map.
 NamespaceMap clone()
          Return a clone of this map.
 boolean equals(Object o)
           
 NamespaceMap extend()
          Create a namespace map inheriting from this one.
 String get(String key)
          Get the URI bound to the given key, either in this map or the closest inherited one.
 Map<String,String> getCombinedMap()
          Return a realized map of keys to URIs that combines all information inherited from parents.
 int hashCode()
           
 boolean isFreshFrom(NamespaceMap freshParent)
          Return whether this namespace map contains no bindings other than inherited ones, and inherits from the given parent.
static boolean isReservedPrefix(String prefix)
          Return whether the given prefix is reserved by the XML spec and should not be manually bound to namespaces.
 void put(String key, String uri)
          Bind the given key to the given URI in this map.
 void putAll(NamespaceMap that)
          Put all bindings from the given map into this one.
 void remove(String key)
          Remove any binding for the given key from the map.
 void replaceWith(NamespaceMap that)
          Sever inheritance connections and replace all bindings with ones from the given map.
 void sever()
          Sever this namespace map from its parents.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NamespaceMap

public NamespaceMap(String... args)
Create a new namespace map with no inherited bindings. Immediate bindings can be specified as a list of key-URI pairs.

Parameters:
args - a list interleaving keys and their associated URIs; its length must be even
Method Detail

isReservedPrefix

public static boolean isReservedPrefix(String prefix)
Return whether the given prefix is reserved by the XML spec and should not be manually bound to namespaces.

Parameters:
prefix - the prefix to check
Returns:
true if the prefix is reserved, false if it's available for binding

extend

public NamespaceMap extend()
Create a namespace map inheriting from this one. If this new map lacks a binding, it will be looked up in the parent. New bindings will always be entered in this map, and may override the parent's bindings.

Returns:
an extension of this map

clone

public NamespaceMap clone()
Return a clone of this map. The immediate bindings are cloned, but the ineritance chain remains unaltered.

Overrides:
clone in class Object
Returns:
a combined clone of this map cascade

sever

public void sever()
Sever this namespace map from its parents. The contents are collapsed prior to the map being severed, so the mappings are not affected. However, any future changes to the previous parents will have no effect on this map. Calling clear() on a severed map is guaranteed to clear all bindings.


get

public String get(String key)
Get the URI bound to the given key, either in this map or the closest inherited one. If the key is not bound, return null.

Parameters:
key - the key to look up
Returns:
the bound URI or null if none

put

public void put(String key,
                String uri)
Bind the given key to the given URI in this map. If the key was already bound in this map, the binding is overwritten. If the key was bound in an inherited map, it is overriden.

Parameters:
key - the key to use
uri - the namespace URI to bind

remove

public void remove(String key)
Remove any binding for the given key from the map. Has no effect if the key is not bound in this map. If the key binding is inherited, the binding is not affected.

Parameters:
key - the key to remove

clear

public void clear()
Clear all bindings from this map. Does not affect any inherited bindings.


putAll

public void putAll(NamespaceMap that)
Put all bindings from the given map into this one. Bindings inherited by the given map are included. Existing bindings may be overwritten or overriden, as appropriate.

Parameters:
that - the map to copy bindings from

replaceWith

public void replaceWith(NamespaceMap that)
Sever inheritance connections and replace all bindings with ones from the given map. Equivalent to calling sever(), clear() and putAll(NamespaceMap) in sequence.

Parameters:
that - the map to copy bindings from

getCombinedMap

public Map<String,String> getCombinedMap()
Return a realized map of keys to URIs that combines all information inherited from parents. This is effectively the map that is used for lookups, but it is normally kept in virtual form for efficiency. The map returned is a copy and is safe for mutation. The map does not include reserved bindings.

Returns:
a combined map of keys to namespace uris

isFreshFrom

public boolean isFreshFrom(NamespaceMap freshParent)
Return whether this namespace map contains no bindings other than inherited ones, and inherits from the given parent.

Parameters:
freshParent - the fresh parent to compare against
Returns:
true if this namespace map is empty except for possible inherited bindings, false otherwise

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object


Copyright (C) All rights reserved.