Esempio n. 1
0
 /**
  * Given a target and params, this method tries to do the reverse routing and returns the path.
  *
  * <p>The params are put to placeholders in the path. The params can be a map of {@code
  * placeholder name -> value} or ordered values. If a param doesn't have a placeholder, it will be
  * put to the query part of the path.
  *
  * @return {@code null} if there's no match
  */
 public String path(final T target, final Object... params) {
   final Collection<MethodlessRouter<T>> rs = routers.values();
   for (MethodlessRouter<T> r : rs) {
     final String ret = r.path(target, params);
     if (ret != null) {
       return ret;
     }
   }
   return anyMethodRouter.path(target, params);
 }
Esempio n. 2
0
  /**
   * Given a target and params, this method tries to do the reverse routing and returns the path.
   *
   * <p>The params are put to placeholders in the path. The params can be a map of {@code
   * placeholder name -> value} or ordered values. If a param doesn't have a placeholder, it will be
   * put to the query part of the path.
   *
   * @return {@code null} if there's no match
   */
  public String path(final HttpMethod method, final T target, final Object... params) {
    MethodlessRouter<T> router = (method == null) ? anyMethodRouter : routers.get(method);

    // Fallback to anyMethodRouter if no router is found for the method
    if (router == null) {
      router = anyMethodRouter;
    }

    final String ret = router.path(target, params);
    if (ret != null) {
      return ret;
    }

    // Fallback to anyMethodRouter if the router was not anyMethodRouter and no path is found
    return (router != anyMethodRouter) ? anyMethodRouter.path(target, params) : null;
  }