Class CompiledTemplate<T>
- java.lang.Object
-
- com.epimorphics.webapi.dispatch.CompiledTemplate<T>
-
public class CompiledTemplate<T> extends Object
A CompiledTemplate is a compiled URI template that can match against a path and bind variables.
Complications arise because CompiledTemplates are used in two ways. One is to match a URI path template against the path of a request URI, binding variables as necessary; this is part of the endpoint selection login. Then these is the additional possibility of the template also having query parameter which may also bind variables. The matching of the actual query parameters against the template query parameters is done separately, with variable values matching anything including / -- as opposed to anything except /, used to match path elements.
The query template matchers are rebuilt on each call rather than being compiled with the main matcher, but only because a first attempt at doing this produced a recursive loop and stack overflow.
The uri template cannot (easily) be treated as a single pattern because the order of the query parameters is irrelevant; so if A and B are submatches we'd have something like AB|BA and that's not dealing with any other -- unclaimed -- query parameters.
An ill-formed variable binding, ie an { or } not part of {NAME}, is reported by prepare as a SyntaxError exception.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCompiledTemplate.SyntaxErrorprotected static classCompiledTemplate.VarGroupIndexA VarGroupIndex associates a {} variable from a URI template with its group index in the regular expression that matches the template.
-
Field Summary
Fields Modifier and Type Field Description static Comparator<CompiledTemplate<?>>compareA MatchTemplate comparator for use in sorting.
-
Constructor Summary
Constructors Modifier Constructor Description protectedCompiledTemplate(int literals, int patterns, String template, Pattern compiled, Map<String,String> uriParamBindings, List<CompiledTemplate.VarGroupIndex> where, T value)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(CompiledTemplate<?> other)Compare this MatchTemplate with another.booleanmatch(Map<String,String> bindings, String uri, javax.ws.rs.core.MultivaluedMap<String,String> queryParams)Match the given uri string.static <T> CompiledTemplate<T>prepare(String template, T value)Answer a MatchTemplate corresponding to the template string.Stringtemplate()Answer the URI template string from which this MatchTemplate was constructed.StringtoString()Tvalue()Answer the associated value for this template.
-
-
-
Field Detail
-
compare
public static Comparator<CompiledTemplate<?>> compare
A MatchTemplate comparator for use in sorting.
-
-
Method Detail
-
compareTo
public int compareTo(CompiledTemplate<?> other)
Compare this MatchTemplate with another. The one with the most literal characters is the lesser; if they have the same number of literals, the one with the fewer patterns is the lesser. (Hence a sort will put "more specific" templates earlier.)
-
template
public String template()
Answer the URI template string from which this MatchTemplate was constructed.
-
value
public T value()
Answer the associated value for this template.
-
prepare
public static <T> CompiledTemplate<T> prepare(String template, T value)
Answer a MatchTemplate corresponding to the template string.
-
match
public boolean match(Map<String,String> bindings, String uri, javax.ws.rs.core.MultivaluedMap<String,String> queryParams)
Match the given uri string. If it matches, add entries to the bindings map so that a template variable X maps to the corresponding piece Y of the uri.- Parameters:
queryParams-
-
-