Package org.eweb4j.mvc.config.bean

Examples of org.eweb4j.mvc.config.bean.ActionConfigBean


    boolean result = false;
    Map<String, List<?>> map = null;
    if (ActionConfigBeanCache.containsKey(this.context.getUri()) || (map = ActionConfigBeanCache.getByMatches(this.context.getUri(), context.getHttpMethod())) != null) {
      // 找到了action 与当前访问的uri映射
      if (map.containsKey("mvcBean")) {
        ActionConfigBean acb = (ActionConfigBean) map.get("mvcBean").get(0);
        this.context.setActionConfigBean(acb);
        result = true;
      }
    }
View Full Code Here


        if (mvcList == null || mvcList.isEmpty()) {
          error = rebuildXmlFile(configFile, ConfigErrCons.CANNOT_READ_CONFIG_INFO);
        } else {
          for (Iterator<ActionConfigBean> it = mvcList.iterator(); it.hasNext();) {
            ActionConfigBean mvc = it.next();

            // 检查MVC.Action配置是否有错误
            String error1 = CheckConfigBean.checkMVCAction(mvc,
                filePath);
            if (error1 != null)
              if (error != null)
                error += error1;
              else
                error = error1;

            // 检查MVC.Action中的Result部分配置是否有错误
            String error2 = CheckConfigBean.checkMVCResultPart(mvc.getResult(), mvc.getUriMapping(), filePath);
            if (error2 != null)
              if (error != null)
                error += error2;
              else
                error = error2;

            // 检查MVC.Action.Validator中的部分配置是否有错误
            String error4 = CheckConfigBean.checkMVCValidator(mvc.getValidator(), mvc.getUriMapping(),filePath);
            if (error4 != null)
              if (error != null)
                error += error4;
              else
                error = error4;
          }

          // 如果没有任何错误,将Action的配置信息放入缓存,供框架运行期使用
          if (error == null)
            for (Iterator<ActionConfigBean> it = mvcList.iterator(); it
                .hasNext();) {
              ActionConfigBean mvc = it.next();
              if (!"".equals(mvc.getClazz()))
                if (!"".equals(mvc.getUriMapping()))
                  ActionConfigBeanCache.add(mvc.getUriMapping(), mvc);
            }
        }
      } catch (Exception e) {
        e.printStackTrace();
        error = rebuildXmlFile(configFile,StringUtil.getExceptionString(e));
View Full Code Here

   * @param moduleName
   */
  private void handleActionConfigInfo(ReflectUtil ru,
      Class<?> controller, Method method, String moduleName) {

    final ActionConfigBean action = parseUriMappingSuffix(moduleName, method);
    if (action == null)
      return;

    action.setClazz(controller.getName());
    action.setMethod(method.getName());

    /* 解析出验证器错误信息输出类型 */
    action.setShowValErrorType(parseShowValErrType(controller, method));

    /* 解析出Http Method */
    String httpMethod = parseHttpMethodByAnnotation(controller, method);
    if (httpMethod != null)
      action.setHttpMethod(httpMethod);

    /* 解析出最终的uriMapping */
    String uriMapping = parseUriMapping(controller, moduleName, action.getUriMapping());
    if (uriMapping != null)
      action.setUriMapping(uriMapping);

    // 解析@Result注解
    Result resultAnn = method.getAnnotation(Result.class);
    if (resultAnn != null)
      action.getResult().addAll(ResultAnnUtil.readResultAnn(resultAnn));

    /* 解析@ActionLevel */
    int level = parseActionLevel(controller, method);
    action.setLevel(String.valueOf(level));

    /* 解析@Produces */
    List<String> pcbs = parseProduces(method);
    if (pcbs != null)
      action.getProduces().addAll(pcbs);

    /* 解析@Validator和各种验证器 */
    List<ValidatorConfigBean> vals = parseValidators(ru, method);
    if (vals != null)
      action.getValidator().addAll(vals);

    /* 解析最终的actionKey (包括合并http method、正则等) */
    String actionConfigKey = parseFullUriMapping(controller, method, action.getHttpMethod(), action.getUriMapping());
    if (actionConfigKey == null)
      return;

    // 将读取成功的配置信息放入缓存供框架运行期使用
    ActionConfigBeanCache.add(actionConfigKey, action);
    ActionClassCache.add(action.getClazz(), controller);
  }
View Full Code Here

   * @param moduleName
   * @param m
   * @return
   */
  private ActionConfigBean parseUriMappingSuffix(String moduleName, Method m) {
    ActionConfigBean acb = new ActionConfigBean();

    String methodName = m.getName();
    String fullName = m.toString();
    log.debug("parse action.method --> " + fullName);

    String uriMapping = null;

    Path m_path = m.getAnnotation(Path.class);
    if (m_path != null) {
      uriMapping = StringUtil.parsePropValue(m_path.value());
    } else if (methodName.startsWith(ActionMethod.PREFIX)) {
      uriMapping = methodName.substring(ActionMethod.PREFIX.length());
      // doUriBindParam1AndParam2JoinUriAtPostOrGet
      String at = null;
      int indexOfAt = methodName.indexOf(ActionMethod.AT);
      if (indexOfAt != -1) {
        at = methodName.substring(indexOfAt + ActionMethod.AT.length());
        if (methodName.startsWith(ActionMethod.PREFIX))
          uriMapping = uriMapping.substring(0,uriMapping.indexOf(ActionMethod.AT));

        String[] httpMethods = at.split(ActionMethod.OR);
        StringBuilder sb = new StringBuilder();
        for (String httpMethod : httpMethods) {
          if (sb.length() > 0)
            sb.append("|");

          sb.append(httpMethod.toUpperCase());
        }

        if (sb.length() > 0) {
          acb.setHttpMethod(sb.toString());
        }
      }
      String join = "";
      String bind;
      int indexOfBind = methodName.indexOf(ActionMethod.BIND);
      if (indexOfBind != -1) {
        if (indexOfAt != -1 && indexOfAt > indexOfBind) {
          bind = methodName.substring(indexOfBind + ActionMethod.BIND.length(),indexOfAt);
        } else {
          bind = methodName.substring(indexOfBind + ActionMethod.BIND.length());
        }

        uriMapping = uriMapping.substring(0,uriMapping.indexOf(ActionMethod.BIND));

        int indexOfJoin = bind.indexOf(ActionMethod.JOIN);
        if (indexOfJoin != -1) {
          String[] joins = bind.split(ActionMethod.JOIN);
          if (joins.length > 1) {
            bind = joins[0];
            join = joins[1];
          }
        }

        String[] pathParams = bind.split(ActionMethod.AND);
        StringBuilder pathParamSB = new StringBuilder();
        for (int i = 0; i < pathParams.length; i++) {
          pathParams[i] = StringUtil.toLowCaseFirst(pathParams[i]);
          pathParamSB.append("/{").append(pathParams[i]).append("}");
        }

        if (pathParamSB.length() > 0)
          uriMapping = uriMapping + pathParamSB.toString();

        acb.setPathParams(pathParams);
      }

      uriMapping = StringUtil.toLowCaseFirst(uriMapping);
      uriMapping = StringUtil.hump2ohter(uriMapping, "-");

      if (join.length() > 0) {
        join = StringUtil.toLowCaseFirst(join);
        join = StringUtil.hump2ohter(join, "-");
        uriMapping = uriMapping + "/" + join;
      }

    } else {
      /* 8 个默认方法 */
      ActionConfigBean defaultAcb = parseDefaultActionConfig(methodName, moduleName);
      if (defaultAcb != null) {
        acb.setHttpMethod(defaultAcb.getHttpMethod());
        acb.getResult().addAll(defaultAcb.getResult());

        uriMapping = defaultAcb.getUriMapping();
      } else {

        String info = fullName + " does not starts with '" + ActionMethod.PREFIX + "' so that can not be a valid action uri mapping";
        log.debug(info);
        return null;
View Full Code Here

    for (Iterator<Entry<Object, ActionConfigBean>> it = ACTION_CFG_BEAN
        .entrySet().iterator(); it.hasNext();) {

      Entry<Object, ActionConfigBean> entry = it.next();
      Object beanID = entry.getKey();
      ActionConfigBean mvcBean = entry.getValue();
      if (!String.class.isAssignableFrom(beanID.getClass()))
        continue;

      // 如果是String
      String regex = String.valueOf(beanID).replace(
          ActionMethod.CON + mvcBean.getHttpMethod(), "");
      if (regex.contains("{") || regex.contains("}"))
        continue;

      if (aUri.endsWith("/"))
        uri = aUri.substring(0, aUri.length() - 1);

      if (regex.endsWith("/"))
        regex = regex.substring(0, regex.length() - 1);

      String[] methods = mvcBean.getHttpMethod().split("\\|");
      boolean checkMethod = false;
      for (String m : methods) {
        if (m.trim().equalsIgnoreCase(reqMethod)) {
          checkMethod = true;
          break;
        }
      }
      if (regex != null && checkMethod && uri.matches(regex)) {
        result = new HashMap<String, List<?>>();
        // 1.hello/{name}/test/{id}
        // 2.{"hello/","{name}","/test/{id}"}
        String urlMapping = mvcBean.getUriMapping();
        // 如果urlMapping的开头是“/”要去掉
        if (urlMapping.startsWith("/"))
          urlMapping = urlMapping.substring(1);

        String pattern = RegexList.path_var_regexp;
View Full Code Here

   * @return
   */
  private static ActionConfigBean parseDefaultActionConfig(String methodName, String moduleName) {
    String uriMapping = null;
    String httpMethod = null;
    ActionConfigBean acb = new ActionConfigBean();

    if (ActionMethod.INDEX.equals(methodName)) {
      uriMapping = "/";
      httpMethod = HttpMethod.GET;
      ResultConfigBean rcb = new ResultConfigBean();
      rcb.setName("jsp");
      rcb.setLocation(moduleName + "/view/index.jsp");
      acb.getResult().add(rcb);
      ResultConfigBean rcb2 = new ResultConfigBean();
      rcb2.setName("html");
      rcb2.setType(RenderType.FREEMARKER);
      rcb2.setLocation(moduleName + "/view/index.html");
      acb.getResult().add(rcb2);
    } else if (ActionMethod.CREATE.equals(methodName)) {
      uriMapping = "/";
      httpMethod = HttpMethod.POST;

      ResultConfigBean rcb = new ResultConfigBean();
      rcb.setName(ActionMethod.INDEX);
      rcb.setLocation(moduleName);
      rcb.setType(RenderType.ACTION);
      acb.getResult().add(rcb);
    } else if (ActionMethod.UPDATE.equals(methodName)) {
      uriMapping = "/{id}";
      httpMethod = HttpMethod.PUT;
      ResultConfigBean rcb = new ResultConfigBean();
      rcb.setName(ActionMethod.INDEX);
      rcb.setLocation(moduleName);
      rcb.setType(RenderType.ACTION);
      acb.getResult().add(rcb);
    } else if (ActionMethod.SHOW.equals(methodName)) {
      uriMapping = "/{id}";
      httpMethod = HttpMethod.GET;

      ResultConfigBean rcb = new ResultConfigBean();
      rcb.setName("jsp");
      rcb.setLocation(moduleName + "/view/show.jsp");
      acb.getResult().add(rcb);
      ResultConfigBean rcb2 = new ResultConfigBean();
      rcb2.setName("html");
      rcb2.setType(RenderType.FREEMARKER);
      rcb2.setLocation(moduleName + "/view/show.html");
      acb.getResult().add(rcb2);
    } else if (ActionMethod.EDIT.equals(methodName)) {
      uriMapping = "/{id}/edit";
      httpMethod = HttpMethod.GET;
      ResultConfigBean rcb = new ResultConfigBean();
      rcb.setName("jsp");
      rcb.setLocation(moduleName + "/view/edit.jsp");
      acb.getResult().add(rcb);
      ResultConfigBean rcb2 = new ResultConfigBean();
      rcb2.setName("html");
      rcb2.setType(RenderType.FREEMARKER);
      rcb2.setLocation(moduleName + "/view/edit.html");
      acb.getResult().add(rcb2);
    } else if (ActionMethod.DESTROY.equals(methodName)) {
      uriMapping = "/{id}";
      httpMethod = HttpMethod.DELETE;

      ResultConfigBean rcb = new ResultConfigBean();
      rcb.setName(ActionMethod.INDEX);
      rcb.setLocation(moduleName);
      rcb.setType(RenderType.ACTION);
      acb.getResult().add(rcb);
    } else if (ActionMethod.NEW.equals(methodName)) {
      uriMapping = "/new";
      httpMethod = HttpMethod.GET;
      ResultConfigBean rcb = new ResultConfigBean();
      rcb.setName("jsp");
      rcb.setLocation(moduleName + "/view/new.jsp");
      acb.getResult().add(rcb);
      ResultConfigBean rcb2 = new ResultConfigBean();
      rcb2.setName("html");
      rcb2.setType(RenderType.FREEMARKER);
      rcb2.setLocation(moduleName + "/view/new.html");
      acb.getResult().add(rcb2);
    } else {
      acb = null;
    }

   
   
    if (acb != null) {
      acb.setHttpMethod(httpMethod);
      acb.setUriMapping(uriMapping);
    }
   
    return acb;
  }
View Full Code Here

      if (!ACTION_CFG_BEAN.containsKey(beanID)) {
        ACTION_CFG_BEAN.put(beanID, o);
        info = "add...finished..." + beanID + "|" + o;
      } else {
        ActionConfigBean actionBean = ACTION_CFG_BEAN.get(beanID);
        if (actionBean != null) {
          String level1 = actionBean.getLevel();
          String level2 = o.getLevel();
          if (level1 == null || level1.trim().length() == 0)
            level1 = "1";

          if (level2 == null || level2.trim().length() == 0)
            level2 = "1";

          int level_1 = 1;
          int level_2 = 1;

          if (level1.matches(RegexList.integer_regexp))
            level_1 = Integer.parseInt(level1);

          if (level2.matches(RegexList.integer_regexp))
            level_2 = Integer.parseInt(level2);

          if (level_2 > level_1) {
            ACTION_CFG_BEAN.remove(beanID);
            ACTION_CFG_BEAN.put(beanID, o);
            info = " " + actionBean.getClazz() + "#"
                + actionBean.getMethod() + "#uri-mapping:"
                + beanID + "  level[" + level_1
                + "]is lower than" + o.getClazz() + "."
                + o.getMethod() + "#uri-mapping:" + beanID
                + "level[" + level_2 + "],so replaced。";
          } else {
View Full Code Here

      String info = null;
      if (!ACTION_CFG_BEAN.containsKey(clazz)) {
        ACTION_CFG_BEAN.put(clazz, o);
        info = "add...finished..." + o;
      } else {
        ActionConfigBean actionBean = ACTION_CFG_BEAN.get(clazz);
        if (actionBean != null) {
          String level1 = actionBean.getLevel();
          String level2 = o.getLevel();
          if (level1 == null || level1.trim().length() == 0)
            level1 = "1";

          if (level2 == null || level2.trim().length() == 0)
View Full Code Here

      log.debug(info);
    }
  }

  public static ActionConfigBean get(String beanID) {
    ActionConfigBean o = null;
    if (beanID != null)
      if (ACTION_CFG_BEAN.containsKey(beanID))
        o = ACTION_CFG_BEAN.get(beanID);

    return o;
View Full Code Here

    return o;
  }

  public static ActionConfigBean get(Class<?> clazz) {
    ActionConfigBean o = null;
    if (clazz != null)
      if (ACTION_CFG_BEAN.containsKey(clazz))
        o = ACTION_CFG_BEAN.get(clazz);

    return o;
View Full Code Here

TOP

Related Classes of org.eweb4j.mvc.config.bean.ActionConfigBean

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.