// ----------------------------------------------------- // Validation // ---------- protected void doSetupValidationConfig( S2ExecuteConfig executeConfig, S2ActionMapping actionMapping, Class<?> actionClass, Method method, Execute execute, String input) { final List<S2ValidationConfig> validationConfigs = new ArrayList<S2ValidationConfig>(); final String validate = execute.validate(); boolean validator = false; if (!StringUtil.isEmpty(validate)) { final BeanDesc actionBeanDesc = actionMapping.getActionBeanDesc(); final BeanDesc actionFormBeanDesc = actionMapping.getActionFormBeanDesc(); for (String name : StringUtil.split(validate, ", ")) { if (VALIDATOR.equals(name)) { if (!execute.validator()) { throw new UnmatchValidatorAndValidateRuntimeException(actionClass, method.getName()); } validationConfigs.add(createValidationConfig()); validator = true; } else if (actionFormBeanDesc.hasMethod(name)) { final Method validateMethod = actionFormBeanDesc.getMethod(name); checkValidateMethod(actionClass, validateMethod); validationConfigs.add(createValidationConfig(validateMethod)); } else { final Method validateMethod = actionBeanDesc.getMethod(name); checkValidateMethod(actionClass, validateMethod); validationConfigs.add(createValidationConfig(validateMethod)); } } } if (!validator && execute.validator()) { validationConfigs.add(0, createValidationConfig()); } if (!validationConfigs.isEmpty() && input == null) { throw new IllegalValidatorOfExecuteMethodRuntimeException(actionClass, method.getName()); } executeConfig.setValidationConfigs(validationConfigs); }
// ----------------------------------------------------- // Reset Method // ------------ protected void doSetupResetMethod( S2ExecuteConfig executeConfig, S2ActionMapping actionMapping, Execute execute) { final String reset = execute.reset(); if (!StringUtil.isEmpty(reset)) { Method resetMethod = null; if ("reset".equals(reset)) { resetMethod = actionMapping.getActionFormBeanDesc().getMethodNoException(reset); } else { resetMethod = actionMapping.getActionFormBeanDesc().getMethod(reset); } if (resetMethod != null) { executeConfig.setResetMethod(resetMethod); } } }
// =================================================================================== // ExecuteConfig // ============= protected void setupExecuteConfig( S2ExecuteConfig executeConfig, S2ActionMapping actionMapping, Class<?> actionClass, Method method) { final Execute execute = method.getAnnotation(Execute.class); final String input = !StringUtil.isEmpty(execute.input()) ? execute.input() : null; executeConfig.setMethod(method); executeConfig.setSaveErrors(execute.saveErrors()); executeConfig.setInput(input); doSetupValidationConfig(executeConfig, actionMapping, actionClass, method, execute, input); executeConfig.setUrlPattern(execute.urlPattern()); doSetupRole(executeConfig, execute); executeConfig.setStopOnValidationError(execute.stopOnValidationError()); executeConfig.setRemoveActionForm(execute.removeActionForm()); doSetupResetMethod(executeConfig, actionMapping, execute); executeConfig.setRedirect(execute.redirect()); }
// ----------------------------------------------------- // Role // ---- protected void doSetupRole(S2ExecuteConfig executeConfig, Execute execute) { final String roles = execute.roles().trim(); if (!StringUtil.isEmpty(roles)) { executeConfig.setRoles(StringUtil.split(roles, ", ")); } }