1 package com.piratepete.dbpirate; 2 3 import java.io.IOException ; 4 import java.io.InputStream ; 5 import java.util.ArrayList ; 6 import java.util.Iterator ; 7 import java.util.List ; 8 9 import org.jdom.Document; 10 import org.jdom.Element; 11 import org.jdom.JDOMException; 12 import org.jdom.input.SAXBuilder; 13 import com.piratepete.util.db.DBConnectionType; 14 import com.piratepete.util.db.DBConnection; 15 16 17 40 public class Registry { 41 private ArrayList dbtypes; private ArrayList dblogins; 44 public Registry() { 45 dbtypes = new ArrayList (); 46 dblogins = new ArrayList (); 47 loadDBTypes(); 48 loadDBLogins(); 49 50 ArrayList myarray; 51 myarray = getDatabaseLogins(); 52 53 int i = 999; 55 } 56 57 public void loadDBTypes() { 58 try { 59 SAXBuilder builder = new SAXBuilder(); 60 InputStream ins = ClassLoader.getSystemResourceAsStream("db.conf"); Document doc = builder.build (ins); 62 Element rootElement = doc.getRootElement(); 63 List children = rootElement.getChildren("database"); 65 Iterator iterator = children.iterator(); 66 while (iterator.hasNext()) { 67 Element child = (Element) iterator.next(); 68 DBConnectionType dtype = new DBConnectionType(); 69 dtype.setName(child.getChildText("name")); 70 dtype.setClassname(child.getChildText("classname")); 71 dtype.setURL(child.getChildText("url")); 72 dbtypes.add(dtype); 73 } 74 75 } catch(JDOMException e) { 76 e.printStackTrace(); 77 } catch(NullPointerException e) { 78 e.printStackTrace(); 79 } catch (IOException ioe) { 80 ioe.printStackTrace(); 81 } 82 83 } 84 85 public void loadDBLogins() { 86 try { 87 SAXBuilder builder = new SAXBuilder(); 88 InputStream ins = ClassLoader.getSystemResourceAsStream("testlogins.conf"); Document doc = builder.build (ins); 90 Element rootElement = doc.getRootElement(); 91 Element dbElement = rootElement.getChild("connections"); 92 List children = dbElement.getChildren("connection"); 93 Iterator iterator = children.iterator(); 94 while (iterator.hasNext()) { 95 Element child = (Element) iterator.next(); 96 DBConnection dbconnection = new DBConnection(); 97 dbconnection.setName(child.getChildText("name")); 98 dbconnection.setUserName(child.getChildText("user")); 99 dbconnection.setPassword(child.getChildText("password")); 100 dbconnection.setHostname(child.getChildText("hostname")); 101 dbconnection.setSid(child.getChildText("sid")); 102 dbconnection.setClassname(child.getChildText("classname")); 103 dbconnection.setUrl(child.getChildText("url")); 104 dbconnection.setPort(child.getChildText("port")); 105 dbconnection.setTimestamp(child.getChildText("timestamp")); 106 dblogins.add(dbconnection); 107 } 108 109 } catch(JDOMException e) { 110 e.printStackTrace(); 111 } catch(NullPointerException e) { 112 e.printStackTrace(); 113 } catch (IOException ioe) { 114 ioe.printStackTrace(); 115 } 116 117 } 118 119 public ArrayList getDatabaseTypes() { 120 if (dbtypes != null) { 121 return dbtypes; 122 } else { 123 return null; 124 } 125 } 126 127 public ArrayList getDatabaseLogins() { 128 if (dblogins != null) { 129 return dblogins; 130 } else { 131 return null; 132 } 133 } 134 135 } 136 | Popular Tags |