1 package ejava.jpa.example.validation;
2
3 import javax.validation.ConstraintValidator;
4 import javax.validation.ConstraintValidatorContext;
5
6
7
8
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 }