Search in sources :

Example 1 with DAOImpl

use of org.eweb4j.orm.dao.DAOImpl in project eweb4j-framework by laiweiwei.

the class ActionExecution method assemParams.

private Object[] assemParams(Class<?>[] paramTypes, Annotation[][] paramAnns) throws Exception {
    Object[] params = new Object[paramTypes.length];
    int pathParamIndex = 0;
    for (int i = 0; i < paramTypes.length; ++i) {
        Annotation[] anns = paramAnns[i];
        Class<?> paramClass = paramTypes[i];
        String[] paramValue = null;
        // 通过给定class 获取对应的ActionContextObj
        if (Context.class.isAssignableFrom(paramClass)) {
            params[i] = this.context;
            continue;
        }
        if (HttpServletRequest.class.isAssignableFrom(paramClass)) {
            params[i] = this.context.getRequest();
            continue;
        }
        if (HttpServletResponse.class.isAssignableFrom(paramClass)) {
            params[i] = this.context.getResponse();
            continue;
        }
        if (PrintWriter.class.isAssignableFrom(paramClass)) {
            params[i] = this.context.getWriter();
            continue;
        }
        if (ServletOutputStream.class.isAssignableFrom(paramClass)) {
            params[i] = this.context.getOut();
            continue;
        }
        if (HttpSession.class.isAssignableFrom(paramClass)) {
            params[i] = this.context.getSession();
            continue;
        }
        if (ActionProp.class.isAssignableFrom(paramClass)) {
            if (this.context.getActionProp() == null)
                this.context.setActionProp(new ActionProp(this.actionObject.getClass().getName()));
            params[i] = this.context.getActionProp();
            continue;
        }
        if (Validation.class.isAssignableFrom(paramClass)) {
            params[i] = this.context.getValidation();
            continue;
        }
        if (QueryParams.class.isAssignableFrom(paramClass)) {
            params[i] = this.context.getQueryParams();
            continue;
        }
        if (DAO.class.isAssignableFrom(paramClass)) {
            params[i] = new DAOImpl("");
            continue;
        }
        if (InsertDAO.class.isAssignableFrom(paramClass)) {
            params[i] = DAOFactory.getInsertDAO();
            continue;
        }
        if (DeleteDAO.class.isAssignableFrom(paramClass)) {
            params[i] = DAOFactory.getDeleteDAO();
            continue;
        }
        if (UpdateDAO.class.isAssignableFrom(paramClass)) {
            params[i] = DAOFactory.getUpdateDAO();
            continue;
        }
        if (SelectDAO.class.isAssignableFrom(paramClass)) {
            params[i] = DAOFactory.getSelectDAO();
            continue;
        }
        if (DivPageDAO.class.isAssignableFrom(paramClass)) {
            params[i] = DAOFactory.getDivPageDAO();
            continue;
        }
        if (SearchDAO.class.isAssignableFrom(paramClass)) {
            params[i] = DAOFactory.getSearchDAO();
            continue;
        }
        if (CascadeDAO.class.isAssignableFrom(paramClass)) {
            params[i] = DAOFactory.getCascadeDAO();
            continue;
        }
        //			PathParam pathParamAnn = this.getPathParamAnn(anns);
        Annotation pathParam = JAXWSUtil.getPathParam(anns);
        if (pathParam != null) {
            paramValue = this.getPathParamValue(PathUtil.getPathParamValue(pathParam));
            params[i] = ClassUtil.getParamVal(paramClass, paramValue[0]);
            continue;
        }
        //			QueryParam queryParamAnn = this.getQueryParamAnn(anns);
        Annotation queryParamAnn = JAXWSUtil.getQueryParam(anns);
        if (queryParamAnn == null && Map.class.isAssignableFrom(paramClass)) {
            params[i] = this.context.getModel();
            continue;
        }
        //若参数有@QueryParam注解
        if (queryParamAnn != null) {
            final String fieldName = QueryParamUtil.getQueryParamValue(queryParamAnn);
            if (File.class.isAssignableFrom(paramClass)) {
                if (!this.context.getUploadMap().containsKey(fieldName))
                    continue;
                List<UploadFile> list = this.context.getUploadMap().get(fieldName);
                if (list == null || list.isEmpty())
                    continue;
                UploadFile uploadFile = list.get(0);
                File file = uploadFile.getTmpFile();
                params[i] = file;
                continue;
            }
            if (File[].class.isAssignableFrom(paramClass)) {
                if (!this.context.getUploadMap().containsKey(fieldName))
                    continue;
                List<UploadFile> list = this.context.getUploadMap().get(fieldName);
                if (list == null || list.isEmpty())
                    continue;
                File[] files = new File[list.size()];
                for (int j = 0; j < files.length; j++) files[j] = list.get(j).getTmpFile();
                params[i] = files;
            }
            if (UploadFile.class.isAssignableFrom(paramClass)) {
                if (!this.context.getUploadMap().containsKey(fieldName))
                    continue;
                List<UploadFile> list = this.context.getUploadMap().get(fieldName);
                if (list == null || list.isEmpty())
                    continue;
                UploadFile uploadFile = list.get(0);
                params[i] = uploadFile;
                continue;
            }
            if (UploadFile[].class.isAssignableFrom(paramClass)) {
                if (!this.context.getUploadMap().containsKey(fieldName))
                    continue;
                List<UploadFile> list = this.context.getUploadMap().get(fieldName);
                if (list == null || list.isEmpty())
                    continue;
                params[i] = list.toArray(new UploadFile[] {});
            }
            // 根据参数名称获取http对应的参数值
            String defaultValue = null;
            //				DefaultValue defaultValueAnn = this.getDefaultValueAnn(anns);
            Annotation defaultValueAnn = JAXWSUtil.getDefaultValue(anns);
            if (defaultValueAnn != null)
                defaultValue = QueryParamUtil.getDefaultValue(defaultValueAnn);
            paramValue = this.getQueryParamValue(fieldName, defaultValue);
            // 处理Date日期类型的参数
            if (java.util.Date.class.isAssignableFrom(paramClass)) {
                params[i] = this.getDateParam(anns, paramValue[0]);
                continue;
            }
            // 处理POJO类型的参数
            String startName = fieldName;
            if (ClassUtil.isPojo(paramClass)) {
                params[i] = this.injectParam2Pojo(paramClass, startName);
                continue;
            }
            // 处理Map类型的参数
            if (Map.class.isAssignableFrom(paramClass)) {
                params[i] = this.injectParam2Map(startName);
                continue;
            }
            //处理数组类型的参数
            if (paramClass.isArray())
                params[i] = ClassUtil.getParamVals(paramClass, paramValue);
            else
                params[i] = ClassUtil.getParamVal(paramClass, paramValue[0]);
        } else {
            // 如果是基本数据类型,则按照排序进行注入
            String[] pathParams = this.context.getActionConfigBean().getPathParams();
            if (pathParams == null) {
                log.warn("QueryParam not found and PathParam not found too");
                continue;
            }
            paramValue = this.getPathParamValue(pathParams[pathParamIndex]);
            params[i] = ClassUtil.getParamVal(paramClass, paramValue[0]);
            pathParamIndex++;
            continue;
        }
    }
    return params;
}
Also used : Annotation(java.lang.annotation.Annotation) UploadFile(org.eweb4j.mvc.upload.UploadFile) DAOImpl(org.eweb4j.orm.dao.DAOImpl) Map(java.util.Map) HashMap(java.util.HashMap) UploadFile(org.eweb4j.mvc.upload.UploadFile) File(java.io.File)

Aggregations

File (java.io.File)1 Annotation (java.lang.annotation.Annotation)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 UploadFile (org.eweb4j.mvc.upload.UploadFile)1 DAOImpl (org.eweb4j.orm.dao.DAOImpl)1