/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package validacion;

import org.springframework.stereotype.Service;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;


@Service
public class CodigoValidator implements Validator {

    @Override
    public boolean supports(Class<?> type) {
       return Integer.class == type;
    }

    @Override
    public void validate(Object valor, Errors errors) {
        Integer codigo = (Integer) valor;
        if (codigo < 1) {
            errors.rejectValue("codigo", "err.codigo", new Object[] {codigo},null);
        }
    }
    
}
