Coverage Report - javax.faces.FactoryFinder
 
Classes in this File Line Coverage Branch Coverage Complexity
FactoryFinder
96%
25/26
100%
8/8
3.333
 
 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;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.HashMap;
 20  
 import java.util.List;
 21  
 import java.util.Map;
 22  
 
 23  
 import javax.faces.internal.FactoryFinderUtil;
 24  
 
 25  
 import org.seasar.framework.util.AssertionUtil;
 26  
 
 27  
 /**
 28  
  * @author shot
 29  
  * @author higa
 30  
  */
 31  0
 public final class FactoryFinder {
 32  
 
 33  
     public static final String APPLICATION_FACTORY = "javax.faces.application.ApplicationFactory";
 34  
 
 35  
     public static final String FACES_CONTEXT_FACTORY = "javax.faces.context.FacesContextFactory";
 36  
 
 37  
     public static final String LIFECYCLE_FACTORY = "javax.faces.lifecycle.LifecycleFactory";
 38  
 
 39  
     public static final String RENDER_KIT_FACTORY = "javax.faces.render.RenderKitFactory";
 40  
 
 41  1
     private static final Map factories = new HashMap();
 42  
 
 43  1
     private static final Map factoryClassNames = new HashMap();
 44  
 
 45  
     public static Object getFactory(String factoryName) throws FacesException {
 46  6009
         AssertionUtil.assertNotNull("factoryName", factoryName);
 47  6008
         if (!factoryClassNames.containsKey(factoryName)) {
 48  1
             throw new IllegalStateException("no factory " + factoryName
 49  
                     + " configured for this application");
 50  
         }
 51  6007
         Object factory = factories.get(factoryName);
 52  6007
         if (factory == null) {
 53  5368
             List classNames = (List) factoryClassNames.get(factoryName);
 54  5368
             factory = FactoryFinderUtil.createFactoryInstance(factoryName,
 55  
                     classNames);
 56  5368
             factories.put(factoryName, factory);
 57  5368
             return factory;
 58  
         } else {
 59  639
             return factory;
 60  
         }
 61  
     }
 62  
 
 63  
     public static void setFactory(String factoryName, String implName) {
 64  5385
         AssertionUtil.assertNotNull("factoryName", factoryName);
 65  5384
         FactoryFinderUtil.checkValidFactoryNames(factoryName);
 66  5383
         List classNameList = (List) factoryClassNames.get(factoryName);
 67  5383
         if (classNameList == null) {
 68  5368
             classNameList = new ArrayList();
 69  5368
             factoryClassNames.put(factoryName, classNameList);
 70  
         }
 71  5383
         if (classNameList.contains(implName)) {
 72  14
             return;
 73  
         }
 74  5369
         classNameList.add(implName);
 75  5369
     }
 76  
 
 77  
     public static void releaseFactories() throws FacesException {
 78  1369
         factories.clear();
 79  1369
         factoryClassNames.clear();
 80  1369
     }
 81  
 
 82  
 }