1 46 47 package org.mr.ra; 48 49 50 import java.io.Serializable ; 52 53 import javax.jms.Connection ; 54 import javax.jms.ConnectionFactory ; 55 import javax.jms.QueueConnection ; 56 import javax.jms.QueueConnectionFactory ; 57 import javax.jms.TopicConnection ; 58 import javax.jms.TopicConnectionFactory ; 59 import javax.jms.JMSException ; 60 61 import javax.naming.Reference ; 62 import javax.resource.Referenceable ; 63 import javax.resource.ResourceException ; 64 import javax.resource.spi.ConnectionManager ; 65 66 import org.apache.commons.logging.Log; 67 import org.apache.commons.logging.LogFactory; 68 69 70 73 public class ConnectionFactoryImpl implements ConnectionFactory , QueueConnectionFactory , 74 TopicConnectionFactory , Referenceable , Serializable 75 { 76 private static final long serialVersionUID = 3616445704952820529L; 77 private static final Log log = LogFactory.getLog(ConnectionFactoryImpl.class); 78 79 transient private ConnectionManager manager; 80 transient private ManagedConnectionFactoryImpl factory; 81 private final ConnectionRequestInfoImpl info; 82 private Reference reference = null; 83 84 85 91 public ConnectionFactoryImpl(ManagedConnectionFactoryImpl factory, 92 ConnectionManager manager, 93 ConnectionRequestInfoImpl info) { 94 this.factory = factory; 95 this.manager = manager; 96 this.info = info; 97 } 98 99 100 105 private Connection createConnection(ConnectionRequestInfoImpl info) throws JMSException { 106 try { 107 111 return (Connection ) manager.allocateConnection(factory, info); 114 } 115 catch (ResourceException e) { 116 log.debug("Connection could not be created:", e); 117 if (e.getCause() instanceof JMSException ) { 119 throw (JMSException ) e.getCause(); 121 } 122 throw new JMSException (e.getMessage()); 123 } 124 } 125 126 127 133 136 public Connection createConnection() throws JMSException { 137 return createConnection(info.copy()); 138 } 139 140 143 public Connection createConnection(String userName, String password) throws JMSException { 144 ConnectionRequestInfoImpl i = info.copy(); 145 i.setUserName(userName); 146 i.setPassword(password); 147 return createConnection(i); 148 } 149 150 151 157 160 public QueueConnection createQueueConnection() throws JMSException { 161 return (QueueConnection ) createConnection(); 162 } 163 164 167 public QueueConnection createQueueConnection(String userName, String password) throws JMSException { 168 return (QueueConnection ) createConnection(userName, password); 169 } 170 171 172 178 181 public TopicConnection createTopicConnection() throws JMSException { 182 return (TopicConnection ) createConnection(); 183 } 184 185 188 public TopicConnection createTopicConnection(String userName, String password) throws JMSException { 189 return (TopicConnection ) createConnection(userName, password); 190 } 191 192 193 199 202 public Reference getReference() { 203 return reference; 204 } 205 206 209 public void setReference(Reference reference) { 210 this.reference = reference; 211 } 212 } 213 | Popular Tags |