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.QueueConnectionFactory ; 11 import javax.jms.QueueConnection ; 12 import javax.jms.Connection ; 13 import javax.jms.JMSException ; 14 15 21 22 public class SomniQueueConnectionFactory 23 implements QueueConnectionFactory , ObjectFactory 24 { 25 private static Object guard = new Object (); 26 private static int counter = 0; 27 28 public SomniQueueConnectionFactory() 29 { 30 } 31 32 46 47 public Connection createConnection() throws JMSException 48 { 49 return createQueueConnection(); 50 } 51 52 68 69 public Connection createConnection(String userName, String password) 70 throws JMSException 71 { 72 return createQueueConnection(userName,password); 73 } 74 75 88 public QueueConnection createQueueConnection() 89 throws JMSException 90 { 91 return createQueueConnection(SomniJNDIBypass.IT.getQueueContext()); 92 } 93 94 QueueConnection createQueueConnection(Context context) 95 { 96 synchronized(guard) 97 { 98 String connectionID = "SomniQueueConnection"+counter; 99 counter++; 100 SomniQueueConnection result = new SomniQueueConnection(this,connectionID,context); 101 SomniLogger.IT.config("Created "+connectionID); 102 return result; 103 } 104 } 105 106 121 public QueueConnection createQueueConnection(String userName, String password) 122 throws JMSException 123 { 124 SomniLogger.IT.warning("Somnifugi does not provide any security. Perhaps you shouldn't provide a userName and password."); 125 return createQueueConnection(); 126 } 127 128 public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable <?,?> environment) 130 throws Exception 131 { 132 return createQueueConnection(nameCtx); 133 } 134 135 } 136 137 157 | Popular Tags |