1 package com.teamkonzept.lib; 2 3 import java.util.*; 4 import java.io.*; 5 import java.sql.*; 6 import com.teamkonzept.db.*; 7 import com.teamkonzept.lib.db.queries.TKDBPropGroupGetPropsByName; 8 9 15 public class DBResourceBundle extends ResourceBundle implements ConfigurationErrorCodes 16 { 17 18 Hashtable props=new Hashtable(); 19 20 21 String groupName; 22 23 27 public DBResourceBundle(String groupName) throws TKException 28 { 29 this.groupName = groupName; 30 loadProperties(); 31 } 32 33 36 public void doReload() throws TKException 37 { 38 loadProperties(); 39 } 40 41 44 public Enumeration getKeys() 45 { 46 return props.keys(); 47 } 48 49 protected void loadProperties() throws TKException 50 { 51 try { 52 props.clear(); 53 TKQuery q = TKDBManager.newQuery(TKDBPropGroupGetPropsByName.class); 54 q.setQueryParams("PROPGROUP_NAME", new String (groupName)); 55 q.execute(); 56 ResultSet rs = q.fetchResultSet(); 57 if (rs != null && rs.next()) 59 { 60 do 61 { 62 String pName = rs.getString("NAME"); 63 String pValue = rs.getString("VALUE"); 64 props.put(pName, pValue); 65 } while (rs.next()); 66 } 67 else 68 { 69 throw new TKConfigurationException("Can't find Propertygroup " + groupName, NO_PROPERTY_FILE, HIGH_SEVERITY, true, null); 70 } 71 } catch (Throwable e) { 72 throw DefaultExceptionHandler.getException(e); 73 } 74 75 } 76 77 81 protected Object handleGetObject(String key) throws MissingResourceException 82 { 83 String value = (String ) props.get(key); 84 if (value == null) { 85 throw new MissingResourceException("The following property was not found:","DBResource: "+groupName, key); 86 } 87 return value; 88 } 89 90 91 } 92 | Popular Tags |