/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bean303;

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

/**
 *
 * @author x
 */
public class ModulCheckValidator2 implements ConstraintValidator<ModulCheck,Integer>{

  /* ohne Generic
  public void initialize(Annotation a) {
    throw new UnsupportedOperationException("Not supported yet.");
  }

  public boolean isValid(Object t, ConstraintValidatorContext cvc) {
    throw new UnsupportedOperationException("Not supported yet.");
  }
   *
   */

  private boolean auch5;
  private double[] ok={1.0,1.3,1.7,2.0,2.3,2.7,3.0,3.3,3.7,4.0};

  public void initialize(ModulCheck a) {
    auch5=a.value();
  }

  public boolean isValid(Integer t, ConstraintValidatorContext cvc) {
    System.out.println("in : "+cvc.getDefaultConstraintMessageTemplate());
    String cmt = cvc.getDefaultConstraintMessageTemplate();
    System.out.println("cmt "+cmt);
    cvc.disableDefaultConstraintViolation();
    cmt = cvc.getDefaultConstraintMessageTemplate();
    System.out.println("cmt "+cmt);
   ConstraintViolationBuilder cbui=cvc.buildConstraintViolationWithTemplate("Hai");
   //cbui.addNode("Hoho");
   cbui.addConstraintViolation();
    boolean ergebnis=false;
    for(double d:ok)
      if(d==t)
        return true;
    return ergebnis || (auch5 && t==5.0);
  }

}
