1 10 11 package org.mule.ra; 12 13 import java.beans.PropertyChangeListener ; 14 import java.beans.PropertyChangeSupport ; 15 import java.io.IOException ; 16 import java.io.ObjectInputStream ; 17 import java.io.PrintWriter ; 18 import java.util.Iterator ; 19 import java.util.Set ; 20 21 import javax.resource.ResourceException ; 22 import javax.resource.spi.ConnectionManager ; 23 import javax.resource.spi.ConnectionRequestInfo ; 24 import javax.resource.spi.ManagedConnection ; 25 import javax.resource.spi.ManagedConnectionFactory ; 26 import javax.resource.spi.security.PasswordCredential ; 27 import javax.security.auth.Subject ; 28 29 import org.apache.commons.logging.Log; 30 import org.apache.commons.logging.LogFactory; 31 32 35 36 public class MuleManagedConnectionFactory implements ManagedConnectionFactory 37 { 38 41 private static final long serialVersionUID = -1460847590293644271L; 42 43 private transient PrintWriter out; 44 private transient PropertyChangeSupport changes = new PropertyChangeSupport (this); 45 46 private String username = null; 48 49 private String password = null; 51 52 55 protected transient Log logger = LogFactory.getLog(this.getClass()); 56 57 public MuleManagedConnectionFactory() 58 { 59 super(); 60 } 61 62 private void readObject(ObjectInputStream in) throws IOException , ClassNotFoundException 63 { 64 in.defaultReadObject(); 65 this.logger = LogFactory.getLog(this.getClass()); 66 this.changes = new PropertyChangeSupport (this); 67 this.out = null; 68 } 69 70 public int hashCode() 71 { 72 final int PRIME = 31; 73 int result = 1; 74 result = PRIME * result + ((password == null) ? 0 : password.hashCode()); 75 return PRIME * result + ((username == null) ? 0 : username.hashCode()); 76 } 77 78 public boolean equals(Object obj) 79 { 80 if (this == obj) 81 { 82 return true; 83 } 84 85 if (obj == null) 86 { 87 return false; 88 } 89 90 if (this.getClass() != obj.getClass()) 91 { 92 return false; 93 } 94 95 final MuleManagedConnectionFactory other = (MuleManagedConnectionFactory)obj; 96 97 if (password == null) 98 { 99 if (other.password != null) 100 { 101 return false; 102 } 103 } 104 else if (!password.equals(other.password)) 105 { 106 return false; 107 } 108 109 if (username == null) 110 { 111 if (other.username != null) 112 { 113 return false; 114 } 115 } 116 else if (!username.equals(other.username)) 117 { 118 return false; 119 } 120 121 return true; 122 } 123 124 135 136 public Object createConnectionFactory(ConnectionManager cxManager) throws ResourceException 137 { 138 try 139 { 140 return new DefaultMuleConnectionFactory(this, cxManager, null); 141 } 142 catch (Exception e) 143 { 144 throw new ResourceException (e); 145 } 146 } 147 148 156 157 public Object createConnectionFactory() throws ResourceException 158 { 159 return new DefaultMuleConnectionFactory(this, null, null); 160 } 161 162 173 174 public ManagedConnection createManagedConnection(Subject subject, ConnectionRequestInfo cxRequestInfo) 175 throws ResourceException 176 { 177 return new MuleManagedConnection(this, subject, cxRequestInfo); 178 } 179 180 195 196 public ManagedConnection matchManagedConnections(Set connectionSet, 197 Subject subject, 198 ConnectionRequestInfo cxRequestInfo) 199 throws ResourceException 200 { 201 PasswordCredential pc = RaHelper.getPasswordCredential(this, subject, cxRequestInfo); 202 203 Iterator it = connectionSet.iterator(); 204 while (it.hasNext()) 205 { 206 Object obj = it.next(); 207 if (obj instanceof MuleManagedConnection) 208 { 209 MuleManagedConnection mc = (MuleManagedConnection)obj; 210 PasswordCredential mcpc = mc.getPasswordCredential(); 211 if (mcpc != null && pc != null && mcpc.equals(pc)) 212 { 213 return mc; 214 } 215 } 216 } 217 return null; 218 } 219 220 228 229 public void setLogWriter(PrintWriter out) throws ResourceException 230 { 231 this.out = out; 232 } 233 234 240 241 public PrintWriter getLogWriter() throws ResourceException 242 { 243 return this.out; 244 } 245 246 253 254 public void addPropertyChangeListener(PropertyChangeListener lis) 255 { 256 changes.addPropertyChangeListener(lis); 257 } 258 259 265 266 public void removePropertyChangeListener(PropertyChangeListener lis) 267 { 268 changes.removePropertyChangeListener(lis); 269 } 270 271 276 277 public String getUsername() 278 { 279 return this.username; 280 } 281 282 287 288 public void setUsername(String username) 289 { 290 this.username = username; 291 } 292 293 298 299 public String getPassword() 300 { 301 return this.password; 302 } 303 304 309 310 public void setPassword(String password) 311 { 312 this.password = password; 313 } 314 } 315 | Popular Tags |