KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > validator > rules > MaxLen


1 package org.sapia.validator.rules;
2
3 import org.sapia.validator.BeanRule;
4
5 /**
6  * Validates that the length of a string is lower or equal
7  * to a given length
8  *
9  * @author Yanick Duchesne
10  * <dl>
11  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
12  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
13  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
14  * </dl>
15  */

16 public class MaxLen extends BeanRule{
17   
18   private int _len;
19
20   /**
21    * Constructor for MaxLen.
22    */

23   public MaxLen() {
24     throwExceptionOnNull(true);
25   }
26   
27   /**
28    * The maximum expected length of validated strings.
29    *
30    * @param len a maximum length.
31    */

32   public void setLen(int len){
33     _len = len;
34   }
35   
36   /**
37    * @see org.sapia.validator.BeanRule#doValidate(Object)
38    */

39   protected boolean doValidate(Object JavaDoc toValidate) {
40     return ((String JavaDoc)toValidate).length() <= _len;
41   }
42
43
44 }
45
Popular Tags