public ValidatorConfigBean create(String fieldName, ValidatorConfigBean val) { if (this.ann == null) return null; if (val == null || !Validators.ENUM.equals(val.getName())) { val = new ValidatorConfigBean(); val.setName(Validators.ENUM); } FieldConfigBean fcb = new FieldConfigBean(); fcb.setName(fieldName); fcb.setMessage(CommonUtil.parsePropValue(ann.mess())); ParamConfigBean pcb = new ParamConfigBean(); pcb.setName(Validators.ENUM_WORD_PARAM); StringBuilder sb = new StringBuilder(); for (String s : ann.words()) { if (sb.length() > 0) sb.append("#"); sb.append(CommonUtil.parsePropValue(s)); } pcb.setValue(sb.toString()); fcb.getParam().add(pcb); val.getField().add(fcb); return val; }
/** * 解析 Uri Mapping 的前部分 * * @param cls * @param moduleName * @return */ private static String parseUriMappingPrefix(Class<?> cls, String moduleName) { Path cls_path = cls.getAnnotation(Path.class); String clazzUriMapping = cls_path == null ? moduleName : cls_path.value(); clazzUriMapping = CommonUtil.parsePropValue(clazzUriMapping); return clazzUriMapping; }
private static List<String> parseProduces(Method m) { // 读取@Produces注解 Produces producesAnn = m.getAnnotation(Produces.class); List<String> pcbs = null; if (producesAnn != null) { pcbs = new ArrayList<String>(); String producesStr = CommonUtil.parsePropValue(producesAnn.value()[0]); pcbs.add(producesStr); } return pcbs; }
private static String parseShowValErrType(Class<?> cls, Method m) { ShowValMess cls_vm = cls.getAnnotation(ShowValMess.class); String clsShowValErr = cls_vm == null ? "alert" : cls_vm.value(); clsShowValErr = CommonUtil.parsePropValue(clsShowValErr); String methodShowValErr = clsShowValErr.trim().length() == 0 ? "alert" : clsShowValErr; // 验证器验证信息输出方式默认”alert“ ShowValMess m_vm = m.getAnnotation(ShowValMess.class); methodShowValErr = m_vm == null ? methodShowValErr : m_vm.value(); return methodShowValErr; }
// IOC,注入对象到pojo private void injectIocBean() throws Exception { fields = ru.getFields(); if (fields == null) return; for (Field f : fields) { Class<?> type = f.getType(); Ioc ioc = f.getAnnotation(Ioc.class); if (ioc == null) continue; String beanId = ""; if (ioc.value().trim().length() == 0) beanId = type.getSimpleName(); else beanId = CommonUtil.parsePropValue(ioc.value()); Method setter = ru.getSetter(f.getName()); if (setter == null) continue; setter.invoke(this.actionObject, IOC.getBean(beanId)); } }
/** * 解析 URI Mapping 后部分 * * @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 (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] = CommonUtil.toLowCaseFirst(pathParams[i]); pathParamSB.append("/{").append(pathParams[i]).append("}"); } if (pathParamSB.length() > 0) uriMapping = uriMapping + pathParamSB.toString(); acb.setPathParams(pathParams); } uriMapping = CommonUtil.toLowCaseFirst(uriMapping); uriMapping = CommonUtil.hump2ohter(uriMapping, "-"); if (join.length() > 0) { join = CommonUtil.toLowCaseFirst(join); join = CommonUtil.hump2ohter(join, "-"); uriMapping = uriMapping + "/" + join; } } else if (m_path == null) { /* 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; } } if (m_path != null) { uriMapping = CommonUtil.parsePropValue(m_path.value()); } acb.setUriMapping(uriMapping); return acb; }