1 22 package org.jboss.resource.adapter.jms; 23 24 import javax.jms.Connection ; 25 import javax.jms.JMSException ; 26 import javax.jms.QueueConnection ; 27 import javax.jms.TopicConnection ; 28 import javax.naming.Reference ; 29 import javax.resource.Referenceable ; 30 import javax.resource.spi.ConnectionManager ; 31 import javax.resource.spi.ManagedConnectionFactory ; 32 33 import org.jboss.logging.Logger; 34 35 47 public class JmsConnectionFactoryImpl 48 implements JmsConnectionFactory, Referenceable 49 { 50 private static final long serialVersionUID = -5135366013101194277L; 51 52 private static final Logger log = Logger.getLogger(JmsConnectionFactoryImpl.class); 53 54 private ManagedConnectionFactory mcf; 55 56 private ConnectionManager cm; 57 58 private Reference reference; 59 60 public JmsConnectionFactoryImpl(final ManagedConnectionFactory mcf, 61 final ConnectionManager cm) 62 { 63 this.mcf = mcf; 64 65 boolean trace = log.isTraceEnabled(); 66 if (cm == null) 67 { 68 this.cm = new JmsConnectionManager(); 70 if (trace) 71 log.trace("Created new connection manager"); 72 } 73 else 74 this.cm = cm; 75 76 if (trace) 77 log.trace("Using ManagedConnectionFactory=" + mcf + ", ConnectionManager=" + cm); 78 } 79 80 public void setReference(final Reference reference) 81 { 82 this.reference = reference; 83 84 if (log.isTraceEnabled()) 85 log.trace("Using Reference=" + reference); 86 } 87 88 public Reference getReference() 89 { 90 return reference; 91 } 92 93 95 public QueueConnection createQueueConnection() throws JMSException 96 { 97 QueueConnection qc = new JmsSessionFactoryImpl(mcf, cm, QUEUE); 98 99 if (log.isTraceEnabled()) 100 log.trace("Created queue connection: " + qc); 101 102 return qc; 103 } 104 105 public QueueConnection createQueueConnection(String userName, String password) 106 throws JMSException 107 { 108 JmsSessionFactoryImpl s = new JmsSessionFactoryImpl(mcf, cm, QUEUE); 109 s.setUserName(userName); 110 s.setPassword(password); 111 112 if (log.isTraceEnabled()) 113 log.trace("Created queue connection: " + s); 114 115 return s; 116 } 117 118 120 public TopicConnection createTopicConnection() throws JMSException 121 { 122 TopicConnection tc = new JmsSessionFactoryImpl(mcf, cm, TOPIC); 123 124 if (log.isTraceEnabled()) 125 log.trace("Created topic connection: " + tc); 126 127 return tc; 128 } 129 130 public TopicConnection createTopicConnection(String userName, String password) 131 throws JMSException 132 { 133 JmsSessionFactoryImpl s = new JmsSessionFactoryImpl(mcf, cm, TOPIC); 134 s.setUserName(userName); 135 s.setPassword(password); 136 137 if (log.isTraceEnabled()) 138 log.trace("Created topic connection: " + s); 139 140 return s; 141 } 142 143 145 public Connection createConnection() 146 throws JMSException 147 { 148 Connection c = new JmsSessionFactoryImpl(mcf, cm, BOTH); 149 150 if (log.isTraceEnabled()) 151 log.trace("Created connection: " + c); 152 153 return c; 154 } 155 156 public Connection createConnection(String userName, String password) 157 throws JMSException 158 { 159 JmsSessionFactoryImpl s = new JmsSessionFactoryImpl(mcf, cm, BOTH); 160 s.setUserName(userName); 161 s.setPassword(password); 162 163 if (log.isTraceEnabled()) 164 log.trace("Created connection: " + s); 165 166 return s; 167 } 168 } 169 | Popular Tags |