Coverage Report - javax.faces.internal.ConverterResource
 
Classes in this File Line Coverage Branch Coverage Complexity
ConverterResource
76%
19/25
75%
6/8
1.625
ConverterResource$ConverterPair
100%
4/4
N/A
1.625
 
 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  
 
 23  
 import org.seasar.framework.util.ArrayUtil;
 24  
 
 25  
 /**
 26  
  * @author shot
 27  
  */
 28  
 public class ConverterResource {
 29  
 
 30  1
     private static Map converterPairs = new HashMap();
 31  
 
 32  
     private static ConverterBuilder builder;
 33  
 
 34  0
     protected ConverterResource() {
 35  0
     }
 36  
 
 37  
     public static synchronized Converter getConverter(final String expression) {
 38  77
         if (builder == null) {
 39  1
             return null;
 40  
         }
 41  76
         ConverterPair[] pairs = (ConverterPair[]) converterPairs
 42  
                 .get(expression);
 43  76
         return builder.build(expression, pairs);
 44  
     }
 45  
 
 46  
     public static synchronized void addConverter(final String expression,
 47  
             final String converterName) {
 48  34
         addConverter(expression, converterName, new HashMap());
 49  34
     }
 50  
 
 51  
     public static synchronized void addConverter(final String expression,
 52  
             final String converterName, final Map properties) {
 53  36
         ConverterPair pair = new ConverterPair(converterName, properties);
 54  36
         ConverterPair[] pairs = (ConverterPair[]) converterPairs
 55  
                 .get(expression);
 56  36
         if (pairs == null) {
 57  33
             pairs = new ConverterPair[0];
 58  
         }
 59  36
         converterPairs.put(expression, ArrayUtil.add(pairs, pair));
 60  36
     }
 61  
 
 62  
     public static synchronized void removeConverter(String expression) {
 63  0
         converterPairs.remove(expression);
 64  0
         if (builder != null) {
 65  0
             builder.clearConverter(expression);
 66  
         }
 67  0
     }
 68  
 
 69  
     public static void removeAll() {
 70  1522
         converterPairs.clear();
 71  1522
         if (builder != null) {
 72  1516
             builder.clearAll();
 73  
         }
 74  1522
     }
 75  
 
 76  
     public static void setConverterBuilder(final ConverterBuilder cb) {
 77  1398
         builder = cb;
 78  1398
     }
 79  
 
 80  
     public static class ConverterPair {
 81  
 
 82  
         public String converterName;
 83  
 
 84  
         public Map properties;
 85  
 
 86  36
         public ConverterPair(final String converterName, final Map properties) {
 87  36
             this.converterName = converterName;
 88  36
             this.properties = properties;
 89  36
         }
 90  
     }
 91  
 
 92  
 }