1 24 package org.objectweb.cjdbc.driver; 25 26 import java.util.Hashtable ; 27 28 import javax.naming.Context ; 29 import javax.naming.Name ; 30 import javax.naming.Reference ; 31 import javax.naming.spi.ObjectFactory ; 32 33 41 public class DataSourceFactory implements ObjectFactory 42 { 43 44 protected final String dataSourceClassName = "org.objectweb.cjdbc.driver.DataSource"; 45 protected final String poolDataSourceName = "org.objectweb.cjdbc.driver.PoolDataSource"; 46 protected final String xaDataSourceName = "org.objectweb.cjdbc.driver.XADataSource"; 47 48 62 public Object getObjectInstance(Object objRef, Name name, Context nameCtx, 63 Hashtable env) throws Exception 64 { 65 Reference ref = (Reference ) objRef; 67 String className = ref.getClassName(); 68 if ((className == null) 69 || !(className.equals(dataSourceClassName) 70 | className.equals(poolDataSourceName) | className 71 .equals(xaDataSourceName))) 72 { 73 return null; 75 } 76 DataSource ds = null; 77 try 78 { 79 ds = (DataSource) Class.forName(className).newInstance(); 80 } 81 catch (Exception e) 82 { 83 throw new RuntimeException ("Error when creating C-JDBC" + className 84 + " instance: " + e); 85 } 86 87 ds.setUrl((String ) ref.get(DataSource.URL_PROPERTY).getContent()); 88 ds.setUser((String ) ref.get(DataSource.USER_PROPERTY).getContent()); 89 ds.setPassword((String ) ref.get(DataSource.PASSWORD_PROPERTY).getContent()); 90 return ds; 91 } 92 } 93 | Popular Tags |