1 17 package org.alfresco.config; 18 19 import java.util.ArrayList ; 20 import java.util.HashMap ; 21 import java.util.List ; 22 import java.util.Map ; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 27 33 public class ConfigImpl implements Config 34 { 35 private static final Log logger = LogFactory.getLog(ConfigImpl.class); 36 37 private Map <String , Object > configElements; 38 39 42 public ConfigImpl() 43 { 44 this.configElements = new HashMap <String , Object >(); 45 } 46 47 53 public ConfigImpl(ConfigImpl config) 54 { 55 this(); 56 57 this.configElements.putAll(config.getConfigElements()); 58 } 59 60 63 public ConfigElement getConfigElement(String name) 64 { 65 return (ConfigElement) this.configElements.get(name); 66 } 67 68 71 public List <ConfigElement> getConfigElementList(String name) 72 { 73 List <ConfigElement> list = null; 74 75 Object obj = this.configElements.get(name); 76 if (obj != null) 77 { 78 if (obj instanceof ConfigElement) 79 { 80 list = new ArrayList <ConfigElement>(1); 81 list.add((ConfigElement)obj); 82 } 83 else if (obj instanceof List ) 84 { 85 list = (List <ConfigElement>)obj; 86 } 87 } 88 89 return list; 90 } 91 92 95 public boolean hasConfigElement(String name) 96 { 97 return this.configElements.containsKey(name); 98 } 99 100 103 public Map <String , Object > getConfigElements() 104 { 105 return this.configElements; 106 } 107 108 115 public void putConfigElement(ConfigElement configElement) 116 { 117 this.configElements.put(configElement.getName(), configElement); 118 } 119 120 127 public void addConfigElement(ConfigElement configElement) 128 { 129 Object obj = this.configElements.get(configElement.getName()); 130 if (obj == null) 131 { 132 putConfigElement(configElement); 133 } 134 else 135 { 136 if (obj instanceof ConfigElement) 137 { 138 List <ConfigElement> list = new ArrayList <ConfigElement>(2); 139 list.add((ConfigElement)obj); 140 list.add(configElement); 141 } 142 else if (obj instanceof List ) 143 { 144 ((List <ConfigElement>)obj).add(configElement); 145 } 146 } 147 } 148 } 149 | Popular Tags |