1 package com.ubermq.kernel; 2 3 import java.io.*; 4 import java.util.*; 5 6 14 public class Configurator 15 { 16 private static Properties theProperties = new Properties(); 17 18 private Configurator() 19 { 20 } 21 22 26 public static void setup(InputStream is) throws IOException 27 { 28 Properties props = new Properties(); 29 props.load(is); 30 setup(props); 31 } 32 33 39 public static void setup(Properties props) 40 { 41 theProperties = (Properties)props.clone(); 42 } 43 44 48 public static String getProperty(String property) 49 { 50 return theProperties.getProperty(property); 51 } 52 53 57 public static String getProperty(String property, String defaultValue) 58 { 59 return theProperties.getProperty(property, defaultValue); 60 } 61 62 70 public static String [] getPropertyList(String property, String defaultValue) 71 { 72 String value = getProperty(property, defaultValue); 73 if (value != null) 74 { 75 return convertFromPropertyList(value); 76 } 77 else 78 { 79 return new String [0]; 80 } 81 } 82 83 91 public static String convertToPropertyList(String [] values) 92 { 93 if (values.length <= 0) 94 return ""; 95 96 StringBuffer sb = new StringBuffer (values[0]); 97 for(int i=1;i < values.length;i++) 98 { 99 sb.append(","); 100 sb.append(values[i]); 101 } 102 return sb.toString(); 103 } 104 105 112 public static String [] convertFromPropertyList(String value) 113 { 114 StringTokenizer st = new StringTokenizer(value, ", "); 115 List l = new LinkedList(); 116 while (st.hasMoreTokens()) 117 { 118 l.add(st.nextToken()); 119 } 120 return (String [])l.toArray(new String [l.size()]); 121 } 122 123 126 public static Object get(Object property) 127 { 128 return theProperties.get(property); 129 } 130 131 public static Properties getProperties() 132 { 133 return theProperties; 134 } 135 136 } 137 | Popular Tags |