1 16 17 package org.springframework.jms.connection; 18 19 import javax.jms.Connection ; 20 import javax.jms.ConnectionFactory ; 21 import javax.jms.JMSException ; 22 import javax.jms.QueueConnection ; 23 import javax.jms.QueueConnectionFactory ; 24 import javax.jms.Session ; 25 import javax.jms.TopicConnection ; 26 import javax.jms.TopicConnectionFactory ; 27 28 43 public class JmsTransactionManager102 extends JmsTransactionManager { 44 45 private boolean pubSubDomain = false; 46 47 48 55 public JmsTransactionManager102() { 56 super(); 57 } 58 59 66 public JmsTransactionManager102(ConnectionFactory connectionFactory, boolean pubSubDomain) { 67 setConnectionFactory(connectionFactory); 68 this.pubSubDomain = pubSubDomain; 69 afterPropertiesSet(); 70 } 71 72 73 80 public void setPubSubDomain(boolean pubSubDomain) { 81 this.pubSubDomain = pubSubDomain; 82 } 83 84 88 public boolean isPubSubDomain() { 89 return pubSubDomain; 90 } 91 92 93 99 public void afterPropertiesSet() { 100 super.afterPropertiesSet(); 101 102 if (isPubSubDomain()) { 107 if (!(getConnectionFactory() instanceof TopicConnectionFactory )) { 108 throw new IllegalArgumentException ( 109 "Specified a Spring JMS 1.0.2 transaction manager for topics " + 110 "but did not supply an instance of TopicConnectionFactory"); 111 } 112 } 113 else { 114 if (!(getConnectionFactory() instanceof QueueConnectionFactory )) { 115 throw new IllegalArgumentException ( 116 "Specified a Spring JMS 1.0.2 transaction manager for queues " + 117 "but did not supply an instance of QueueConnectionFactory"); 118 } 119 } 120 } 121 122 123 126 protected Connection createConnection() throws JMSException { 127 if (isPubSubDomain()) { 128 return ((TopicConnectionFactory ) getConnectionFactory()).createTopicConnection(); 129 } 130 else { 131 return ((QueueConnectionFactory ) getConnectionFactory()).createQueueConnection(); 132 } 133 } 134 135 138 protected Session createSession(Connection con) throws JMSException { 139 if (isPubSubDomain()) { 140 return ((TopicConnection ) con).createTopicSession(true, Session.AUTO_ACKNOWLEDGE); 141 } 142 else { 143 return ((QueueConnection ) con).createQueueSession(true, Session.AUTO_ACKNOWLEDGE); 144 } 145 } 146 147 } 148 | Popular Tags |