Package ch.ralscha.extdirectspring.annotation

Examples of ch.ralscha.extdirectspring.annotation.ExtDirectMethod


  @SuppressWarnings({ "unchecked", "rawtypes" })
  private Object processRemotingRequest(final HttpServletRequest request, final HttpServletResponse response,
      final Locale locale, final ExtDirectRequest directRequest, final MethodInfo methodInfo) throws Exception {

    ExtDirectMethod annotation = methodInfo.getExtDirectMethodAnnotation();

    ExtDirectMethodType type = annotation.value();

    int jsonParamIndex = 0;
    Annotation[][] parameterAnnotations = methodInfo.getParameterAnnotations();
    Map<String, Object> remainingParameters = null;
    ExtDirectStoreReadRequest directStoreReadRequest = null;

    List<Object> directStoreModifyRecords = null;
    Class<?> directStoreEntryClass;

    if (type == ExtDirectMethodType.STORE_READ || type == ExtDirectMethodType.FORM_LOAD) {

      if (directRequest.getData() != null && directRequest.getData().length > 0) {
        if (type == ExtDirectMethodType.STORE_READ) {
          directStoreReadRequest = new ExtDirectStoreReadRequest();
          remainingParameters = fillObjectFromMap(directStoreReadRequest, (Map) directRequest.getData()[0]);
        } else {
          remainingParameters = (Map) directRequest.getData()[0];
        }
        jsonParamIndex = 1;
      }
    } else if (type == ExtDirectMethodType.STORE_MODIFY) {
      directStoreEntryClass = annotation.entryClass();

      if (directRequest.getData() != null && directRequest.getData().length > 0) {
        Map<String, Object> jsonData = (LinkedHashMap<String, Object>) directRequest.getData()[0];

        ArrayList<Object> records = (ArrayList<Object>) jsonData.get("records");
View Full Code Here


      String beanName = entry.getKey();

      Method[] methods = beanClass.getMethods();

      for (Method method : methods) {
        ExtDirectMethod annotation = AnnotationUtils.findAnnotation(method, ExtDirectMethod.class);
        if (annotation != null && isSameGroup(group, annotation.group())) {
          ExtDirectMethodType type = annotation.value();

          switch (type) {
          case SIMPLE:
            remotingApi.addAction(beanName, method.getName(), numberOfParameters(method));
            break;
          case FORM_LOAD:
          case STORE_READ:
          case STORE_MODIFY:
            remotingApi.addAction(beanName, method.getName(), 1);
            break;
          case FORM_POST:
            if (isValidFormPostMethod(beanClass, method)) {
              remotingApi.addAction(beanName, method.getName(), 0, true);
            } else {
              LogFactory
                  .getLog(getClass())
                  .warn("Method '"
                      + beanName
                      + "."
                      + method.getName()
                      + "' is annotated as a form post method but is not valid. "
                      + "A form post method must be annotated with @RequestMapping and method=RequestMethod.POST. Method ignored.");
            }
            break;
          case POLL:
            remotingApi.addPollingProvider(beanName, method.getName(), annotation.event());
            break;

          }

        }
View Full Code Here

        }
        this.forwardPath = "forward:" + path;
      }
    }

    ExtDirectMethod extDirectMethodAnnotation = AnnotationUtils.findAnnotation(method, ExtDirectMethod.class);
    if (extDirectMethodAnnotation != null) {
      this.type = extDirectMethodAnnotation.value();
      this.synchronizeOnSession = extDirectMethodAnnotation.synchronizeOnSession();
    }

    this.parameters = buildParameterList(clazz, method);

    for (ParameterInfo parameter : parameters) {
View Full Code Here

  private String sseMethod;

  public MethodInfo(Class<?> clazz, ApplicationContext context, String beanName, Method method) {

    ExtDirectMethod extDirectMethodAnnotation = AnnotationUtils.findAnnotation(method, ExtDirectMethod.class);

    this.type = extDirectMethodAnnotation.value();

    if (StringUtils.hasText(extDirectMethodAnnotation.group())) {
      this.group = extDirectMethodAnnotation.group().trim();
    } else {
      this.group = null;
    }

    this.synchronizeOnSession = extDirectMethodAnnotation.synchronizeOnSession();
    this.streamResponse = extDirectMethodAnnotation.streamResponse();

    if (type != ExtDirectMethodType.FORM_POST) {
      this.method = method;
      this.parameters = buildParameterList(method);

      this.collectionType = (extDirectMethodAnnotation.entryClass() == Object.class) ? null
          : extDirectMethodAnnotation.entryClass();

      if (this.collectionType == null) {
        for (ParameterInfo parameter : parameters) {
          Class<?> collType = parameter.getCollectionType();
          if (collType != null) {
            this.collectionType = collType;
            break;
          }
        }
      }
    } else {
      if (method.getReturnType().equals(Void.TYPE)) {

        RequestMapping methodAnnotation = AnnotationUtils.findAnnotation(method, RequestMapping.class);
        RequestMapping classAnnotation = AnnotationUtils.findAnnotation(clazz, RequestMapping.class);

        String path = null;
        if (hasValue(classAnnotation)) {
          path = classAnnotation.value()[0];
        }

        if (hasValue(methodAnnotation)) {
          String methodPath = methodAnnotation.value()[0];
          if (path != null) {
            path = path + methodPath;
          } else {
            path = methodPath;
          }
        }

        if (path != null) {
          if (path.charAt(0) == '/' && path.length() > 1) {
            path = path.substring(1, path.length());
          }
          this.forwardPath = "forward:" + path;
        }
      } else {
        this.handlerMethod = new HandlerMethod(beanName, context, method).createWithResolvedBean();
      }
    }

    switch (type) {
    case SIMPLE:
      int paramLength = 0;
      for (ParameterInfo parameter : this.parameters) {
        if (!parameter.isSupportedParameter() && !parameter.isHasRequestHeaderAnnotation()) {
          paramLength++;
        }
      }
      this.action = new Action(method.getName(), paramLength, null);
      break;
    case SIMPLE_NAMED:
      List<String> parameterNames = new ArrayList<String>();
      for (ParameterInfo parameter : this.parameters) {
        if (!parameter.isSupportedParameter() && !parameter.isHasRequestHeaderAnnotation()) {
          parameterNames.add(parameter.getName());
        }
      }
      this.action = new Action(method.getName(), parameterNames);
      break;
    case FORM_LOAD:
    case STORE_READ:
    case STORE_MODIFY:
    case TREE_LOAD:
      this.action = new Action(method.getName(), 1, null);
      break;
    case FORM_POST:
      this.action = new Action(method.getName(), 0, true);
      break;
    case POLL:
      this.pollingProvider = new PollingProvider(beanName, method.getName(), extDirectMethodAnnotation.event());
      break;
    case SSE:
      this.sseMethod = method.getName();
      break;
    default:
      throw new IllegalStateException("ExtDirectMethodType: " + type + " does not exists");
    }

    this.action = extractDocumentationAnnotations(extDirectMethodAnnotation.documentation());

  }
View Full Code Here

  private String sseMethod;

  public MethodInfo(Class<?> clazz, ApplicationContext context, String beanName, Method method) {

    ExtDirectMethod extDirectMethodAnnotation = AnnotationUtils.findAnnotation(method, ExtDirectMethod.class);

    this.type = extDirectMethodAnnotation.value();

    if (extDirectMethodAnnotation.jsonView() != ExtDirectMethod.NoJsonView.class) {
      this.jsonView = extDirectMethodAnnotation.jsonView();
    } else {
      this.jsonView = null;
    }

    if (StringUtils.hasText(extDirectMethodAnnotation.group())) {
      this.group = extDirectMethodAnnotation.group().trim();
    } else {
      this.group = null;
    }

    this.synchronizeOnSession = extDirectMethodAnnotation.synchronizeOnSession();
    this.streamResponse = extDirectMethodAnnotation.streamResponse();

    if (type != ExtDirectMethodType.FORM_POST) {
      this.method = method;
      this.parameters = buildParameterList(clazz, method);

      this.collectionType = (extDirectMethodAnnotation.entryClass() == Object.class) ? null
          : extDirectMethodAnnotation.entryClass();

      if (this.collectionType == null) {
        for (ParameterInfo parameter : parameters) {
          Class<?> collType = parameter.getCollectionType();
          if (collType != null) {
            this.collectionType = collType;
            break;
          }
        }
      }
    } else {
      if (method.getReturnType().equals(Void.TYPE)) {

        RequestMapping methodAnnotation = AnnotationUtils.findAnnotation(method, RequestMapping.class);
        RequestMapping classAnnotation = AnnotationUtils.findAnnotation(clazz, RequestMapping.class);

        String path = null;
        if (hasValue(classAnnotation)) {
          path = classAnnotation.value()[0];
        }

        if (hasValue(methodAnnotation)) {
          String methodPath = methodAnnotation.value()[0];
          if (path != null) {
            path = path + methodPath;
          } else {
            path = methodPath;
          }
        }

        if (path != null) {
          if (path.charAt(0) == '/' && path.length() > 1) {
            path = path.substring(1, path.length());
          }
          this.forwardPath = "forward:" + path;
        }
      } else {
        this.handlerMethod = new HandlerMethod(beanName, context, method).createWithResolvedBean();
      }
    }

    switch (type) {
    case SIMPLE:
      int paramLength = 0;
      for (ParameterInfo parameter : this.parameters) {
        if (!parameter.isSupportedParameter() && !parameter.isHasRequestHeaderAnnotation()) {
          paramLength++;
        }
      }
      this.action = new Action(method.getName(), paramLength, null);
      break;
    case SIMPLE_NAMED:
      List<String> parameterNames = new ArrayList<String>();
      for (ParameterInfo parameter : this.parameters) {
        if (!parameter.isSupportedParameter() && !parameter.isHasRequestHeaderAnnotation()) {
          parameterNames.add(parameter.getName());
        }
      }
      this.action = new Action(method.getName(), parameterNames);
      break;
    case FORM_LOAD:
    case STORE_READ:
    case STORE_MODIFY:
    case TREE_LOAD:
      this.action = new Action(method.getName(), 1, null);
      break;
    case FORM_POST:
      this.action = new Action(method.getName(), 0, true);
      break;
    case FORM_POST_JSON:
      this.action = new Action(method.getName(), 1, null);
      break;
    case POLL:
      this.pollingProvider = new PollingProvider(beanName, method.getName(), extDirectMethodAnnotation.event());
      break;
    case SSE:
      this.sseMethod = method.getName();
      break;
    default:
      throw new IllegalStateException("ExtDirectMethodType: " + type + " does not exists");
    }

    this.action = extractDocumentationAnnotations(extDirectMethodAnnotation.documentation());

  }
View Full Code Here

          return AnnotationUtils.findAnnotation(method, ExtDirectMethod.class) != null;
        }
      });

      for (Method method : methods) {
        ExtDirectMethod directMethodAnnotation = AnnotationUtils.findAnnotation(method, ExtDirectMethod.class);
        final String beanAndMethodName = beanName + "." + method.getName();
        if (directMethodAnnotation.value().isValid(beanAndMethodName, userType, method)) {
          MethodInfoCache.INSTANCE.put(beanName, handlerType, method, event.getApplicationContext());

          // /CLOVER:OFF
          if (log.isDebugEnabled()) {
            String info = "Register " + beanAndMethodName + "(" + directMethodAnnotation.value();
            if (StringUtils.hasText(directMethodAnnotation.group())) {
              info += ", " + directMethodAnnotation.group();
            }
            info += ")";
            log.debug(info);
          }
          // /CLOVER:ON
View Full Code Here

  private String sseMethod;

  public MethodInfo(Class<?> clazz, ApplicationContext context, String beanName, Method method) {

    ExtDirectMethod extDirectMethodAnnotation = AnnotationUtils.findAnnotation(method, ExtDirectMethod.class);

    this.type = extDirectMethodAnnotation.value();

    if (extDirectMethodAnnotation.jsonView() != ExtDirectMethod.NoJsonView.class) {
      this.jsonView = extDirectMethodAnnotation.jsonView();
    } else {
      this.jsonView = null;
    }

    if (StringUtils.hasText(extDirectMethodAnnotation.group())) {
      this.group = extDirectMethodAnnotation.group().trim();
    } else {
      this.group = null;
    }

    this.synchronizeOnSession = extDirectMethodAnnotation.synchronizeOnSession();
    this.streamResponse = extDirectMethodAnnotation.streamResponse();

    if (type != ExtDirectMethodType.FORM_POST) {
      this.method = method;
      this.parameters = buildParameterList(clazz, method);

      this.collectionType = (extDirectMethodAnnotation.entryClass() == Object.class) ? null
          : extDirectMethodAnnotation.entryClass();

      if (this.collectionType == null) {
        for (ParameterInfo parameter : parameters) {
          Class<?> collType = parameter.getCollectionType();
          if (collType != null) {
            this.collectionType = collType;
            break;
          }
        }
      }
    } else {
      if (method.getReturnType().equals(Void.TYPE)) {

        RequestMapping methodAnnotation = AnnotationUtils.findAnnotation(method, RequestMapping.class);
        RequestMapping classAnnotation = AnnotationUtils.findAnnotation(clazz, RequestMapping.class);

        String path = null;
        if (hasValue(classAnnotation)) {
          path = classAnnotation.value()[0];
        }

        if (hasValue(methodAnnotation)) {
          String methodPath = methodAnnotation.value()[0];
          if (path != null) {
            path = path + methodPath;
          } else {
            path = methodPath;
          }
        }

        if (path != null) {
          if (path.charAt(0) == '/' && path.length() > 1) {
            path = path.substring(1, path.length());
          }
          this.forwardPath = "forward:" + path;
        }
      } else {
        this.handlerMethod = new HandlerMethod(beanName, context, method).createWithResolvedBean();
      }
    }

    switch (type) {
    case SIMPLE:
      int paramLength = 0;
      for (ParameterInfo parameter : this.parameters) {
        if (!parameter.isSupportedParameter() && !parameter.isHasRequestHeaderAnnotation()) {
          paramLength++;
        }
      }
      this.action = new Action(method.getName(), paramLength, null);
      break;
    case SIMPLE_NAMED:
      List<String> parameterNames = new ArrayList<String>();
      for (ParameterInfo parameter : this.parameters) {
        if (!parameter.isSupportedParameter() && !parameter.isHasRequestHeaderAnnotation()) {
          parameterNames.add(parameter.getName());
        }
      }
      this.action = new Action(method.getName(), parameterNames);
      break;
    case FORM_LOAD:
    case STORE_READ:
    case STORE_MODIFY:
    case TREE_LOAD:
      this.action = new Action(method.getName(), 1, null);
      break;
    case FORM_POST:
      this.action = new Action(method.getName(), 0, true);
      break;
    case POLL:
      this.pollingProvider = new PollingProvider(beanName, method.getName(), extDirectMethodAnnotation.event());
      break;
    case SSE:
      this.sseMethod = method.getName();
      break;
    default:
      throw new IllegalStateException("ExtDirectMethodType: " + type + " does not exists");
    }

    this.action = extractDocumentationAnnotations(extDirectMethodAnnotation.documentation());

  }
View Full Code Here

          return AnnotationUtils.findAnnotation(method, ExtDirectMethod.class) != null;
        }
      });

      for (Method method : methods) {
        ExtDirectMethod directMethodAnnotation = AnnotationUtils.findAnnotation(method, ExtDirectMethod.class);
        final String beanMethodName = beanName + "." + method.getName();
        if (directMethodAnnotation.value().isValid(beanMethodName, userType, method)) {
          MethodInfoCache.INSTANCE.put(beanName, handlerType, method, event.getApplicationContext());

          // /CLOVER:OFF
          if (log.isDebugEnabled()) {
            String info = "Register " + beanMethodName + "(" + directMethodAnnotation.value();
            if (StringUtils.hasText(directMethodAnnotation.group())) {
              info += ", " + directMethodAnnotation.group();
            }
            info += ")";
            log.debug(info);
          }
          // /CLOVER:ON
View Full Code Here

        }
        this.forwardPath = "forward:" + path;
      }
    }

    ExtDirectMethod extDirectMethodAnnotation = AnnotationUtils.findAnnotation(method, ExtDirectMethod.class);
    if (extDirectMethodAnnotation != null) {
      this.type = extDirectMethodAnnotation.value();
      this.synchronizeOnSession = extDirectMethodAnnotation.synchronizeOnSession();
    }

    this.parameters = buildParameterList(clazz, method);

    for (ParameterInfo parameter : parameters) {
View Full Code Here

      String beanName = entry.getKey();

      Method[] methods = beanClass.getMethods();

      for (Method method : methods) {
        ExtDirectMethod annotation = AnnotationUtils.findAnnotation(method, ExtDirectMethod.class);
        if (annotation != null && isSameGroup(group, annotation.group())) {
          ExtDirectMethodType type = annotation.value();

          switch (type) {
          case SIMPLE:
            remotingApi.addAction(beanName, method.getName(), numberOfParameters(method));
            break;
          case SIMPLE_NAMED:
            remotingApi.addAction(beanName, method.getName(), parameterNames(beanClass, method));
            break;
          case FORM_LOAD:
          case STORE_READ:
          case STORE_MODIFY:
          case TREE_LOADER:
          case TREE_LOAD:
            remotingApi.addAction(beanName, method.getName(), 1);
            break;
          case FORM_POST:
            if (isValidFormPostMethod(beanClass, method)) {
              remotingApi.addAction(beanName, method.getName(), 0, true);
            } else {
              LogFactory
                  .getLog(getClass())
                  .warn("Method '"
                      + beanName
                      + "."
                      + method.getName()
                      + "' is annotated as a form post method but is not valid. "
                      + "A form post method must be annotated with @RequestMapping and method=RequestMethod.POST. Method ignored.");
            }
            break;
          case POLL:
            remotingApi.addPollingProvider(beanName, method.getName(), annotation.event());
            break;

          }

        }
View Full Code Here

TOP

Related Classes of ch.ralscha.extdirectspring.annotation.ExtDirectMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.