1 5 package com.opensymphony.webwork.config; 6 7 import java.io.IOException ; 8 import java.net.URL ; 9 import java.util.Iterator ; 10 import java.util.Properties ; 11 12 13 20 public class PropertiesConfiguration extends Configuration { 21 23 Properties settings; 24 25 27 34 public PropertiesConfiguration(String name) { 35 settings = new Properties (); 36 37 URL settingsUrl = Thread.currentThread().getContextClassLoader().getResource(name + ".properties"); 38 39 if (settingsUrl == null) { 40 throw new IllegalStateException (name + ".properties missing"); 41 } 42 43 try { 45 settings.load(settingsUrl.openStream()); 46 } catch (IOException e) { 47 throw new RuntimeException ("Could not load " + name + ".properties:" + e); 48 } 49 } 50 51 53 58 public void setImpl(String aName, Object aValue) { 59 settings.put(aName, aValue); 60 } 61 62 67 public Object getImpl(String aName) throws IllegalArgumentException { 68 Object setting = settings.get(aName); 69 70 if (setting == null) { 71 throw new IllegalArgumentException ("No such setting:" + aName); 72 } 73 74 return setting; 75 } 76 77 82 public boolean isSetImpl(String aName) { 83 if (settings.get(aName) != null) { 84 return true; 85 } else { 86 return false; 87 } 88 } 89 90 95 public Iterator listImpl() { 96 return settings.keySet().iterator(); 97 } 98 } 99 | Popular Tags |