Package org.springmodules.validation.bean.rule

Examples of org.springmodules.validation.bean.rule.ValidationRule


     * @param errors The {@link Errors} instance where all global validation errors will be registered.
     */
    protected void applyGlobalValidationRules(BeanValidationConfiguration configuration, Object obj, Errors errors) {
        ValidationRule[] globalRules = configuration.getGlobalRules();
        for (int i=0; i<globalRules.length; i++) {
            ValidationRule rule = globalRules[i];
            if (rule.isApplicable(obj) && !rule.getCondition().check(obj)) {
                String errorCode = errorCodeConverter.convertGlobalErrorCode(rule.getErrorCode(), obj.getClass());

                // if there is a nested path in errors, the global errors should be registered as field errors
                // for the nested path. Otherwise, they should be registered as global errors. Starting from Spring 2.0-rc2
                // this is actually not required - it's just enough to call rejectValue() with null as the field name,
                // but we keep this implementation for now to support earlier versions.

                if (StringUtils.hasLength(errors.getNestedPath())) {
                    String nestedPath = errors.getNestedPath();
                    String propertyName = nestedPath.substring(0, nestedPath.length() - 1);
                    errors.popNestedPath();
                    errors.rejectValue(propertyName, errorCode, rule.getErrorArguments(obj), rule.getDefaultErrorMessage());
                    errors.pushNestedPath(propertyName);
                } else {
                    errors.reject(errorCode, rule.getErrorArguments(obj), rule.getDefaultErrorMessage());
                }
            }
        }
    }
View Full Code Here


     * @param obj The validated object.
     * @param errors The {@link Errors} instance where the validation errors will be registered.
     */
    protected void validateAndShortCircuitRules(ValidationRule[] rules, String propertyName, Object obj, Errors errors) {
        for (int i=0; i<rules.length; i++) {
            ValidationRule rule = rules[i];
            if (rule.isApplicable(obj) && !rule.getCondition().check(obj)) {
                String errorCode = errorCodeConverter.convertPropertyErrorCode(rule.getErrorCode(), obj.getClass(), propertyName);
                errors.rejectValue(propertyName, errorCode, rule.getErrorArguments(obj), rule.getDefaultErrorMessage());
                return;
            }
        }
    }
View Full Code Here

     */
    public void validate(Object obj, Errors errors) {

        // validating using the registered global rules
        for (Iterator iter = globalRules.iterator(); iter.hasNext();) {
            ValidationRule rule = (ValidationRule)iter.next();
            if (rule.isApplicable(obj) && !rule.getCondition().check(obj)) {
                errors.reject(rule.getErrorCode(), rule.getErrorArguments(obj), rule.getDefaultErrorMessage());
            }
        }

        // validating using the registered field rules
        for (Iterator names = rulesByProperty.keySet().iterator(); names.hasNext();) {
            String propertyName = (String)names.next();
            List rules = (List)rulesByProperty.get(propertyName);
            for (Iterator iter = rules.iterator(); iter.hasNext();) {
                ValidationRule rule = (ValidationRule)iter.next();
                if (rule.isApplicable(obj) && !rule.getCondition().check(obj)) {
                    errors.rejectValue(propertyName, rule.getErrorCode(), rule.getErrorArguments(obj), rule.getDefaultErrorMessage());
                }
            }
        }
    }
View Full Code Here

     */
    public void validate(Object obj, Errors errors) {

        // validating using the registered global rules
        for (Iterator iter = globalRules.iterator(); iter.hasNext();) {
            ValidationRule rule = (ValidationRule) iter.next();
            if (rule.isApplicable(obj) && !rule.getCondition().check(obj)) {
                errors.reject(rule.getErrorCode(), rule.getErrorArguments(obj), rule.getDefaultErrorMessage());
            }
        }

        // validating using the registered field rules
        for (Iterator names = rulesByProperty.keySet().iterator(); names.hasNext();) {
            String propertyName = (String) names.next();
            List rules = (List) rulesByProperty.get(propertyName);
            for (Iterator iter = rules.iterator(); iter.hasNext();) {
                ValidationRule rule = (ValidationRule) iter.next();
                if (rule.isApplicable(obj) && !rule.getCondition().check(obj)) {
                    errors.rejectValue(propertyName, rule.getErrorCode(), rule.getErrorArguments(obj), rule
                            .getDefaultErrorMessage());
                }
            }
        }
    }
View Full Code Here

     * @param errors The {@link Errors} instance where all global validation errors will be registered.
     */
    protected void applyGlobalValidationRules(BeanValidationConfiguration configuration, Object obj, Errors errors) {
        ValidationRule[] globalRules = configuration.getGlobalRules();
        for (int i = 0; i < globalRules.length; i++) {
            ValidationRule rule = globalRules[i];
            if (rule.isApplicable(obj) && !rule.getCondition().check(obj)) {
                String errorCode = errorCodeConverter.convertGlobalErrorCode(rule.getErrorCode(), obj.getClass());

                // if there is a nested path in errors, the global errors should be registered as field errors
                // for the nested path. Otherwise, they should be registered as global errors. Starting from Spring 2.0-rc2
                // this is actually not required - it's just enough to call rejectValue() with null as the field name,
                // but we keep this implementation for now to support earlier versions.

                if (StringUtils.hasLength(errors.getNestedPath())) {
                    String nestedPath = errors.getNestedPath();
                    String propertyName = nestedPath.substring(0, nestedPath.length() - 1);
                    errors.popNestedPath();
                    errors.rejectValue(propertyName, errorCode, rule.getErrorArguments(obj), rule.getDefaultErrorMessage());
                    errors.pushNestedPath(propertyName);
                } else {
                    errors.reject(errorCode, rule.getErrorArguments(obj), rule.getDefaultErrorMessage());
                }
            }
        }
    }
View Full Code Here

     * @param obj The validated object.
     * @param errors The {@link Errors} instance where the validation errors will be registered.
     */
    protected void validateAndShortCircuitRules(ValidationRule[] rules, String propertyName, Object obj, Errors errors) {
        for (int i = 0; i < rules.length; i++) {
            ValidationRule rule = rules[i];
            if (rule.isApplicable(obj) && !rule.getCondition().check(obj)) {
                String errorCode = errorCodeConverter.convertPropertyErrorCode(rule.getErrorCode(), obj.getClass(), propertyName);
                errors.rejectValue(propertyName, errorCode, rule.getErrorArguments(obj), rule.getDefaultErrorMessage());
                if (shortCircuitFieldValidation) {
                    return;
                }
            }
        }
View Full Code Here

     * @param errors The {@link Errors} instance where all global validation errors will be registered.
     */
    protected void applyGlobalValidationRules(BeanValidationConfiguration configuration, Object obj, Errors errors) {
        ValidationRule[] globalRules = configuration.getGlobalRules();
        for (int i = 0; i < globalRules.length; i++) {
            ValidationRule rule = globalRules[i];
            if (rule.isApplicable(obj) && !rule.getCondition().check(obj)) {
                String errorCode = errorCodeConverter.convertGlobalErrorCode(rule.getErrorCode(), obj.getClass());

                // if there is a nested path in errors, the global errors should be registered as field errors
                // for the nested path. Otherwise, they should be registered as global errors. Starting from Spring 2.0-rc2
                // this is actually not required - it's just enough to call rejectValue() with null as the field name,
                // but we keep this implementation for now to support earlier versions.

                if (StringUtils.hasLength(errors.getNestedPath())) {
                    String nestedPath = errors.getNestedPath();
                    String propertyName = nestedPath.substring(0, nestedPath.length() - 1);
                    errors.popNestedPath();
                    errors.rejectValue(propertyName, errorCode, rule.getErrorArguments(obj), rule.getDefaultErrorMessage());
                    errors.pushNestedPath(propertyName);
                } else {
                    errors.reject(errorCode, rule.getErrorArguments(obj), rule.getDefaultErrorMessage());
                }
            }
        }
    }
View Full Code Here

     * @param obj The validated object.
     * @param errors The {@link Errors} instance where the validation errors will be registered.
     */
    protected void validateAndShortCircuitRules(ValidationRule[] rules, String propertyName, Object obj, Errors errors) {
        for (int i = 0; i < rules.length; i++) {
            ValidationRule rule = rules[i];
            if (rule.isApplicable(obj) && !rule.getCondition().check(obj)) {
                String errorCode = errorCodeConverter.convertPropertyErrorCode(rule.getErrorCode(), obj.getClass(), propertyName);
                errors.rejectValue(propertyName, errorCode, rule.getErrorArguments(obj), rule.getDefaultErrorMessage());
                if (shortCircuitFieldValidation) {
                    return;
                }
            }
        }
View Full Code Here

     */
    public void validate(Object obj, Errors errors) {

        // validating using the registered global rules
        for (Iterator iter = globalRules.iterator(); iter.hasNext();) {
            ValidationRule rule = (ValidationRule) iter.next();
            if (rule.isApplicable(obj) && !rule.getCondition().check(obj)) {
                errors.reject(rule.getErrorCode(), rule.getErrorArguments(obj), rule.getDefaultErrorMessage());
            }
        }

        // validating using the registered field rules
        for (Iterator names = rulesByProperty.keySet().iterator(); names.hasNext();) {
            String propertyName = (String) names.next();
            List rules = (List) rulesByProperty.get(propertyName);
            for (Iterator iter = rules.iterator(); iter.hasNext();) {
                ValidationRule rule = (ValidationRule) iter.next();
                if (rule.isApplicable(obj) && !rule.getCondition().check(obj)) {
                    errors.rejectValue(propertyName, rule.getErrorCode(), rule.getErrorArguments(obj), rule.getDefaultErrorMessage());
                }
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.springmodules.validation.bean.rule.ValidationRule

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.