Coverage Report - javax.faces.internal.ValidatorResource
 
Classes in this File Line Coverage Branch Coverage Complexity
ValidatorResource
72%
18/25
62%
5/8
1.625
ValidatorResource$ValidatorPair
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.validator.Validator;
 22  
 
 23  
 import org.seasar.framework.util.ArrayUtil;
 24  
 
 25  
 /**
 26  
  * @author shot
 27  
  * @author higa
 28  
  */
 29  
 public class ValidatorResource {
 30  
 
 31  1
     private static Map validatorPairs = new HashMap();
 32  
 
 33  
     private static ValidatorBuilder builder;
 34  
 
 35  0
     protected ValidatorResource() {
 36  0
     }
 37  
 
 38  
     public static synchronized Validator getValidator(final String expression) {
 39  45
         if (builder == null) {
 40  0
             return null;
 41  
         }
 42  45
         ValidatorPair[] pairs = (ValidatorPair[]) validatorPairs
 43  
                 .get(expression);
 44  45
         return builder.build(expression, pairs);
 45  
     }
 46  
 
 47  
     public static synchronized void addValidator(final String expression,
 48  
             final String validatorName) {
 49  4
         addValidator(expression, validatorName, new HashMap());
 50  4
     }
 51  
 
 52  
     public static synchronized void addValidator(final String expression,
 53  
             final String validatorName, final Map properties) {
 54  23
         ValidatorPair pair = new ValidatorPair(validatorName, properties);
 55  23
         ValidatorPair[] pairs = (ValidatorPair[]) validatorPairs
 56  
                 .get(expression);
 57  23
         if (pairs == null) {
 58  21
             pairs = new ValidatorPair[0];
 59  
         }
 60  23
         validatorPairs.put(expression, ArrayUtil.add(pairs, pair));
 61  23
     }
 62  
 
 63  
     public static synchronized void removeValidator(String expression) {
 64  0
         validatorPairs.remove(expression);
 65  0
         if (builder != null) {
 66  0
             builder.clearValidator(expression);
 67  
         }
 68  0
     }
 69  
 
 70  
     public static void removeAll() {
 71  1524
         validatorPairs.clear();
 72  1524
         if (builder != null) {
 73  1514
             builder.clearAll();
 74  
         }
 75  1524
     }
 76  
 
 77  
     public static void setValidatorBuilder(ValidatorBuilder vb) {
 78  1792
         builder = vb;
 79  1792
     }
 80  
 
 81  
     public static class ValidatorPair {
 82  
 
 83  
         public String validatorName;
 84  
 
 85  
         public Map properties;
 86  
 
 87  23
         public ValidatorPair(final String validatorName, final Map properties) {
 88  23
             this.validatorName = validatorName;
 89  23
             this.properties = properties;
 90  23
         }
 91  
     }
 92  
 
 93  
 }