Coverage Report - org.kuali.rice.core.framework.config.property.SimpleConfig
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleConfig
0%
0/49
0%
0/4
1.136
 
 1  
 /**
 2  
  * Copyright 2005-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  
 package org.kuali.rice.core.framework.config.property;
 17  
 
 18  
 import org.apache.commons.lang.builder.ToStringBuilder;
 19  
 import org.apache.log4j.Logger;
 20  
 import org.kuali.rice.core.api.config.property.Config;
 21  
 import org.kuali.rice.core.api.util.RiceUtilities;
 22  
 
 23  
 import java.io.IOException;
 24  
 import java.util.ArrayList;
 25  
 import java.util.Collections;
 26  
 import java.util.HashMap;
 27  
 import java.util.LinkedHashMap;
 28  
 import java.util.List;
 29  
 import java.util.Map;
 30  
 import java.util.Properties;
 31  
 
 32  
 /**
 33  
  * Base config implementation that does not support file parsing.
 34  
  *
 35  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 36  
  */
 37  
 public class SimpleConfig extends AbstractBaseConfig {
 38  
 
 39  0
     private static final Logger LOG = Logger.getLogger(SimpleConfig.class);
 40  
 
 41  0
     protected Map<String, Object> configs = new LinkedHashMap<String, Object>();
 42  
 
 43  
     protected final List<String> fileLocs;
 44  
 
 45  0
     protected Properties propertiesUsed = new Properties();
 46  
 
 47  0
     private Map<String, Object> objects = new LinkedHashMap<String, Object>();
 48  
 
 49  0
     private Properties baseProperties = new Properties();
 50  
 
 51  0
     private Map<String, Object> baseObjects = new HashMap<String, Object>();
 52  
 
 53  0
     public SimpleConfig() {
 54  0
         this.fileLocs = new ArrayList<String>();
 55  0
     }
 56  
 
 57  
     public SimpleConfig(String fileLoc) {
 58  0
        this(Collections.singletonList(fileLoc));
 59  0
     }
 60  
 
 61  0
     public SimpleConfig(List<String> fileLocs) {
 62  0
         this.fileLocs = fileLocs;
 63  0
     }
 64  
 
 65  
     public SimpleConfig(Properties properties) {
 66  0
         this(new ArrayList<String>(), properties);
 67  0
     }
 68  
 
 69  
     public SimpleConfig(String fileLoc, Properties baseProperties) {
 70  0
         this(Collections.singletonList(fileLoc), baseProperties);
 71  0
     }
 72  
 
 73  
     public SimpleConfig(List<String> fileLocs, Properties baseProperties) {
 74  0
         this(fileLocs);
 75  0
         this.baseProperties = baseProperties;
 76  0
     }
 77  
 
 78  
 
 79  
     public void parseConfig() throws IOException {
 80  0
         throw new UnsupportedOperationException("Parsing is no longer supported by BaseConfig, please see JAXBConfigImpl instead.");
 81  
     }
 82  
 
 83  
     /**
 84  
      * Configures built-in properties.
 85  
      */
 86  
     protected void configureBuiltIns(Properties properties) {
 87  0
         properties.put("host.ip", RiceUtilities.getIpNumber());
 88  0
         properties.put("host.name", RiceUtilities.getHostName());
 89  0
     }
 90  
 
 91  
     public Map<String, Object> getBaseObjects() {
 92  0
         return this.baseObjects;
 93  
     }
 94  
 
 95  
     public Properties getBaseProperties() {
 96  0
         return this.baseProperties;
 97  
     }
 98  
 
 99  
     public Properties getProperties() {
 100  0
         return this.propertiesUsed;
 101  
     }
 102  
 
 103  
     public String getProperty(String key) {
 104  0
         return getProperties().getProperty(key);
 105  
     }
 106  
 
 107  
     public Map<String, Object> getObjects() {
 108  0
         return this.objects;
 109  
     }
 110  
 
 111  
     public Object getObject(String key) {
 112  0
         return getObjects().get(key);
 113  
     }
 114  
 
 115  
     public void putProperties(Properties properties) {
 116  0
         if (properties != null) {
 117  0
             getProperties().putAll(properties);
 118  
         }
 119  0
     }
 120  
 
 121  
     public void putProperty(String key, String value) {
 122  0
         this.getProperties().put(key, value);
 123  0
     }
 124  
 
 125  
     public void putObject(String key, Object value) {
 126  0
         this.getObjects().put(key, value);
 127  0
     }
 128  
 
 129  
     public void putObjects(Map<String, Object> objects) {
 130  0
         if(objects != null){
 131  0
             this.getObjects().putAll(objects);
 132  
         }
 133  0
     }
 134  
 
 135  
     public void removeObject(String key){
 136  0
         this.getObjects().remove(key);
 137  0
     }
 138  
 
 139  
     public void removeProperty(String key){
 140  0
         this.getProperties().remove(key);
 141  0
     }
 142  
 
 143  
     public void putConfig(Config config) {
 144  0
         putProperties(config.getProperties());
 145  0
         putObjects(config.getObjects());
 146  0
     }
 147  
 
 148  
     public String toString() {
 149  0
         return new ToStringBuilder(this).append("fileLocs", fileLocs).toString();
 150  
     }
 151  
 }