Package com.globalmentor.net
Class AbstractNamespaceLabelManager
- java.lang.Object
-
- com.globalmentor.collections.MapDecorator<java.net.URI,java.lang.String>
-
- com.globalmentor.net.AbstractNamespaceLabelManager
-
- All Implemented Interfaces:
java.util.Map<java.net.URI,java.lang.String>
public abstract class AbstractNamespaceLabelManager extends MapDecorator<java.net.URI,java.lang.String>
Map managing namespace URIs and labels for serialization. Mapping labels to thenull
namespace or to thenull
label is allowed.This class is not thread safe.
- Author:
- Garret Wilson
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.Map<java.net.URI,java.lang.String>
DEFAULT_NAMESPACE_URI_LABEL_MAP
The default map of namespace-label mappings.static java.util.Set<java.net.URI>
KNOWN_NAMESPACE_URIS
The set of known namespace URIs.-
Fields inherited from class com.globalmentor.collections.MapDecorator
map
-
-
Constructor Summary
Constructors Constructor Description AbstractNamespaceLabelManager()
Default constructor using a hash map.AbstractNamespaceLabelManager(java.util.Map<java.net.URI,java.lang.String> map)
Map constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
addNamespaceURI(java.net.URI namespaceURI)
Adds a namespace URI and associates it with a default label.java.lang.String
determineNamespaceLabel(java.net.URI namespaceURI)
Retrieves the label to use for the given namespace.protected abstract boolean
isLabel(java.lang.String string)
Determines whether the given string is a valid labelboolean
isRecognized(java.net.URI namespaceURI)
Determines whether the given namespace URI is that of a recognized namespace.-
Methods inherited from class com.globalmentor.collections.MapDecorator
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
-
-
-
Field Detail
-
KNOWN_NAMESPACE_URIS
public static final java.util.Set<java.net.URI> KNOWN_NAMESPACE_URIS
The set of known namespace URIs.
-
DEFAULT_NAMESPACE_URI_LABEL_MAP
public static final java.util.Map<java.net.URI,java.lang.String> DEFAULT_NAMESPACE_URI_LABEL_MAP
The default map of namespace-label mappings.
-
-
Constructor Detail
-
AbstractNamespaceLabelManager
public AbstractNamespaceLabelManager()
Default constructor using a hash map.
-
AbstractNamespaceLabelManager
public AbstractNamespaceLabelManager(java.util.Map<java.net.URI,java.lang.String> map)
Map constructor.- Parameters:
map
- The map this map should decorate.- Throws:
java.lang.NullPointerException
- if the provided map isnull
.
-
-
Method Detail
-
isRecognized
public boolean isRecognized(java.net.URI namespaceURI)
Determines whether the given namespace URI is that of a recognized namespace. A namespace is recognized if a label has been associated with the given namespace URI or the default namespace URI label map has a record of this namespace.- Parameters:
namespaceURI
- A namespace URId- Returns:
true
if a label has been associated with the given namespace URI or if a label is known that could be associated with this namespace URI.- See Also:
DEFAULT_NAMESPACE_URI_LABEL_MAP
-
addNamespaceURI
public boolean addNamespaceURI(java.net.URI namespaceURI)
Adds a namespace URI and associates it with a default label.- Parameters:
namespaceURI
- The namespace URI to add.- Returns:
true
if the namespace was not previously known.- Throws:
java.lang.NullPointerException
- if the given namespace URI isnull
.
-
determineNamespaceLabel
public java.lang.String determineNamespaceLabel(java.net.URI namespaceURI)
Retrieves the label to use for the given namespace. If a namespace is unrecognized (i.e. no label, including thenull
label, has been registered with the given namespace), a new one will be created and stored in the map for future use. The last package segment of any hierarchical URIs will be used as the namespace label if possible.- Parameters:
namespaceURI
- The namespace URI for which a label should be returned- Returns:
- A label for use with the given namespace, or
null
if thenull
label is assigned to the given namespace. - See Also:
isLabel(String)
-
isLabel
protected abstract boolean isLabel(java.lang.String string)
Determines whether the given string is a valid label- Parameters:
string
- The string to check for being a label.- Returns:
true
if the given string represents a valid label.- Throws:
java.lang.NullPointerException
- if the given string isnull
.
-
-