Coverage Report - org.seasar.cubby.validator.validators.RequiredValidator
 
Classes in this File Line Coverage Branch Coverage Complexity
RequiredValidator
100%
12/12
N/A
2.667
 
 1  
 package org.seasar.cubby.validator.validators;
 2  
 
 3  
 import org.seasar.cubby.validator.BaseValidator;
 4  
 import org.seasar.cubby.validator.ValidationContext;
 5  
 import org.seasar.framework.util.StringUtil;
 6  
 
 7  
 /**
 8  
  * ?須検証します??<p>
 9  
  * ?字??長さが0の場合?検証エラーとなります??
 10  
  * @author agata
 11  
  *
 12  
  */
 13  
 public class RequiredValidator extends BaseValidator {
 14  
 
 15  
         /**
 16  
          * コンストラクタ
 17  
          */
 18  
         public RequiredValidator() {
 19  16
                 this("valid.required");
 20  16
         }
 21  
 
 22  
         /**
 23  
          * エラーメ?セージキーを指定するコンストラクタ
 24  
          * @param messageKey エラーメ?セージキー
 25  
          */
 26  16
         public RequiredValidator(final String messageKey) {
 27  16
                 this.setMessageKey(messageKey);
 28  16
         }
 29  
 
 30  
         public String validate(final ValidationContext ctx) {
 31  8
                 final Object value = ctx.getValue();
 32  8
                 if (value instanceof String) {
 33  4
                         String str = (String)value;
 34  4
                         if (!StringUtil.isEmpty(str)) {
 35  4
                                 return null;
 36  
                         }
 37  
                 } else if (value != null) {
 38  1
                         return null;
 39  
                 }
 40  3
                 return getMessage(getPropertyMessage(ctx
 41  
                                 .getName()));
 42  
         }
 43  
 
 44  
 }