| 1 23 24 package com.rift.coad.lib.configuration.xml; 26 27 import java.util.Map ; 29 import java.util.HashMap ; 30 import java.util.Set ; 31 32 import com.rift.coad.lib.configuration.Configuration; 34 import com.rift.coad.lib.configuration.ConfigurationException; 35 36 41 public class XMLConfiguration implements Configuration { 42 43 private String className = null; 45 private Map entries = null; 46 47 52 public XMLConfiguration(String className) { 53 this.className = className; 54 this.entries = new HashMap (); 55 } 56 57 58 63 public String getClassName() { 64 return className; 65 } 66 67 74 public boolean containsKey(String key) throws ConfigurationException { 75 return entries.containsKey(key); 76 } 77 78 79 85 public Set getKeys() throws ConfigurationException { 86 return entries.keySet(); 87 } 88 89 90 97 public boolean isString(String key) throws ConfigurationException { 98 XMLConfigurationEntry entry = (XMLConfigurationEntry)entries.get(key); 99 if (entry == null) { 100 throw new ConfigurationException("The entry [" + key 101 + "] does not exist"); 102 } 103 if (entry.getType().getType() == XMLConfigurationType.STRING_VALUE) { 104 return true; 105 } 106 return false; 107 } 108 109 110 117 public String getString(String key) throws ConfigurationException { 118 XMLConfigurationEntry entry = (XMLConfigurationEntry)entries.get(key); 119 if (entry == null) { 120 throw new ConfigurationException("The entry [" + key 121 + "] does not exist"); 122 } 123 return entry.getStringValue(); 124 } 125 126 127 135 public String getString(String key,String defValue) 136 throws ConfigurationException { 137 XMLConfigurationEntry entry = (XMLConfigurationEntry)entries.get(key); 138 if (entry == null) { 139 return defValue; 140 } 141 return entry.getStringValue(); 142 } 143 144 145 152 public void setString(String key, String value) 153 throws ConfigurationException { 154 throw new ConfigurationException("Not Implemented"); 155 } 156 157 158 165 public boolean isLong(String key) throws ConfigurationException { 166 XMLConfigurationEntry entry = (XMLConfigurationEntry)entries.get(key); 167 if (entry == null) { 168 throw new ConfigurationException("The entry [" + key 169 + "] does not exist"); 170 } 171 if (entry.getType().getType() == XMLConfigurationType.LONG_VALUE) { 172 return true; 173 } 174 return false; 175 } 176 177 178 185 public long getLong(String key) throws ConfigurationException { 186 XMLConfigurationEntry entry = (XMLConfigurationEntry)entries.get(key); 187 if (entry == null) { 188 throw new ConfigurationException("The entry [" + key 189 + "] does not exist"); 190 } 191 return entry.getLongValue(); 192 } 193 194 195 203 public long getLong(String key,long defValue) throws ConfigurationException { 204 XMLConfigurationEntry entry = (XMLConfigurationEntry)entries.get(key); 205 if (entry == null) { 206 return defValue; 207 } 208 return entry.getLongValue(); 209 } 210 211 212 219 public void setLong(String key,long value) throws ConfigurationException { 220 throw new ConfigurationException("Not Implemented"); 221 } 222 223 224 231 public boolean isBoolean(String key) throws ConfigurationException { 232 XMLConfigurationEntry entry = (XMLConfigurationEntry)entries.get(key); 233 if (entry == null) { 234 throw new ConfigurationException("The entry [" + key 235 + "] does not exist"); 236 } 237 if (entry.getType().getType() == XMLConfigurationType.BOOLEAN_VALUE) { 238 return true; 239 } 240 return false; 241 } 242 243 244 251 public boolean getBoolean(String key) throws ConfigurationException { 252 XMLConfigurationEntry entry = (XMLConfigurationEntry)entries.get(key); 253 if (entry == null) { 254 throw new ConfigurationException("The entry [" + key 255 + "] does not exist"); 256 } 257 return entry.getBooleanValue(); 258 } 259 260 261 269 public boolean getBoolean(String key,boolean defValue) throws 270 ConfigurationException { 271 XMLConfigurationEntry entry = (XMLConfigurationEntry)entries.get(key); 272 if (entry == null) { 273 return defValue; 274 } 275 return entry.getBooleanValue(); 276 } 277 278 279 286 public void setBoolean(String key,boolean value) throws 287 ConfigurationException { 288 throw new ConfigurationException("Not implemented"); 289 } 290 291 292 297 public void saveConfiguration() throws ConfigurationException { 298 throw new ConfigurationException("Not Implemented"); 299 } 300 301 302 307 public void addConfigurationEntry(XMLConfigurationEntry entry){ 308 entries.put(entry.getKey(),entry); 309 } 310 } 311 | Popular Tags |