1 4 package nl.justobjects.pushlet.core; 5 6 import nl.justobjects.pushlet.util.Log; 7 import nl.justobjects.pushlet.util.Sys; 8 9 import java.util.Properties ; 10 11 17 public class Config implements ConfigDefs { 18 private static final String PROPERTIES_RESOURCE = "pushlet.properties"; 19 private static Properties properties; 20 21 24 public static void load() { 25 Log.info("Config: loading"); 27 try { 28 properties = Sys.loadPropertiesResource(PROPERTIES_RESOURCE); 29 } catch (Throwable t) { 30 Log.warn("Config: cannot find properties file: " + PROPERTIES_RESOURCE, t); 31 return; 32 } 33 Log.info("Config: loaded values=" + properties); 34 35 } 36 37 public static String getProperty(String aName) { 38 String value = properties.getProperty(aName); 39 if (value == null) { 40 throw new IllegalArgumentException ("Unknown property: " + aName); 41 } 42 return value; 43 } 44 45 public static boolean getBoolProperty(String aName) { 46 String value = getProperty(aName); 47 try { 48 return value.equals("true"); 49 } catch (Throwable t) { 50 throw new IllegalArgumentException ("Illegal property value: " + aName + " val=" + value); 51 } 52 } 53 54 public static int getIntProperty(String aName) { 55 String value = getProperty(aName); 56 try { 57 return Integer.parseInt(value); 58 } catch (Throwable t) { 59 throw new IllegalArgumentException ("Illegal property value: " + aName + " val=" + value); 60 } 61 } 62 63 public static long getLongProperty(String aName) { 64 String value = getProperty(aName); 65 try { 66 return Long.parseLong(value); 67 } catch (Throwable t) { 68 throw new IllegalArgumentException ("Illegal property value: " + aName + " val=" + value); 69 } 70 } 71 72 public static boolean hasProperty(String aName) { 73 return properties.containsKey(aName); 74 } 75 76 77 } 78 79 87 | Popular Tags |