Class 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.

    • 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 -