Coverage Report - org.seasar.cubby.validator.AbstractValidationRules
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractValidationRules
90%
9/10
83%
5/6
0
 
 1  
 /*
 2  
  * Copyright 2004-2009 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.cubby.validator;
 17  
 
 18  
 import java.util.Collection;
 19  
 import java.util.Map;
 20  
 
 21  
 import org.seasar.cubby.action.ActionErrors;
 22  
 
 23  11
 public abstract class AbstractValidationRules implements ValidationRules {
 24  
 
 25  
         /**
 26  
          * すべてのフェーズに対する入力検証を実行します。
 27  
          * 
 28  
          * @param validationRules
 29  
          *            入力検証ルールの集合
 30  
          * @param params
 31  
          *            リクエストパラメータ
 32  
          * @param form
 33  
          *            フォームオブジェクト
 34  
          * @param errors
 35  
          *            アクションのエラー
 36  
          */
 37  
         public void validate(final Map<String, Object[]> params, final Object form,
 38  
                         final ActionErrors errors) {
 39  1
                 for (final ValidationPhase validationPhase : this.getValidationPhases()) {
 40  2
                         validate(validationPhase, params, form, errors);
 41  
                 }
 42  0
         }
 43  
 
 44  
         /**
 45  
          * 指定されたフェーズに対する入力検証を実行します。
 46  
          * 
 47  
          * @param validationRules
 48  
          *            入力検証ルールの集合
 49  
          * @param validationPhase
 50  
          *            入力検証のフェーズ
 51  
          * @param errors
 52  
          *            アクションのエラー
 53  
          * @param params
 54  
          *            リクエストパラメータ
 55  
          * @param form
 56  
          *            フォームオブジェクト
 57  
          */
 58  
         protected void validate(final ValidationPhase validationPhase,
 59  
                         final Map<String, Object[]> params, final Object form,
 60  
                         final ActionErrors errors) {
 61  2
                 final Collection<ValidationRule> phaseValidationRules = this
 62  
                                 .getPhaseValidationRules(validationPhase);
 63  2
                 for (final ValidationRule validationRule : phaseValidationRules) {
 64  1
                         validationRule.apply(params, form, errors);
 65  
                 }
 66  2
                 if (!errors.isEmpty()) {
 67  1
                         throw new ValidationException();
 68  
                 }
 69  1
         }
 70  
 
 71  
 }