1 package net.walend.somnifugi; 2 3 import java.util.Hashtable ; 4 5 import javax.naming.Name ; 6 import javax.naming.Context ; 7 8 import javax.naming.spi.ObjectFactory ; 9 10 import javax.jms.TopicConnectionFactory ; 11 import javax.jms.TopicConnection ; 12 import javax.jms.JMSException ; 13 import javax.jms.Connection ; 14 15 21 22 public class SomniTopicConnectionFactory 23 implements TopicConnectionFactory , ObjectFactory 24 { 25 private static Object guard = new Object (); 26 private static int counter = 0; 27 28 public SomniTopicConnectionFactory() 29 { 30 } 31 32 46 47 public Connection createConnection() throws JMSException 48 { 49 return createTopicConnection(); 50 } 51 52 53 69 70 public Connection createConnection(String userName, String password) 71 throws JMSException 72 { 73 return createTopicConnection(userName,password); 74 } 75 76 77 78 91 public TopicConnection createTopicConnection() 92 throws JMSException 93 { 94 return createTopicConnection(SomniJNDIBypass.IT.getTopicContext()); 95 } 96 97 TopicConnection createTopicConnection(Context context) 98 { 99 synchronized(guard) 100 { 101 String connectionID = "SomniTopicConnection "+counter; 102 counter++; 103 SomniTopicConnection result = new SomniTopicConnection(this,connectionID,context); 104 SomniLogger.IT.config("Created "+connectionID); 105 return result; 106 } 107 } 108 109 110 111 126 public TopicConnection createTopicConnection(String userName, String password) 127 throws JMSException 128 { 129 SomniLogger.IT.warning("Somnifugi does not provide any security. Perhaps you shouldn't provide a userName and password."); 130 return createTopicConnection(); 131 } 132 133 public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable <?,?> environment) 135 throws Exception 136 { 137 return createTopicConnection(nameCtx); 138 } 139 140 } 141 142 162 | Popular Tags |