Search in sources :

Example 6 with ActionConfigBean

use of org.eweb4j.mvc.config.bean.ActionConfigBean in project eweb4j-framework by laiweiwei.

the class ActionAnnotationConfig method parseDefaultActionConfig.

/**
	 * 解析默认的Action配置
	 * 
	 * @param methodReqMapVal
	 * @param moduleName
	 * @return
	 */
private static ActionConfigBean parseDefaultActionConfig(String methodName, String modelName) {
    String moduleName = null;
    if (modelName.equals("/")) {
        moduleName = "";
    } else {
        moduleName = modelName.endsWith("/") ? modelName.substring(0, modelName.lastIndexOf("/")) : modelName;
    }
    String uriMapping = null;
    String httpMethod = null;
    ActionConfigBean acb = new ActionConfigBean();
    if (ActionMethod.INDEX.equals(methodName)) {
        uriMapping = "/";
        httpMethod = Http.Method.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 = Http.Method.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 = Http.Method.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 = Http.Method.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 = Http.Method.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 = Http.Method.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 = Http.Method.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;
}
Also used : ResultConfigBean(org.eweb4j.mvc.config.bean.ResultConfigBean) ActionConfigBean(org.eweb4j.mvc.config.bean.ActionConfigBean)

Example 7 with ActionConfigBean

use of org.eweb4j.mvc.config.bean.ActionConfigBean in project eweb4j-framework by laiweiwei.

the class ActionAnnotationConfig method handleActionConfigInfo.

/**
	 * 处理Action配置信息
	 * 
	 * @param ru
	 * @param controller
	 * @param method
	 * @param moduleName
	 */
private void handleActionConfigInfo(ReflectUtil ru, Class<?> controller, Method method, String moduleName) {
    //log.debug("now parse the method...... moduleName->" + moduleName);
    // 这一步解析约定好的方法名doXxxAtXxx
    final ActionConfigBean action = parseUriMappingSuffix(moduleName, method);
    //log.debug("parse uri mapping by default rule -> " + action);
    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 && httpMethod.trim().length() > 0)
        action.setHttpMethod(httpMethod);
    //log.debug("parse httpMethod -> " + httpMethod);
    /* 解析出最终的uriMapping */
    String uriMapping = parseUriMapping(controller, moduleName, action.getUriMapping());
    //log.debug("parse uriMapping -> " + uriMapping);
    if (uriMapping != null && uriMapping.trim().length() > 0)
        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());
    //log.debug("parse actionConfigKey -> " + actionConfigKey);
    if (actionConfigKey == null)
        return;
    // 将读取成功的配置信息放入缓存供框架运行期使用
    //log.debug("action cache add key -> "+actionConfigKey + ", action->"  + action);
    ActionConfigBeanCache.add(actionConfigKey, action);
    ActionClassCache.add(action.getClazz(), controller);
}
Also used : ValidatorConfigBean(org.eweb4j.mvc.config.bean.ValidatorConfigBean) ActionConfigBean(org.eweb4j.mvc.config.bean.ActionConfigBean) Result(org.eweb4j.mvc.action.annotation.Result)

Example 8 with ActionConfigBean

use of org.eweb4j.mvc.config.bean.ActionConfigBean in project eweb4j-framework by laiweiwei.

the class MVCConfigBeanCreator method getActionBean.

public static ActionConfigBean getActionBean() {
    ActionConfigBean mvcBean = null;
    mvcBean = new ActionConfigBean();
    List<ResultConfigBean> rlist = new ArrayList<ResultConfigBean>();
    ResultConfigBean result = new ResultConfigBean();
    rlist.add(result);
    mvcBean.setResult(rlist);
    List<ValidatorConfigBean> vlist = new ArrayList<ValidatorConfigBean>();
    ValidatorConfigBean validator = new ValidatorConfigBean();
    List<FieldConfigBean> fieldList = new ArrayList<FieldConfigBean>();
    FieldConfigBean field = new FieldConfigBean();
    List<ParamConfigBean> paramList = new ArrayList<ParamConfigBean>();
    ParamConfigBean param = new ParamConfigBean();
    paramList.add(param);
    field.setParam(paramList);
    fieldList.add(field);
    validator.setField(fieldList);
    vlist.add(validator);
    mvcBean.setValidator(vlist);
    mvcBean.setParam(paramList);
    return mvcBean;
}
Also used : ValidatorConfigBean(org.eweb4j.mvc.config.bean.ValidatorConfigBean) ParamConfigBean(org.eweb4j.mvc.config.bean.ParamConfigBean) FieldConfigBean(org.eweb4j.mvc.config.bean.FieldConfigBean) ResultConfigBean(org.eweb4j.mvc.config.bean.ResultConfigBean) ArrayList(java.util.ArrayList) ActionConfigBean(org.eweb4j.mvc.config.bean.ActionConfigBean)

Example 9 with ActionConfigBean

use of org.eweb4j.mvc.config.bean.ActionConfigBean in project eweb4j-framework by laiweiwei.

the class ActionConfigBeanCache method add.

/*
	public static boolean containsKey(Class<?> clazz) {
		return ACTION_CFG_BEAN.containsKey(clazz);
	}*/
public static void add(String beanID, ActionConfigBean o) {
    if (beanID != null && o != null) {
        String info = null;
        if (!ACTION_CFG_BEAN.containsKey(beanID)) {
            ACTION_CFG_BEAN.put(beanID, o);
            info = "http -> " + beanID + " mapping to class -> " + o.getClazz() + "." + o.getMethod() + " ok";
        } 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 {
                    info = "the http -> " + beanID + " is exists";
                }
            } else {
                ACTION_CFG_BEAN.put(beanID, o);
                info = "http -> " + beanID + " mapping to class -> " + o.getClazz() + "." + o.getMethod() + " ok";
            }
        }
        log.debug(info);
    }
}
Also used : ActionConfigBean(org.eweb4j.mvc.config.bean.ActionConfigBean)

Aggregations

ActionConfigBean (org.eweb4j.mvc.config.bean.ActionConfigBean)9 ResultConfigBean (org.eweb4j.mvc.config.bean.ResultConfigBean)3 ValidatorConfigBean (org.eweb4j.mvc.config.bean.ValidatorConfigBean)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ConfigBean (org.eweb4j.config.bean.ConfigBean)2 FieldConfigBean (org.eweb4j.mvc.config.bean.FieldConfigBean)2 ParamConfigBean (org.eweb4j.mvc.config.bean.ParamConfigBean)2 File (java.io.File)1 Method (java.lang.reflect.Method)1 Iterator (java.util.Iterator)1 Entry (java.util.Map.Entry)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 CheckConfigBean (org.eweb4j.config.CheckConfigBean)1 LogConfigBean (org.eweb4j.config.bean.LogConfigBean)1 IOCConfigBean (org.eweb4j.ioc.config.bean.IOCConfigBean)1 Result (org.eweb4j.mvc.action.annotation.Result)1 InterConfigBean (org.eweb4j.mvc.config.bean.InterConfigBean)1 ORMConfigBean (org.eweb4j.orm.config.bean.ORMConfigBean)1