1 56 package org.objectstyle.cayenne.conn; 57 58 import java.util.Hashtable ; 59 60 import javax.naming.Context ; 61 import javax.naming.Name ; 62 import javax.naming.RefAddr ; 63 import javax.naming.Reference ; 64 import javax.naming.spi.ObjectFactory ; 65 66 import org.apache.log4j.Logger; 67 68 69 128 129 public class ContainerPoolFactory implements ObjectFactory { 130 private static Logger logObj = Logger.getLogger(ContainerPoolFactory.class); 131 132 133 148 public Object getObjectInstance(Object obj, Name name, Context nameCtx, 149 Hashtable environment) 150 throws Exception { 151 if ((obj == null) || !(obj instanceof Reference )) { 154 logObj.info("unsupported or null reference: " + obj); 155 return null; 156 } 157 158 Reference ref = (Reference ) obj; 159 if (!"javax.sql.DataSource".equals(ref.getClassName())) { 160 logObj.info("unsupported type: " + ref.getClassName()); 161 return null; 162 } 163 164 RefAddr ra = null; 167 String driver = null; 168 String url = null; 169 int min = 1; 170 int max = 1; 171 String username = null; 172 String password = null; 173 174 ra = ref.get("min"); 175 if (ra != null) { 176 min = Integer.parseInt(ra.getContent().toString()); 177 } 178 179 ra = ref.get("max"); 180 if (ra != null) { 181 max = Integer.parseInt(ra.getContent().toString()); 182 } 183 184 185 ra = ref.get("driver"); 186 if (ra != null) { 187 driver = ra.getContent().toString(); 188 } 189 190 191 ra = ref.get("password"); 192 if (ra != null) { 193 password = ra.getContent().toString(); 194 } 195 196 ra = ref.get("url"); 197 if (ra != null) { 198 url = ra.getContent().toString(); 199 } 200 201 ra = ref.get("username"); 202 if (ra != null) { 203 username = ra.getContent().toString(); 204 } 205 206 logObj.info("Loading datasource driver: " + driver); 207 logObj.info("Connecting to URL: " + url); 208 return new PoolManager(driver, url, min, max, username, password); 209 } 210 } 211 212 | Popular Tags |