Coverage Report - javax.faces.internal.NormalConverterBuilderImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
NormalConverterBuilderImpl
88%
23/26
80%
8/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.HashMap;
 19  
 import java.util.Map;
 20  
 
 21  
 import javax.faces.convert.Converter;
 22  
 import javax.faces.internal.ConverterResource.ConverterPair;
 23  
 
 24  
 import org.seasar.framework.beans.util.BeanUtil;
 25  
 import org.seasar.framework.container.ComponentDef;
 26  
 import org.seasar.framework.container.S2Container;
 27  
 import org.seasar.framework.container.factory.SingletonS2ContainerFactory;
 28  
 
 29  
 /**
 30  
  * @author shot
 31  
  */
 32  
 public class NormalConverterBuilderImpl implements ConverterBuilder {
 33  
 
 34  
     private S2Container container;
 35  
 
 36  1393
     private Map converters = new HashMap();
 37  
 
 38  1
     public NormalConverterBuilderImpl() {
 39  1
         container = SingletonS2ContainerFactory.getContainer();
 40  1
     }
 41  
 
 42  1392
     public NormalConverterBuilderImpl(S2Container container) {
 43  1392
         this.container = container;
 44  1392
     }
 45  
 
 46  
     public Converter build(String expression, ConverterPair[] pairs) {
 47  71
         if (pairs == null || pairs.length == 0) {
 48  35
             return null;
 49  
         }
 50  36
         if (converters.containsKey(expression)) {
 51  4
             return (Converter) converters.get(expression);
 52  
         }
 53  32
         Converter converter = getSingleConverter(pairs[0]);
 54  32
         converters.put(expression, converter);
 55  32
         return converter;
 56  
     }
 57  
 
 58  
     //see https://www.seasar.org/issues/browse/TEEDA-125
 59  
     protected Converter getSingleConverter(ConverterPair pair) {
 60  32
         final ComponentDef cd = container.getComponentDef(pair.converterName);
 61  33
         if (!Converter.class.isAssignableFrom(cd.getComponentClass())) {
 62  0
             return null;
 63  
         }
 64  32
         final Converter converter = (Converter) cd.getComponent();
 65  32
         BeanUtil.copyProperties(pair.properties, converter);
 66  32
         return converter;
 67  
     }
 68  
 
 69  
     public void setContainer(S2Container container) {
 70  1
         this.container = container;
 71  1
     }
 72  
 
 73  
     public void clearAll() {
 74  1516
         converters.clear();
 75  1516
     }
 76  
 
 77  
     public void clearConverter(String expression) {
 78  0
         converters.remove(expression);
 79  0
     }
 80  
 
 81  
 }