Package br.com.caelum.stella.bean.validation.logic

Source Code of br.com.caelum.stella.bean.validation.logic.StellaCPFValidator

package br.com.caelum.stella.bean.validation.logic;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import br.com.caelum.stella.bean.validation.CPF;
import br.com.caelum.stella.validation.CPFValidator;

/**
* Valida a cadeia gerada através do método {@linkplain #toString()} para
* verificar se ela está de acordo com o padrĂ£o de CPF.
*
* @author Fabio Kung
* @author Leonardo Bessa
* @author David Paniz
*/
public class StellaCPFValidator implements ConstraintValidator<CPF, String> {
  private CPFValidator stellaValidator;

  public void initialize(CPF cpf) {
    AnnotationMessageProducer messageProducer = new AnnotationMessageProducer(cpf);
    stellaValidator = new CPFValidator(messageProducer, cpf.formatted());
  }

  public boolean isValid(String cpf, ConstraintValidatorContext context) {
    if (cpf != null) {
      if (cpf.trim().length() == 0) {
        return true;
      } else {
        return stellaValidator.invalidMessagesFor(cpf).isEmpty();
      }
    } else {
      return true;
    }
  }
}
TOP

Related Classes of br.com.caelum.stella.bean.validation.logic.StellaCPFValidator

TOP
Copyright © 2018 www.massapi.com. 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.