Ejemplo n.º 1
0
  private Route verified(Route route) {
    if (route != null) {
      /*
       * Checking that parameterized routes should always have controllers
       */
      if (route.getController() == null
          || route.getController().getControllerClass() == null
          || route.getController().getControllerMethod() == null) {
        if (route.getUrl().getParameters() != null && route.getUrl().getParameters().size() > 0) {
          throw new RouteParserException(
              "Controller is not defined for route: " + prettyPrintUrl(route));
        }
      }

      if (route.getView() == null && !viewLessRouteHasControllerReturningFileType(route)) {
        throw new RouteParserException(
            "View is not defined for route: "
                + prettyPrintUrl(route)
                + "\nNo view is only allowed for controllers with return type File");
      }

      if (route.getUrl().getParameters().size() > 0) {
        if (route.getProvider() == null
            || route.getProvider().getProviderClass() == null
            || route.getProvider().getProviderMethod() == null) {
          throw new RouteParserException(
              "Provider is not defined for parameterized route: " + prettyPrintUrl(route));
        }

        for (String param : route.getUrl().getParameters()) {
          if (!route.getController().getParameters().contains(param)) {
            throw new RouteParserException(
                "Route url parameter '"
                    + param
                    + "' is not used in controller arguments for route: "
                    + prettyPrintUrl(route));
          }
        }
      } else {
        if (route.getProvider() != null) {
          throw new RouteParserException(
              "Non-parameterized route " + prettyPrintUrl(route) + " does not need a provider");
        }
      }
    }
    return route;
  }
Ejemplo n.º 2
0
 public ParsingArgs(Route route) {
   super(route);
   route.getController().setParameters(new LinkedList<String>());
 }
Ejemplo n.º 3
0
 private boolean viewLessRouteHasControllerReturningFileType(Route route) {
   return route.getController() != null
       && route.getController().getControllerMethod() != null
       && route.getController().getControllerMethod().getReturnType().equals(File.class);
 }