1 22 package org.jboss.resource.adapter.jms; 23 24 import java.io.PrintWriter ; 25 import java.util.Iterator ; 26 import java.util.Set ; 27 28 import javax.jms.ConnectionMetaData ; 29 import javax.resource.ResourceException ; 30 import javax.resource.spi.ConnectionManager ; 31 import javax.resource.spi.ConnectionRequestInfo ; 32 import javax.resource.spi.ManagedConnection ; 33 import javax.resource.spi.ManagedConnectionFactory ; 34 import javax.security.auth.Subject ; 35 36 import org.jboss.jms.jndi.JMSProviderAdapter; 37 import org.jboss.logging.Logger; 38 39 46 public class JmsManagedConnectionFactory implements ManagedConnectionFactory 47 { 48 private static final long serialVersionUID = -923483284031773011L; 49 50 private static final Logger log = Logger.getLogger(JmsManagedConnection.class); 51 52 53 private JmsMCFProperties mcfProperties = new JmsMCFProperties(); 54 55 56 private boolean strict = true; 57 58 59 private JMSProviderAdapter adapter; 60 61 public JmsManagedConnectionFactory() 62 { 63 } 65 66 69 public Object createConnectionFactory() throws ResourceException 70 { 71 return createConnectionFactory(null); 72 } 73 74 77 public Object createConnectionFactory(ConnectionManager cxManager) throws ResourceException 78 { 79 Object cf = new JmsConnectionFactoryImpl(this, cxManager); 80 81 if (log.isTraceEnabled()) 82 { 83 log.trace("Created connection factory: " + cf + ", using connection manager: " + cxManager); 84 } 85 86 return cf; 87 } 88 89 92 public ManagedConnection createManagedConnection(Subject subject, ConnectionRequestInfo info) 93 throws ResourceException 94 { 95 boolean trace = log.isTraceEnabled(); 96 97 info = getInfo(info); 98 if (trace) 99 log.trace("connection request info: " + info); 100 101 JmsCred cred = JmsCred.getJmsCred(this, subject, info); 102 if (trace) 103 log.trace("jms credentials: " + cred); 104 105 JmsManagedConnection mc = new JmsManagedConnection(this, info, cred.name, cred.pwd); 107 108 if (trace) 109 log.trace("created new managed connection: " + mc); 110 111 113 117 return mc; 118 } 119 120 123 public ManagedConnection matchManagedConnections(Set connectionSet, Subject subject, ConnectionRequestInfo info) 124 throws ResourceException 125 { 126 boolean trace = log.isTraceEnabled(); 127 128 info = getInfo(info); 130 JmsCred cred = JmsCred.getJmsCred(this, subject, info); 131 132 if (trace) 133 log.trace("Looking for connection matching credentials: " + cred); 134 135 Iterator connections = connectionSet.iterator(); 138 139 while (connections.hasNext()) 140 { 141 Object obj = connections.next(); 142 143 if (obj instanceof JmsManagedConnection) 145 { 146 JmsManagedConnection mc = (JmsManagedConnection) obj; 148 149 ManagedConnectionFactory mcf = mc.getManagedConnectionFactory(); 151 152 155 158 if ((mc.getUserName() == null || (mc.getUserName() != null && mc.getUserName().equals(cred.name))) 159 && mcf.equals(this)) 160 { 161 if (info.equals(mc.getInfo())) 163 { 164 165 if (trace) 166 log.trace("Found matching connection: " + mc); 167 168 return mc; 169 } 170 } 171 } 172 } 173 174 if (trace) 175 log.trace("No matching connection was found"); 176 177 return null; 178 } 179 180 public void setLogWriter(PrintWriter out) throws ResourceException 181 { 182 } 186 187 public PrintWriter getLogWriter() throws ResourceException 188 { 189 193 return null; 194 } 195 196 199 public boolean equals(Object obj) 200 { 201 if (obj == null) 202 return false; 203 if (obj instanceof JmsManagedConnectionFactory) 204 { 205 return mcfProperties.equals(((JmsManagedConnectionFactory) obj).getProperties()); 206 } 207 else 208 { 209 return false; 210 } 211 } 212 213 public int hashCode() 214 { 215 return mcfProperties.hashCode(); 216 } 217 218 220 public void setJmsProviderAdapterJNDI(String jndi) 221 { 222 mcfProperties.setProviderJNDI(jndi); 223 } 224 225 public String getJmsProviderAdapterJNDI() 226 { 227 return mcfProperties.getProviderJNDI(); 228 } 229 230 233 public void setUserName(String userName) 234 { 235 mcfProperties.setUserName(userName); 236 } 237 238 241 public String getUserName() 242 { 243 return mcfProperties.getUserName(); 244 } 245 246 249 public void setPassword(String password) 250 { 251 mcfProperties.setPassword(password); 252 } 253 254 257 public String getPassword() 258 { 259 return mcfProperties.getPassword(); 260 } 261 262 265 public String getClientID() 266 { 267 return mcfProperties.getClientID(); 268 } 269 270 273 public void setClientID(final String clientID) 274 { 275 mcfProperties.setClientID(clientID); 276 } 277 278 public boolean isStrict() 279 { 280 return strict; 281 } 282 283 public void setStrict(boolean strict) 284 { 285 this.strict = strict; 286 } 287 288 public void setStrict(Boolean strict) 289 { 290 this.strict = strict.booleanValue(); 291 } 292 293 300 public void setSessionDefaultType(String type) throws ResourceException 301 { 302 mcfProperties.setSessionDefaultType(type); 303 } 304 305 public String getSessionDefaultType() 306 { 307 return mcfProperties.getSessionDefaultType(); 308 } 309 310 313 public void setJmsProviderAdapter(final JMSProviderAdapter adapter) 314 { 315 this.adapter = adapter; 316 } 317 318 public JMSProviderAdapter getJmsProviderAdapter() 319 { 320 return adapter; 321 } 322 323 private ConnectionRequestInfo getInfo(ConnectionRequestInfo info) 324 { 325 if (info == null) 326 { 327 return new JmsConnectionRequestInfo(mcfProperties); 329 } 330 else 331 { 332 ((JmsConnectionRequestInfo) info).setDefaults(mcfProperties); 334 return info; 335 } 336 } 337 338 public ConnectionMetaData getMetaData() 339 { 340 return new JmsConnectionMetaData(); 341 } 342 343 345 protected JmsMCFProperties getProperties() 346 { 347 return mcfProperties; 348 } 349 } 350 | Popular Tags |