Coverage Report - javax.faces.internal.NormalValidatorBuilderImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
NormalValidatorBuilderImpl
76%
22/29
60%
6/10
2
 
 1  
 /*
 2  
  * Copyright 2004-2011 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 javax.faces.internal;
 17  
 
 18  
 import java.util.HashMap;
 19  
 import java.util.Map;
 20  
 
 21  
 import javax.faces.internal.ValidatorResource.ValidatorPair;
 22  
 import javax.faces.validator.Validator;
 23  
 
 24  
 import org.seasar.framework.beans.util.BeanUtil;
 25  
 import org.seasar.framework.container.S2Container;
 26  
 import org.seasar.framework.container.factory.SingletonS2ContainerFactory;
 27  
 
 28  
 /**
 29  
  * @author shot
 30  
  *
 31  
  */
 32  
 public class NormalValidatorBuilderImpl implements ValidatorBuilder {
 33  
 
 34  
     private S2Container container;
 35  
 
 36  1783
     private Map validators = new HashMap();
 37  
 
 38  443
     public NormalValidatorBuilderImpl() {
 39  443
         container = SingletonS2ContainerFactory.getContainer();
 40  443
     }
 41  
 
 42  1340
     public NormalValidatorBuilderImpl(S2Container container) {
 43  1340
         this.container = container;
 44  1340
     }
 45  
 
 46  
     public Validator build(String expression, ValidatorPair[] pairs) {
 47  36
         if (pairs == null || pairs.length == 0) {
 48  16
             return null;
 49  
         }
 50  20
         if (validators.containsKey(expression)) {
 51  3
             return (Validator) validators.get(expression);
 52  
         }
 53  17
         if (pairs.length == 1) {
 54  17
             Validator validator = getSingleValidator(pairs[0]);
 55  17
             validators.put(expression, validator);
 56  17
             return validator;
 57  
         }
 58  0
         final ValidatorChain chain = new ValidatorChain();
 59  0
         for (int i = 0; i < pairs.length; i++) {
 60  0
             chain.add(getSingleValidator(pairs[i]));
 61  
         }
 62  0
         validators.put(expression, chain);
 63  0
         return chain;
 64  
     }
 65  
 
 66  
     protected Validator getSingleValidator(ValidatorPair pair) {
 67  17
         final Validator validator = (Validator) container
 68  
                 .getComponent(pair.validatorName);
 69  17
         BeanUtil.copyProperties(pair.properties, validator);
 70  17
         return validator;
 71  
     }
 72  
 
 73  
     public void setContainer(S2Container container) {
 74  443
         this.container = container;
 75  443
     }
 76  
 
 77  
     public void clearAll() {
 78  1514
         validators.clear();
 79  1514
     }
 80  
 
 81  
     public void clearValidator(String expression) {
 82  0
         validators.remove(expression);
 83  0
     }
 84  
 
 85  
 }