Coverage Report - javax.faces.internal.HotDeployValidatorBuilderImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
HotDeployValidatorBuilderImpl
71%
17/24
70%
7/10
1.857
 
 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.Map;
 19  
 
 20  
 import javax.faces.internal.ValidatorResource.ValidatorPair;
 21  
 import javax.faces.validator.Validator;
 22  
 
 23  
 import org.seasar.framework.beans.util.BeanUtil;
 24  
 import org.seasar.framework.container.S2Container;
 25  
 import org.seasar.framework.container.factory.SingletonS2ContainerFactory;
 26  
 import org.seasar.framework.container.hotdeploy.HotdeployUtil;
 27  
 
 28  
 /**
 29  
  * @author shot
 30  
  *
 31  
  */
 32  
 public class HotDeployValidatorBuilderImpl implements ValidatorBuilder {
 33  
 
 34  
     private S2Container container;
 35  
 
 36  4
     public HotDeployValidatorBuilderImpl() {
 37  4
         container = SingletonS2ContainerFactory.getContainer();
 38  4
     }
 39  
 
 40  0
     public HotDeployValidatorBuilderImpl(S2Container container) {
 41  0
         this.container = container;
 42  0
     }
 43  
 
 44  
     public Validator build(String expression, ValidatorPair[] pairs) {
 45  9
         if (pairs == null || pairs.length == 0) {
 46  0
             return null;
 47  
         }
 48  9
         if (pairs.length == 1) {
 49  5
             return getSingleValidator(pairs[0]);
 50  
         }
 51  4
         final ValidatorChain chain = new ValidatorChain();
 52  12
         for (int i = 0; i < pairs.length; i++) {
 53  8
             chain.add(getSingleValidator(pairs[i]));
 54  
         }
 55  4
         return chain;
 56  
     }
 57  
 
 58  
     protected Validator getSingleValidator(ValidatorPair pair) {
 59  13
         Map properties = pair.properties;
 60  13
         if (HotdeployUtil.isHotdeploy()) {
 61  0
             properties = EnumUtil.convertNameToEnum(properties);
 62  
         }
 63  13
         final Validator validator = (Validator) container
 64  
                 .getComponent(pair.validatorName);
 65  13
         BeanUtil.copyProperties(properties, validator);
 66  13
         return validator;
 67  
     }
 68  
 
 69  
     public void setContainer(S2Container container) {
 70  4
         this.container = container;
 71  4
     }
 72  
 
 73  
     public void clearAll() {
 74  
         //no op;
 75  0
     }
 76  
 
 77  
     public void clearValidator(String expression) {
 78  
         //no op;
 79  0
     }
 80  
 
 81  
 }