Coverage Report - org.seasar.cubby.validator.AbstractValidationRules
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractValidationRules
100%
10/10
100%
6/6
3
 
 1  
 /*
 2  
  * Copyright 2004-2010 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  
 
 17  
 package org.seasar.cubby.validator;
 18  
 
 19  
 import java.util.Collection;
 20  
 import java.util.Map;
 21  
 
 22  
 import org.seasar.cubby.action.ActionErrors;
 23  
 
 24  
 /**
 25  
  * 入力検証ルールの抽象Kクラスです。
 26  
  * 
 27  
  * @author baba
 28  
  */
 29  13
 public abstract class AbstractValidationRules implements ValidationRules {
 30  
 
 31  
         /**
 32  
          * すべてのフェーズに対する入力検証を実行します。
 33  
          * 
 34  
          * @param params
 35  
          *            要求パラメータ
 36  
          * @param form
 37  
          *            フォームオブジェクト
 38  
          * @param errors
 39  
          *            アクションのエラー
 40  
          */
 41  
         public void validate(final Map<String, Object[]> params, final Object form,
 42  
                         final ActionErrors errors) {
 43  3
                 for (final ValidationPhase validationPhase : this.getValidationPhases()) {
 44  6
                         validate(validationPhase, params, form, errors);
 45  
                 }
 46  2
         }
 47  
 
 48  
         /**
 49  
          * 指定されたフェーズに対する入力検証を実行します。
 50  
          * 
 51  
          * @param validationRules
 52  
          *            入力検証ルールの集合
 53  
          * @param validationPhase
 54  
          *            入力検証のフェーズ
 55  
          * @param errors
 56  
          *            アクションのエラー
 57  
          * @param params
 58  
          *            要求パラメータ
 59  
          * @param form
 60  
          *            フォームオブジェクト
 61  
          */
 62  
         protected void validate(final ValidationPhase validationPhase,
 63  
                         final Map<String, Object[]> params, final Object form,
 64  
                         final ActionErrors errors) {
 65  6
                 final Collection<ValidationRule> phaseValidationRules = this
 66  
                                 .getPhaseValidationRules(validationPhase);
 67  6
                 for (final ValidationRule validationRule : phaseValidationRules) {
 68  1
                         validationRule.apply(params, form, errors);
 69  
                 }
 70  6
                 if (!errors.isEmpty()) {
 71  1
                         throw new ValidationException();
 72  
                 }
 73  5
         }
 74  
 
 75  
 }