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.QueueConnectionFactory ; 23 import javax.jms.TopicConnectionFactory ; 24 25 39 public class SingleConnectionFactory102 extends SingleConnectionFactory { 40 41 private boolean pubSubDomain = false; 42 43 44 47 public SingleConnectionFactory102() { 48 super(); 49 } 50 51 59 public SingleConnectionFactory102(ConnectionFactory connectionFactory, boolean pubSubDomain) { 60 setTargetConnectionFactory(connectionFactory); 61 this.pubSubDomain = pubSubDomain; 62 afterPropertiesSet(); 63 } 64 65 66 73 public void setPubSubDomain(boolean pubSubDomain) { 74 this.pubSubDomain = pubSubDomain; 75 } 76 77 81 public boolean isPubSubDomain() { 82 return this.pubSubDomain; 83 } 84 85 86 92 public void afterPropertiesSet() { 93 super.afterPropertiesSet(); 94 95 if (isPubSubDomain()) { 100 if (!(getTargetConnectionFactory() instanceof TopicConnectionFactory )) { 101 throw new IllegalArgumentException ( 102 "Specified a Spring JMS 1.0.2 SingleConnectionFactory for topics " + 103 "but did not supply an instance of TopicConnectionFactory"); 104 } 105 } 106 else { 107 if (!(getTargetConnectionFactory() instanceof QueueConnectionFactory )) { 108 throw new IllegalArgumentException ( 109 "Specified a Spring JMS 1.0.2 SingleConnectionFactory for queues " + 110 "but did not supply an instance of QueueConnectionFactory"); 111 } 112 } 113 } 114 115 118 protected Connection doCreateConnection() throws JMSException { 119 if (isPubSubDomain()) { 120 return ((TopicConnectionFactory ) getTargetConnectionFactory()).createTopicConnection(); 121 } 122 else { 123 return ((QueueConnectionFactory ) getTargetConnectionFactory()).createQueueConnection(); 124 } 125 } 126 127 } 128 | Popular Tags |