Exemplo n.º 1
0
  private void addRoutes(Object handler) {
    Class clazz = handler.getClass();
    for (Method method : clazz.getMethods()) {
      int modifier = method.getModifiers();
      if (!(Modifier.isPublic(modifier))) continue;

      Class<?>[] paramTypes = method.getParameterTypes();
      if (paramTypes.length != 2
          || !paramTypes[0].equals(Request.class)
          || !paramTypes[1].equals(Response.class)) continue;

      Before beforeAnn = method.getAnnotation(Before.class);
      After afterAnn = method.getAnnotation(After.class);
      Route routeAnn = method.getAnnotation(Route.class);

      if (routeAnn != null) routes.add(new MatchEntity(handler, method, routeAnn));
      else if (beforeAnn != null) before.add(new MatchEntity(handler, method, beforeAnn));
      else if (afterAnn != null) after.add(new MatchEntity(handler, method, afterAnn));
    }

    if (L.isInfoEnabled()) {
      for (MatchEntity e : routes) L.info(null, "route " + ObjectUtils.toString(e));
      for (MatchEntity e : before) L.info(null, "before " + ObjectUtils.toString(e));
      for (MatchEntity e : after) L.info(null, "after " + ObjectUtils.toString(e));
    }
  }