Пример #1
0
  protected static void processMethod(
      ResourceClassBuilder resourceClassBuilder, Class<?> root, Method implementation) {
    Method method = findAnnotatedMethod(root, implementation);
    if (method != null) {
      Path path = method.getAnnotation(Path.class);
      Set<String> httpMethods = IsHttpMethod.getHttpMethods(method);

      ResteasyUriBuilder builder = new ResteasyUriBuilder();
      if (root.isAnnotationPresent(Path.class)) {
        builder.path(root);
      }
      if (path != null) {
        builder.path(method);
      }
      String pathExpression = builder.getPath();
      if (pathExpression == null) pathExpression = "";

      ResourceLocatorBuilder resourceLocatorBuilder;

      if (httpMethods == null) {
        resourceLocatorBuilder = resourceClassBuilder.locator(implementation, method);
      } else {
        ResourceMethodBuilder resourceMethodBuilder =
            resourceClassBuilder.method(implementation, method);
        resourceLocatorBuilder = resourceMethodBuilder;

        for (String httpMethod : httpMethods) {
          if (httpMethod.equalsIgnoreCase(HttpMethod.GET)) resourceMethodBuilder.get();
          else if (httpMethod.equalsIgnoreCase(HttpMethod.PUT)) resourceMethodBuilder.put();
          else if (httpMethod.equalsIgnoreCase(HttpMethod.POST)) resourceMethodBuilder.post();
          else if (httpMethod.equalsIgnoreCase(HttpMethod.DELETE)) resourceMethodBuilder.delete();
          else if (httpMethod.equalsIgnoreCase(HttpMethod.OPTIONS)) resourceMethodBuilder.options();
          else if (httpMethod.equalsIgnoreCase(HttpMethod.HEAD)) resourceMethodBuilder.head();
          else resourceMethodBuilder.httpMethod(httpMethod);
        }
        Produces produces = method.getAnnotation(Produces.class);
        if (produces == null)
          produces = resourceClassBuilder.resourceClass.getClazz().getAnnotation(Produces.class);
        if (produces == null) produces = method.getDeclaringClass().getAnnotation(Produces.class);
        if (produces != null) resourceMethodBuilder.produces(produces.value());

        Consumes consumes = method.getAnnotation(Consumes.class);
        if (consumes == null)
          consumes = resourceClassBuilder.resourceClass.getClazz().getAnnotation(Consumes.class);
        if (consumes == null) consumes = method.getDeclaringClass().getAnnotation(Consumes.class);
        if (consumes != null) resourceMethodBuilder.consumes(consumes.value());
      }
      resourceLocatorBuilder.path(pathExpression);
      for (int i = 0; i < resourceLocatorBuilder.locator.params.length; i++) {
        resourceLocatorBuilder.param(i).fromAnnotations();
      }
      resourceLocatorBuilder.buildMethod();
    }
  }
Пример #2
0
 public ResourceClassBuilder buildMethod() {
   return locator.buildMethod();
 }