Coverage Report - org.seasar.cubby.validator.validators.MaxSizeValidator
 
Classes in this File Line Coverage Branch Coverage Complexity
MaxSizeValidator
100%
13/13
N/A
2.333
 
 1  
 package org.seasar.cubby.validator.validators;
 2  
 
 3  
 import org.seasar.cubby.util.CubbyUtils;
 4  
 import org.seasar.cubby.validator.BaseValidator;
 5  
 import org.seasar.cubby.validator.ValidationContext;
 6  
 
 7  
 /**
 8  
  * 配???大サイズを検証します??
 9  
  * @author agata
 10  
  *
 11  
  */
 12  
 public class MaxSizeValidator extends BaseValidator {
 13  
 
 14  
         /**
 15  
          * 配???大サイズ
 16  
          */
 17  
         private final int max;
 18  
 
 19  
         /**
 20  
          * コンストラクタ
 21  
          * @param max 配???大サイズ
 22  
          */
 23  
         public MaxSizeValidator(final int max) {
 24  1
                 this(max, "valid.maxSize");
 25  1
         }
 26  
 
 27  
         /**
 28  
          * エラーメ?セージキーを指定するコンストラクタ
 29  
          * @param max 配???大サイズ
 30  
          * @param messageKey エラーメ?セージキー
 31  
          */
 32  1
         public MaxSizeValidator(final int max, final String messageKey) {
 33  1
                 this.max = max;
 34  1
                 this.setMessageKey(messageKey);
 35  1
         }
 36  
 
 37  
         public String validate(final ValidationContext ctx) {
 38  4
                 final Object value = ctx.getValue();
 39  4
                 if (value == null) {
 40  1
                         return null; 
 41  
                 } 
 42  3
                 int size = CubbyUtils.getObjectSize(value);
 43  3
                 if (size <= max) {
 44  2
                         return null;
 45  
                 } else {
 46  1
                         return getMessage(getPropertyMessage(ctx.getName()), max);
 47  
                 }
 48  
         }
 49  
 }