public class BindingRepository<T> extends Object implements Iterable<Map.Entry<UriPattern,T>>
This is a mutable repository of bindings from UriPattern
s to some target type T. The ContainerBuilder
has a mapping of named instances of this class for RequestHandler
s, and is used to
configure the set of BindingSet
s that eventually become part of the active Container
.
Modifier and Type | Field and Description |
---|---|
private Map<UriPattern,T> |
bindings |
private static Logger |
log |
Constructor and Description |
---|
BindingRepository() |
Modifier and Type | Method and Description |
---|---|
BindingSet<T> |
activate()
Creates and returns an immutable
BindingSet that contains the bindings of this BindingRepository. |
void |
bind(String uriPattern,
T target)
Creates a
UriPattern from the given pattern string, and calls put(UriPattern, Object) . |
void |
bindAll(Map<String,T> bindings)
Convenient method for calling
bind(String, Object) for all entries in a collection of bindings. |
void |
clear()
Removes all bindings from this repository.
|
Iterator<Map.Entry<UriPattern,T>> |
iterator() |
void |
put(UriPattern uriPattern,
T target)
Binds the given target to the given
UriPattern . |
void |
putAll(Iterable<Map.Entry<UriPattern,T>> bindings)
Convenient method for calling
put(UriPattern, Object) for all entries in a collection of
bindings. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
private static final Logger log
private final Map<UriPattern,T> bindings
public void bind(String uriPattern, T target)
Creates a UriPattern
from the given pattern string, and calls put(UriPattern, Object)
.
uriPattern
- The URI pattern to parse and bind to the target.target
- The target to assign to the URI pattern.NullPointerException
- If any argument is null.IllegalArgumentException
- If the URI pattern string could not be parsed.public void bindAll(Map<String,T> bindings)
Convenient method for calling bind(String, Object)
for all entries in a collection of bindings.
bindings
- The collection of bindings to copy to this.NullPointerException
- If argument is null or contains null.public void put(UriPattern uriPattern, T target)
Binds the given target to the given UriPattern
. Although all bindings will eventually be evaluated by
a call to BindingSet.resolve(URI)
, where matching order is significant, the order in which bindings are
added is NOT. Instead, the creation of the BindingSet
in activate()
sorts the bindings in such a
way that the more strict patterns are evaluated first. See class-level commentary on UriPattern
for more
on this.
uriPattern
- The URI pattern to parse and bind to the target.target
- The target to assign to the URI pattern.NullPointerException
- If any argument is null.IllegalArgumentException
- If the pattern has already been bound to another target.public void putAll(Iterable<Map.Entry<UriPattern,T>> bindings)
Convenient method for calling put(UriPattern, Object)
for all entries in a collection of
bindings.
bindings
- The collection of bindings to copy to this.NullPointerException
- If argument is null or contains null.public BindingSet<T> activate()
Creates and returns an immutable BindingSet
that contains the bindings of this BindingRepository.
Notice that the BindingSet uses a snapshot of the current bindings so that this repository remains mutable and
reusable.
public void clear()
public Iterator<Map.Entry<UriPattern,T>> iterator()
iterator
in interface Iterable<Map.Entry<UriPattern,T>>
Copyright © 2017. All rights reserved.