1 package org.hibernate.validator; 3 4 import org.hibernate.mapping.Column; 5 import org.hibernate.mapping.Property; 6 7 12 public class LengthValidator implements Validator<Length>, PropertyConstraint { 13 private int max; 14 private int min; 15 16 public void initialize(Length parameters) { 17 max = parameters.max(); 18 min = parameters.min(); 19 } 20 21 public boolean isValid(Object value) { 22 if (value==null) return true; 23 if ( !(value instanceof String ) ) return false; 24 String string = (String ) value; 25 int length = string.length(); 26 return length>=min && length<=max; 27 } 28 29 public void apply(Property property) { 30 Column col = (Column) property.getColumnIterator().next(); 31 col.setLength(max); 32 } 33 34 } 35 | Popular Tags |