View Javadoc
1   package ejava.jpa.example.validation;
2   
3   import javax.validation.ConstraintValidator;
4   import javax.validation.ConstraintValidatorContext;
5   
6   /**
7    * This type check will determine if city and state or zip where expressed for
8    * an Address.
9    */
10  public class CityStateOrZipValidator implements ConstraintValidator<CityStateOrZip, Address1>{
11  
12  	@Override
13  	public void initialize(CityStateOrZip constraintAnnotation) {
14  	}
15  
16  	@Override
17  	public boolean isValid(Address1 address, ConstraintValidatorContext context) {
18  		if (address==null) { return true; }
19  		return (address.getCity()!=null && address.getState()!=null) ||
20  				address.getZip()!=null;
21  	}
22  
23  }