1 22 23 package org.xquark.xml.xdbc; 24 25 26 29 public class XMLDriverManager { 30 31 32 33 private static java.util.Set drivers = java.util.Collections.synchronizedSet(new java.util.HashSet ()); 34 private static java.io.PrintWriter logWriter = null; 35 private static int loginTimeout = 0; 36 37 private XMLDriverManager() {} 38 39 45 public static XMLDriver getDriver(String uri) 46 throws XMLDBCException { 47 java.util.Iterator it = getDrivers(); 48 while (it.hasNext()) { 49 XMLDriver driver = (XMLDriver)it.next(); 50 if (driver.acceptsURI(uri)) 51 return driver; 52 } 53 return null; 54 } 55 56 62 public static XMLConnection getConnection(String uri) 63 throws XMLDBCException { 64 return getDataSource(uri).getConnection(); 65 } 66 67 75 public static XMLConnection getConnection(String uri, String user, String password) 76 throws XMLDBCException { 77 XMLDriver driver = getDriver(uri); 78 if (driver == null) throw new XMLDBCException("No driver found for uri: "+uri); 79 XMLDataSource dataSource = driver.getDataSource(uri, user, password); 81 if (dataSource != null) { 82 dataSource.setLogWriter(logWriter); 83 dataSource.setLoginTimeout(loginTimeout); 84 return dataSource.getConnection(); 85 } 86 dataSource = driver.getDataSource(uri); 88 if (dataSource != null) { 89 dataSource.setLogWriter(logWriter); 90 dataSource.setLoginTimeout(loginTimeout); 91 return dataSource.getConnection(user, password); 92 } else { 93 throw new XMLDBCException("No data source found for uri: "+uri); 94 } 95 } 96 97 104 public static XMLDataSource getDataSource(String uri) 105 throws XMLDBCException { 106 XMLDriver driver = getDriver(uri); 107 if (driver == null) throw new XMLDBCException("No driver found for uri: "+uri); 108 XMLDataSource dataSource = driver.getDataSource(uri); 109 if (dataSource == null) throw new XMLDBCException("No data source found for uri: "+uri); 110 dataSource.setLogWriter(logWriter); 111 dataSource.setLoginTimeout(loginTimeout); 112 return dataSource; 113 } 114 115 124 public static XMLDataSource getDataSource(String uri, String user, String password) 125 throws XMLDBCException { 126 XMLDriver driver = getDriver(uri); 127 if (driver == null) throw new XMLDBCException("No driver found for uri: "+uri); 128 XMLDataSource dataSource = driver.getDataSource(uri, user, password); 129 if (dataSource == null) throw new XMLDBCException("No data source found for uri: "+uri); 130 dataSource.setLogWriter(logWriter); 131 dataSource.setLoginTimeout(loginTimeout); 132 return dataSource; 133 } 134 135 141 public static void setLogWriter(java.io.PrintWriter writer) { 142 logWriter = writer; 143 } 144 145 150 public java.io.PrintWriter getLogWriter() { 151 return logWriter; 152 } 153 154 160 public void setLoginTimeout(int seconds) { 161 loginTimeout = seconds; 162 } 163 164 169 public int getLoginTimeout() { 170 return loginTimeout; 171 } 172 173 178 public static void registerDriver(XMLDriver driver) { 179 drivers.add(driver); 180 } 181 182 186 public static void deregisterDriver(XMLDriver driver) { 187 drivers.remove(driver); 188 } 189 190 194 public static java.util.Iterator getDrivers() { 195 return drivers.iterator(); 196 } 197 } 198 | Popular Tags |