1 22 package org.jboss.mq; 23 24 import java.io.Serializable ; 25 import java.util.Properties ; 26 27 import javax.jms.Connection ; 28 import javax.jms.ConnectionFactory ; 29 import javax.jms.JMSException ; 30 import javax.jms.QueueConnection ; 31 import javax.jms.QueueConnectionFactory ; 32 import javax.jms.TopicConnection ; 33 import javax.jms.TopicConnectionFactory ; 34 import javax.naming.NamingException ; 35 import javax.naming.Reference ; 36 import javax.naming.Referenceable ; 37 38 import org.jboss.mq.referenceable.ObjectRefAddr; 39 40 50 public class SpyConnectionFactory 51 implements Serializable , ConnectionFactory , QueueConnectionFactory , TopicConnectionFactory , Referenceable 52 { 53 54 static final long serialVersionUID = 3392566934963731105L; 55 56 57 protected GenericConnectionFactory factory; 58 59 64 public SpyConnectionFactory(GenericConnectionFactory factory) 65 { 66 this.factory = factory; 67 } 68 69 74 public SpyConnectionFactory(Properties config) 75 { 76 this.factory = new GenericConnectionFactory(null, config); 77 } 78 79 82 public Properties getProperties() 83 { 84 if (factory == null) 85 return null; 86 else 87 return factory.getProperties(); 88 } 89 90 public Reference getReference() throws NamingException 91 { 92 return new Reference ("org.jboss.mq.SpyConnectionFactory", new ObjectRefAddr("DCF", factory), 93 "org.jboss.mq.referenceable.SpyConnectionFactoryObjectFactory", null); 94 } 95 96 public Connection createConnection() throws JMSException 97 { 98 return internalCreateConnection(SpyConnection.UNIFIED); 99 } 100 101 public Connection createConnection(String userName, String password) throws JMSException 102 { 103 return internalCreateConnection(SpyConnection.UNIFIED, userName, password); 104 } 105 106 public QueueConnection createQueueConnection() throws JMSException 107 { 108 return (QueueConnection ) internalCreateConnection(SpyConnection.QUEUE); 109 } 110 111 public QueueConnection createQueueConnection(String userName, String password) throws JMSException 112 { 113 return (QueueConnection ) internalCreateConnection(SpyConnection.QUEUE, userName, password); 114 } 115 116 public TopicConnection createTopicConnection() throws JMSException 117 { 118 return (TopicConnection ) internalCreateConnection(SpyConnection.TOPIC); 119 } 120 121 public TopicConnection createTopicConnection(String userName, String password) throws JMSException 122 { 123 return (TopicConnection ) internalCreateConnection(SpyConnection.TOPIC, userName, password); 124 } 125 126 133 protected Connection internalCreateConnection(int type) throws JMSException 134 { 135 try 136 { 137 return new SpyConnection(type, factory); 138 } 139 catch (JMSException e) 140 { 141 throw e; 142 } 143 catch (Exception e) 144 { 145 throw new SpyJMSException("Failed to create Connection", e); 146 } 147 } 148 149 158 protected Connection internalCreateConnection(int type, String userName, String password) throws JMSException 159 { 160 try 161 { 162 if (userName == null) 163 throw new SpyJMSException("Username is null"); 164 if (password == null) 165 throw new SpyJMSException("Password is null"); 166 167 return new SpyConnection(type, userName, password, factory); 168 } 169 catch (JMSException e) 170 { 171 throw e; 172 } 173 catch (Exception e) 174 { 175 throw new SpyJMSException("Failed to create Connection", e); 176 } 177 } 178 } | Popular Tags |