Class BindingRepository<T>
- java.lang.Object
-
- com.yahoo.jdisc.application.BindingRepository<T>
-
- All Implemented Interfaces:
java.lang.Iterable<java.util.Map.Entry<UriPattern,T>>
public class BindingRepository<T> extends java.lang.Object implements java.lang.Iterable<java.util.Map.Entry<UriPattern,T>>
This is a mutable repository of bindings from
UriPattern
s to some target type T. TheContainerBuilder
has a mapping of named instances of this class forRequestHandler
s, and is used to configure the set ofBindingSet
s that eventually become part of the activeContainer
.- Author:
- Simon Thoresen Hult
-
-
Constructor Summary
Constructors Constructor Description BindingRepository()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BindingSet<T>
activate()
Creates and returns an immutableBindingSet
that contains the bindings of this BindingRepository.void
bind(java.lang.String uriPattern, T target)
Creates aUriPattern
from the given pattern string, and callsput(UriPattern, Object)
.void
bindAll(java.util.Map<java.lang.String,T> bindings)
Convenient method for callingbind(String, Object)
for all entries in a collection of bindings.void
clear()
Removes all bindings from this repository.java.util.Iterator<java.util.Map.Entry<UriPattern,T>>
iterator()
void
put(UriPattern uriPattern, T target)
Binds the given target to the givenUriPattern
.void
putAll(java.lang.Iterable<java.util.Map.Entry<UriPattern,T>> bindings)
Convenient method for callingput(UriPattern, Object)
for all entries in a collection of bindings.
-
-
-
Method Detail
-
bind
public void bind(java.lang.String uriPattern, T target)
Creates a
UriPattern
from the given pattern string, and callsput(UriPattern, Object)
.- Parameters:
uriPattern
- The URI pattern to parse and bind to the target.target
- The target to assign to the URI pattern.- Throws:
java.lang.NullPointerException
- If any argument is null.java.lang.IllegalArgumentException
- If the URI pattern string could not be parsed.
-
bindAll
public void bindAll(java.util.Map<java.lang.String,T> bindings)
Convenient method for calling
bind(String, Object)
for all entries in a collection of bindings.- Parameters:
bindings
- The collection of bindings to copy to this.- Throws:
java.lang.NullPointerException
- If argument is null or contains null.
-
put
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 toBindingSet.resolve(URI)
, where matching order is significant, the order in which bindings are added is NOT. Instead, the creation of theBindingSet
inactivate()
sorts the bindings in such a way that the more strict patterns are evaluated first. See class-level commentary onUriPattern
for more on this.- Parameters:
uriPattern
- The URI pattern to parse and bind to the target.target
- The target to assign to the URI pattern.- Throws:
java.lang.NullPointerException
- If any argument is null.java.lang.IllegalArgumentException
- If the pattern has already been bound to another target.
-
putAll
public void putAll(java.lang.Iterable<java.util.Map.Entry<UriPattern,T>> bindings)
Convenient method for calling
put(UriPattern, Object)
for all entries in a collection of bindings.- Parameters:
bindings
- The collection of bindings to copy to this.- Throws:
java.lang.NullPointerException
- If argument is null or contains null.
-
activate
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.- Returns:
- The created BindingSet instance.
-
clear
public void clear()
Removes all bindings from this repository.
-
iterator
public java.util.Iterator<java.util.Map.Entry<UriPattern,T>> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<T>
-
-