Coverage Report - org.kuali.rice.core.api.config.property.ConfigContext
 
Classes in this File Line Coverage Branch Coverage Complexity
ConfigContext
0%
0/15
0%
0/2
1
 
 1  
 /*
 2  
  * Copyright 2006-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
 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, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package org.kuali.rice.core.api.config.property;
 18  
 
 19  
 import java.util.Collections;
 20  
 import java.util.Map;
 21  
 import java.util.Set;
 22  
 import java.util.concurrent.ConcurrentHashMap;
 23  
 
 24  
 /**
 25  
  * Singleton that holds references to global engine objects.
 26  
  *
 27  
  *
 28  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 29  
  */
 30  
 public class ConfigContext {
 31  0
     private static final ConcurrentHashMap<ClassLoader, Config> CONFIGS = new ConcurrentHashMap<ClassLoader, Config>();
 32  
 
 33  0
     private ConfigContext() {
 34  
         // nothing to do here
 35  0
     }
 36  
 
 37  
     /**
 38  
      * Perform a one-time initialization of the Config system.  This should only be performed by the applicable LifeCycle
 39  
      * implementation.
 40  
      * @param rootCfg the root config
 41  
      */
 42  
     public static void init(Config rootCfg) {
 43  0
             init(Thread.currentThread().getContextClassLoader(), rootCfg);
 44  0
     }
 45  
 
 46  
     /**
 47  
      * Initializes the ConfigContext with the given Config and binds it to the given ClassLoader.
 48  
      */
 49  
     public static void init(ClassLoader classLoader, Config config) {
 50  0
             CONFIGS.put(classLoader, config);
 51  0
     }
 52  
 
 53  
     public static boolean isInitialized() {
 54  0
             return !CONFIGS.isEmpty();
 55  
     }
 56  
     
 57  
     /**
 58  
      * Destroy method (mostly to aid testing, as core needs to be torn down appropriately).
 59  
      */
 60  
     public static void destroy() {
 61  0
         CONFIGS.clear();
 62  0
     }
 63  
 
 64  
     /**
 65  
      * Utility method that all code should call to obtain its appropriate Config object.
 66  
      * The Config object which is associated with the caller's context classloader will be
 67  
      * returned, being created first if it does not yet exist.
 68  
      * @return the Config object which is associated with the caller's context classloader
 69  
      */
 70  
     public static Config getCurrentContextConfig() {
 71  0
             return getConfig(Thread.currentThread().getContextClassLoader());
 72  
     }
 73  
 
 74  
     /**
 75  
      * Returns the Config which is bound to the given class loader.  If no configuration is bound to the given class
 76  
      * loader this method will return null;
 77  
      *
 78  
      * @param cl the classloader whose Config to return
 79  
      * @return the Config of a particular class loader, or null if no config is bound to the given class loader
 80  
      */
 81  
     public static Config getConfig(ClassLoader cl) {
 82  0
         return CONFIGS.get(cl);
 83  
     }
 84  
 
 85  
     /**
 86  
      * @return an immutable view of the Configs entry set
 87  
      */
 88  
     public static Set<Map.Entry<ClassLoader, Config>> getConfigs() {
 89  0
         return Collections.unmodifiableSet(CONFIGS.entrySet());
 90  
     }
 91  
 
 92  
     /**
 93  
      * Overrides any existing Config for the classloader
 94  
      * @param cl the classloader whose Config should be overridden
 95  
      * @param config the config
 96  
      */
 97  
     public static void overrideConfig(ClassLoader cl, Config config) {
 98  0
         CONFIGS.put(cl, config);
 99  0
     }
 100  
 }