1 43 package org.exolab.jms.server.net; 44 45 import java.util.Map ; 46 47 import javax.naming.Context ; 48 import javax.naming.NamingException ; 49 import javax.jms.XAConnectionFactory ; 50 51 import org.apache.commons.logging.Log; 52 import org.apache.commons.logging.LogFactory; 53 54 import org.exolab.jms.client.JmsConnectionFactory; 55 import org.exolab.jms.client.JmsServerStubIfc; 56 import org.exolab.jms.client.JmsXAConnectionFactory; 57 import org.exolab.jms.config.ConnectionFactories; 58 import org.exolab.jms.config.ConnectionFactory; 59 import org.exolab.jms.config.QueueConnectionFactory; 60 import org.exolab.jms.config.TopicConnectionFactory; 61 import org.exolab.jms.config.XAQueueConnectionFactory; 62 import org.exolab.jms.config.XATopicConnectionFactory; 63 import org.exolab.jms.config.ConnectionFactoryType; 64 import org.exolab.jms.server.ServerConnector; 65 66 67 73 public class ConnectionFactoryHelper { 74 75 78 private static final Log _log = 79 LogFactory.getLog(ConnectionFactoryHelper.class); 80 81 82 93 public static void bind(Context context, ConnectionFactories factories, 94 Class implementation, Map properties) 95 throws NamingException { 96 if (context == null) { 97 throw new IllegalArgumentException ("Argument 'context' is null"); 98 } 99 if (factories == null) { 100 throw new IllegalArgumentException ("Argument 'factories' is null"); 101 } 102 if (implementation == null) { 103 throw new IllegalArgumentException ( 104 "Argument 'implementation' is null"); 105 } 106 if (!JmsServerStubIfc.class.isAssignableFrom(implementation)) { 107 throw new IllegalArgumentException ( 108 "Class " + implementation.getName() + " does not implement " + 109 JmsServerStubIfc.class.getName()); 110 } 111 if (properties == null) { 112 throw new IllegalArgumentException ("Argument properties is null"); 113 } 114 115 ConnectionFactoryType[] type = factories.getConnectionFactory(); 116 ConnectionFactoryType[] queue = factories.getQueueConnectionFactory(); 117 ConnectionFactoryType[] topic = factories.getTopicConnectionFactory(); 118 ConnectionFactoryType[] xatype = factories.getXAConnectionFactory(); 119 ConnectionFactoryType[] xaqueue = 120 factories.getXAQueueConnectionFactory(); 121 ConnectionFactoryType[] xatopic = 122 factories.getXATopicConnectionFactory(); 123 for (int i = 0; i < type.length; ++i) { 124 bind(context, type[i], implementation, properties); 125 } 126 for (int i = 0; i < queue.length; ++i) { 127 bind(context, queue[i], implementation, properties); 128 } 129 for (int i = 0; i < topic.length; ++i) { 130 bind(context, topic[i], implementation, properties); 131 } 132 for (int i = 0; i < xatype.length; ++i) { 133 bind(context, xatype[i], implementation, properties); 134 } 135 for (int i = 0; i < xaqueue.length; ++i) { 136 bind(context, xaqueue[i], implementation, properties); 137 } 138 for (int i = 0; i < xatopic.length; ++i) { 139 bind(context, xatopic[i], implementation, properties); 140 } 141 } 142 143 154 private static void bind(Context context, ConnectionFactoryType factory, 155 Class implementation, Map properties) 156 throws NamingException { 157 JmsConnectionFactory instance = null; 158 if (factory instanceof ConnectionFactory 159 || factory instanceof QueueConnectionFactory 160 || factory instanceof TopicConnectionFactory) { 161 instance = new JmsConnectionFactory(implementation.getName(), 162 properties, null); 163 } else if (factory instanceof XAConnectionFactory 164 || factory instanceof XAQueueConnectionFactory 165 || factory instanceof XATopicConnectionFactory) { 166 instance = new JmsXAConnectionFactory( 167 implementation.getName(), properties); 168 } else { 169 throw new IllegalArgumentException ( 170 "Unknown connection factory type: " + 171 factory.getClass().getName()); 172 } 173 174 context.rebind(factory.getName(), instance); 175 _log.debug("Bound connection factory " + factory.getName()); 176 } 177 178 } 179 | Popular Tags |