1 19 20 package org.apache.cayenne.conn; 21 22 import java.util.Hashtable ; 23 24 import javax.naming.Context ; 25 import javax.naming.Name ; 26 import javax.naming.RefAddr ; 27 import javax.naming.Reference ; 28 import javax.naming.spi.ObjectFactory ; 29 30 31 90 public class ContainerPoolFactory implements ObjectFactory { 91 92 107 public Object getObjectInstance(Object obj, Name name, Context nameCtx, 108 Hashtable environment) 109 throws Exception { 110 if ((obj == null) || !(obj instanceof Reference )) { 113 return null; 114 } 115 116 Reference ref = (Reference ) obj; 117 if (!"javax.sql.DataSource".equals(ref.getClassName())) { 118 return null; 119 } 120 121 RefAddr ra = null; 124 String driver = null; 125 String url = null; 126 int min = 1; 127 int max = 1; 128 String username = null; 129 String password = null; 130 131 ra = ref.get("min"); 132 if (ra != null) { 133 min = Integer.parseInt(ra.getContent().toString()); 134 } 135 136 ra = ref.get("max"); 137 if (ra != null) { 138 max = Integer.parseInt(ra.getContent().toString()); 139 } 140 141 142 ra = ref.get("driver"); 143 if (ra != null) { 144 driver = ra.getContent().toString(); 145 } 146 147 148 ra = ref.get("password"); 149 if (ra != null) { 150 password = ra.getContent().toString(); 151 } 152 153 ra = ref.get("url"); 154 if (ra != null) { 155 url = ra.getContent().toString(); 156 } 157 158 ra = ref.get("username"); 159 if (ra != null) { 160 username = ra.getContent().toString(); 161 } 162 163 return new PoolManager(driver, url, min, max, username, password); 164 } 165 } 166 167 | Popular Tags |