示例#1
0
  /** new version of mapping annotations */
  private MappingData mappingDataForNewAnot(Method method) {
    Path path = method.getAnnotation(Path.class);
    if (path == null) {
      return null;
    }

    MappingData reqMapping =
        new MappingData(null, null, HttpMethodType.ALL, path.value(), method.getName(), null);

    Model resultName = method.getAnnotation(Model.class);
    if (resultName != null) {
      reqMapping.resultName = resultName.value();
    }

    // resolve HTTP method
    if (method.getAnnotation(GET.class) != null) {
      reqMapping.httpMethodType = HttpMethodType.GET;
    } else if (method.getAnnotation(POST.class) != null) {
      reqMapping.httpMethodType = HttpMethodType.POST;
    } else if (method.getAnnotation(PUT.class) != null) {
      reqMapping.httpMethodType = HttpMethodType.PUT;
    } else if (method.getAnnotation(DELETE.class) != null) {
      reqMapping.httpMethodType = HttpMethodType.DELETE;
    } else if (method.getAnnotation(HEAD.class) != null) {
      reqMapping.httpMethodType = HttpMethodType.HEAD;
    } else {
      reqMapping.httpMethodType = HttpMethodType.ALL;
    }

    return reqMapping;
  }
示例#2
0
  /**
   * Method do scanning of controller's class and produce {@link ClassInvoker} object
   *
   * @param controllerClass
   * @param injector
   * @return instance of the class invoker for annotated class.
   * @throws Exception
   */
  public ClassInvoker scan(Class<?> controllerClass, Injector injector) {
    try {
      InterceptorService interceptorService = injector.getInstance(InterceptorService.class);
      if (interceptorService == null) {
        throw new IllegalStateException("The InterceptorService doesn't exists in guice module");
      }

      Controller controllerAnotation = controllerClass.getAnnotation(Controller.class);
      if (controllerAnotation == null) {
        throw new IllegalStateException(
            "Class is not defined as a controller. Missing @Controller annotation.");
      }

      // scan session attributes & default view
      List<String> sessionAttrList = Arrays.asList(controllerAnotation.sessionAttributes());

      // scan methods
      List<Method> methods = Arrays.asList(controllerClass.getMethods());
      List<MethodInvoker> scannedInvokers = new LinkedList<MethodInvoker>();
      for (Method method : methods) {
        MappingData reqMappingData = mappingDataForNewAnot(method);
        if (reqMappingData == null) {
          reqMappingData = mappingDataForNewAnot(method);
        }

        if (reqMappingData != null) {
          reqMappingData.injector = injector;
          reqMappingData.controllerClass = controllerClass;
          reqMappingData.method = method;

          // create the invoker
          MethodInvoker invoker = MethodInvokerImpl.createInvoker(reqMappingData);

          // at the end is filter decorator
          MethodInvoker filteredInvoker = new MethodInvokerFilter(reqMappingData, invoker);
          scannedInvokers.add(filteredInvoker);
        }
      }

      if (scannedInvokers != null) {
        Collections.sort(scannedInvokers);
      }

      return new ClassInvoker(controllerClass, scannedInvokers, sessionAttrList);
    } catch (Exception e) {
      throw new ScannerException(controllerClass, e);
    }
  }
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = (prime * result) + ((desc == null) ? 0 : desc.hashCode());
   result = (prime * result) + ((fieldOwner == null) ? 0 : fieldOwner.hashCode());
   result = (prime * result) + ((name == null) ? 0 : name.hashCode());
   return result;
 }
 @Override
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj == null) return false;
   if (getClass() != obj.getClass()) return false;
   FieldMappingData other = (FieldMappingData) obj;
   if (desc == null) {
     if (other.desc != null) return false;
   } else if (!desc.equals(other.desc)) return false;
   if (fieldOwner == null) {
     if (other.fieldOwner != null) return false;
   } else if (!fieldOwner.equals(other.fieldOwner)) return false;
   if (name == null) {
     if (other.name != null) return false;
   } else if (!name.equals(other.name)) return false;
   return true;
 }