1 46 47 package org.mr.ra; 48 49 import org.apache.commons.logging.Log; 50 import org.apache.commons.logging.LogFactory; 51 52 import java.io.PrintWriter ; 53 import java.util.Iterator ; 54 import java.util.Set ; 55 56 import javax.jms.JMSException ; 57 import javax.resource.ResourceException ; 58 import javax.resource.spi.ConnectionManager ; 59 import javax.resource.spi.ConnectionRequestInfo ; 60 import javax.resource.spi.ManagedConnection ; 61 import javax.resource.spi.ManagedConnectionFactory ; 62 import javax.resource.spi.ResourceAdapter ; 63 import javax.resource.spi.ResourceAdapterAssociation ; 64 import javax.security.auth.Subject ; 65 66 71 public class ManagedConnectionFactoryImpl implements 72 ManagedConnectionFactory , ResourceAdapterAssociation { 73 74 private static final long serialVersionUID = 3545800978927334450L; 75 private static final Log log = LogFactory.getLog(ManagedConnectionFactoryImpl.class); 76 77 private ResourceAdapterImpl adapter = null; 78 private PrintWriter logWriter = null; 79 private ConnectionRequestInfoImpl info; 80 81 82 85 public ManagedConnectionFactoryImpl() { 86 info = new ConnectionRequestInfoImpl(); 87 } 88 89 95 98 public Object createConnectionFactory(ConnectionManager manager) throws ResourceException { 99 return new ConnectionFactoryImpl(this, manager, info); 100 } 101 102 110 public Object createConnectionFactory() throws ResourceException { 111 return new ConnectionFactoryImpl(this, new ConnectionManagerImpl(), info); 112 } 113 114 118 public ManagedConnection createManagedConnection(Subject subject, 119 ConnectionRequestInfo info) 120 throws ResourceException 121 { 122 try { 123 ConnectionRequestInfoImpl mantaInfo = (ConnectionRequestInfoImpl)info; 124 return new ManagedConnectionImpl(subject, adapter.makeConnection(mantaInfo), mantaInfo); 125 } catch (JMSException e) { 126 throw new ResourceException ("Could not create connection.", e); 127 } 128 } 129 130 135 public ManagedConnection matchManagedConnections(Set connections, 136 Subject subject, 137 ConnectionRequestInfo info) 138 throws ResourceException 139 { 140 Iterator iterator = connections.iterator(); 141 while (iterator.hasNext()) { 142 ManagedConnectionImpl mc = (ManagedConnectionImpl) iterator.next(); 143 if (mc.matches(subject, info)) { 145 return mc; 148 } 152 } 153 return null; 154 } 155 156 159 public void setLogWriter(PrintWriter logWriter) throws ResourceException { 160 this.logWriter = logWriter; 161 } 162 163 166 public PrintWriter getLogWriter() throws ResourceException { 167 return logWriter; 168 } 169 170 171 177 180 public void setResourceAdapter(ResourceAdapter adapter) throws ResourceException { 181 this.adapter = (ResourceAdapterImpl) adapter; 182 ConnectionRequestInfoImpl baseInfo = this.adapter.getInfo().copy(); 183 if (info.getPassword() == null) 184 info.setPassword(baseInfo.getPassword()); 185 if (info.getUserName() == null) 186 info.setUserName(baseInfo.getUserName()); 187 } 188 189 192 public ResourceAdapter getResourceAdapter() { 193 return adapter; 194 } 195 196 197 200 public int hashCode() { 201 return info.hashCode(); 202 } 203 204 207 public boolean equals(Object o) { 208 if (o == null) { 209 return false; 210 } 211 if (!this.getClass().equals(o.getClass())) { 212 return false; 213 } 214 ManagedConnectionFactoryImpl otherFactory = (ManagedConnectionFactoryImpl)o; 215 return this.info.equals(otherFactory.info); 216 } 217 218 219 225 public String getPassword() { 226 return info.getPassword(); 227 } 228 229 public void setPassword(String password) { 230 info.setPassword(password); 231 } 232 233 public String getUserName() { 234 return info.getUserName(); 235 } 236 237 public void setUserName(String userid) { 238 info.setUserName(userid); 239 } 240 241 } 242 | Popular Tags |