Coverage Report - javax.faces.internal.HotDeployConverterBuilderImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
HotDeployConverterBuilderImpl
64%
14/22
60%
6/10
1.714
 
 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.convert.Converter;
 21  
 import javax.faces.internal.ConverterResource.ConverterPair;
 22  
 
 23  
 import org.seasar.framework.beans.util.BeanUtil;
 24  
 import org.seasar.framework.container.ComponentDef;
 25  
 import org.seasar.framework.container.S2Container;
 26  
 import org.seasar.framework.container.factory.SingletonS2ContainerFactory;
 27  
 import org.seasar.framework.container.hotdeploy.HotdeployUtil;
 28  
 
 29  
 /**
 30  
  * @author shot
 31  
  */
 32  
 public class HotDeployConverterBuilderImpl implements ConverterBuilder {
 33  
 
 34  
     private S2Container container;
 35  
 
 36  2
     public HotDeployConverterBuilderImpl() {
 37  2
         container = SingletonS2ContainerFactory.getContainer();
 38  2
     }
 39  
 
 40  0
     public HotDeployConverterBuilderImpl(S2Container container) {
 41  0
         this.container = container;
 42  0
     }
 43  
 
 44  
     public Converter build(String expression, ConverterPair[] pairs) {
 45  5
         if (pairs == null || pairs.length == 0) {
 46  0
             return null;
 47  
         }
 48  
         //TODO need ConverterChain? I guess not.
 49  5
         return getSingleConverter(pairs[0]);
 50  
     }
 51  
 
 52  
     //see https://www.seasar.org/issues/browse/TEEDA-125
 53  
     protected Converter getSingleConverter(ConverterPair pair) {
 54  5
         final ComponentDef cd = container.getComponentDef(pair.converterName);
 55  6
         if (!Converter.class.isAssignableFrom(cd.getComponentClass())) {
 56  0
             return null;
 57  
         }
 58  5
         Map properties = pair.properties;
 59  5
         if (HotdeployUtil.isHotdeploy()) {
 60  0
             properties = EnumUtil.convertNameToEnum(properties);
 61  
         }
 62  5
         final Converter converter = (Converter) cd.getComponent();
 63  5
         BeanUtil.copyProperties(properties, converter);
 64  5
         return converter;
 65  
     }
 66  
 
 67  
     public void setContainer(S2Container container) {
 68  2
         this.container = container;
 69  2
     }
 70  
 
 71  
     public void clearAll() {
 72  
         //no op;
 73  0
     }
 74  
 
 75  
     public void clearConverter(String expression) {
 76  
         //no op;
 77  0
     }
 78  
 
 79  
 }