Package org.springframework.validation

Examples of org.springframework.validation.Validator


   
    public void addValidator(Object validator)
    {
        if (validator != null) {
            if (Validator.class.isInstance(validator)) {
                Validator val = (Validator) validator;
                this.validators.add(val);
            }
        }
    }
View Full Code Here


        return getValidator(this.getClassFromName(classSimpleName));
    }
   
    protected Validator getValidator(Class clazz)
    {
        Validator validValidator = null;
        if (clazz != null)
        {
            for (Validator validator : this.validators)
                if ((validValidator == null) && (validator.supports(clazz)))
                    validValidator = validator;
View Full Code Here

    {
        String message = null;
        if ((fieldName == null) || (fieldName.indexOf(".") < 0)) throw new DWRBindException(fieldName);
        String className = fieldName.substring(0, fieldName.lastIndexOf("."));
        Class<?> clazz = this.getClassFromName(className);
        Validator validator = this.getValidator(clazz);
        if (validator != null)
        {
            String field = fieldName.substring(fieldName.lastIndexOf(".") + 1);
            String capitalizedField = StringUtils.capitalize(field);
            Object formBackingObject = clazz.newInstance();
View Full Code Here

    public Errors validateObject(Object object) throws Exception {
        Errors errors = null;
        if (object != null)
        {
            Validator validator = this.getValidator(object.getClass());
            if (validator != null)
            {
                errors = new DirectFieldBindingResult(object, "command");
                Class[] validationArgs = new Class[] { Object.class, Errors.class };
                String methodName = "validate";
                Method method = validator.getClass().getMethod(methodName, validationArgs);
                if (method != null)
                {
                    if (log.isDebugEnabled()) log.debug("Invoking  " + methodName + " on " + validator);
                    method.invoke(validator, new Object[] { object, errors });
                }
                else
                    if (log.isDebugEnabled()) log.debug("No method validate found in validator " + validator.getClass());
            }
            else
                if (log.isDebugEnabled()) log.debug("No validator found for " + object.getClass());
        }
        return errors;
View Full Code Here

   
    public void addValidator(Object validator)
    {
        if (validator != null) {
            if (Validator.class.isInstance(validator)) {
                Validator val = (Validator) validator;
                this.validators.add(val);
            }
        }
    }
View Full Code Here

        return getValidator(this.getClassFromName(classSimpleName));
    }
   
    protected Validator getValidator(Class clazz)
    {
        Validator validValidator = null;
        if (clazz != null)
        {
            for (Validator validator : this.validators)
                if ((validValidator == null) && (validator.supports(clazz)))
                    validValidator = validator;
View Full Code Here

    {
        String message = null;
        if ((fieldName == null) || (fieldName.indexOf(".") < 0)) throw new DWRBindException(fieldName);
        String className = fieldName.substring(0, fieldName.lastIndexOf("."));
        Class<?> clazz = this.getClassFromName(className);
        Validator validator = this.getValidator(clazz);
        if (validator != null)
        {
            String field = fieldName.substring(fieldName.lastIndexOf(".") + 1);
            String capitalizedField = StringUtils.capitalize(field);
            Object formBackingObject = clazz.newInstance();
View Full Code Here

    public Errors validateObject(Object object) throws Exception {
        Errors errors = null;
        if (object != null)
        {
            Validator validator = this.getValidator(object.getClass());
            if (validator != null)
            {
                errors = new DirectFieldBindingResult(object, "command");
                Class[] validationArgs = new Class[] { Object.class, Errors.class };
                String methodName = "validate";
                Method method = validator.getClass().getMethod(methodName, validationArgs);
                if (method != null)
                {
                    if (log.isDebugEnabled()) log.debug("Invoking  " + methodName + " on " + validator);
                    method.invoke(validator, new Object[] { object, errors });
                }
                else
                    if (log.isDebugEnabled()) log.debug("No method validate found in validator " + validator.getClass());
            }
            else
                if (log.isDebugEnabled()) log.debug("No validator found for " + object.getClass());
        }
        return errors;
View Full Code Here

    public void testApplyCustomValidator() throws Exception {
        Object object = new Object();

        MockControl customValidatorControl = MockControl.createControl(Validator.class);
        Validator customValidator = (Validator)customValidatorControl.getMock();
        customValidator.validate(object, errors);
        configurationControl.expectAndReturn(configuration.getCustomValidator(), customValidator);

        replay();
        validator.applyCustomValidator(configuration, object, errors);
        verify();
View Full Code Here

     * @param configuration The configuration from which the custom validator will be taken from.
     * @param obj The object to be validated.
     * @param errors The {@link Errors} instance where all validation errors will be registered.
     */
    protected void applyCustomValidator(BeanValidationConfiguration configuration, Object obj, Errors errors) {
        Validator validator = configuration.getCustomValidator();
        if (validator != null) {
            if (validator.supports(obj.getClass())) {
                validator.validate(obj, errors);
            } else {
                if (logger.isWarnEnabled()) {
                    logger.warn("Validator: " + validator + " was extracted from the configuration of object: " +
                        obj + " but it is not applied for it does not support this object type: " +
                        obj.getClass().getName());
View Full Code Here

TOP

Related Classes of org.springframework.validation.Validator

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.