1 16 17 package org.apache.axis.components.jms; 18 19 import java.util.HashMap ; 20 import java.util.Hashtable ; 21 22 import javax.jms.ConnectionFactory ; 23 import javax.jms.Queue ; 24 import javax.jms.QueueConnectionFactory ; 25 import javax.jms.QueueSession ; 26 import javax.jms.Topic ; 27 import javax.jms.TopicConnectionFactory ; 28 import javax.jms.TopicSession ; 29 import javax.naming.Context ; 30 import javax.naming.InitialContext ; 31 32 import org.apache.axis.transport.jms.JMSConstants; 33 import org.apache.axis.transport.jms.JMSURLHelper; 34 35 41 public class JNDIVendorAdapter extends JMSVendorAdapter 42 { 43 public final static String CONTEXT_FACTORY = "java.naming.factory.initial"; 44 public final static String PROVIDER_URL = "java.naming.provider.url"; 45 46 public final static String _CONNECTION_FACTORY_JNDI_NAME = "ConnectionFactoryJNDIName"; 47 public final static String CONNECTION_FACTORY_JNDI_NAME = JMSConstants.JMS_PROPERTY_PREFIX + 48 _CONNECTION_FACTORY_JNDI_NAME; 49 50 private Context context; 51 52 public QueueConnectionFactory getQueueConnectionFactory(HashMap cfConfig) 53 throws Exception 54 { 55 return (QueueConnectionFactory )getConnectionFactory(cfConfig); 56 } 57 58 public TopicConnectionFactory getTopicConnectionFactory(HashMap cfConfig) 59 throws Exception 60 { 61 return (TopicConnectionFactory )getConnectionFactory(cfConfig); 62 } 63 64 private ConnectionFactory getConnectionFactory(HashMap cfProps) 65 throws Exception 66 { 67 if(cfProps == null) 68 throw new IllegalArgumentException ("noCFProps"); 69 String jndiName = (String )cfProps.get(CONNECTION_FACTORY_JNDI_NAME); 70 if(jndiName == null || jndiName.trim().length() == 0) 71 throw new IllegalArgumentException ("noCFName"); 72 73 Hashtable environment = new Hashtable (cfProps); 74 75 String ctxFactory = (String )cfProps.get(CONTEXT_FACTORY); 77 if (ctxFactory != null) 78 environment.put(CONTEXT_FACTORY, ctxFactory); 79 80 String providerURL = (String )cfProps.get(PROVIDER_URL); 82 if (providerURL != null) 83 environment.put(PROVIDER_URL, providerURL); 84 85 context = new InitialContext (environment); 86 87 return (ConnectionFactory )context.lookup(jndiName); 88 } 89 90 97 public void addVendorConnectionFactoryProperties(JMSURLHelper jmsurl, 98 HashMap cfConfig) 99 { 100 String cfJNDIName = jmsurl.getPropertyValue(_CONNECTION_FACTORY_JNDI_NAME); 102 if (cfJNDIName != null) 103 cfConfig.put(CONNECTION_FACTORY_JNDI_NAME, cfJNDIName); 104 105 String ctxFactory = jmsurl.getPropertyValue(CONTEXT_FACTORY); 107 if (ctxFactory != null) 108 cfConfig.put(CONTEXT_FACTORY, ctxFactory); 109 110 String providerURL = jmsurl.getPropertyValue(PROVIDER_URL); 112 if (providerURL != null) 113 cfConfig.put(PROVIDER_URL, providerURL); 114 } 115 116 125 public boolean isMatchingConnectionFactory(ConnectionFactory cf, 126 JMSURLHelper originalJMSURL, 127 HashMap cfProps) 128 { 129 JMSURLHelper jmsurl = (JMSURLHelper)cfProps.get(JMSConstants.JMS_URL); 130 131 String cfJndiName = jmsurl.getPropertyValue(_CONNECTION_FACTORY_JNDI_NAME); 133 String originalCfJndiName = originalJMSURL.getPropertyValue(_CONNECTION_FACTORY_JNDI_NAME); 134 135 if (cfJndiName.equalsIgnoreCase(originalCfJndiName)) 136 return true; 137 138 return false; 139 } 140 141 public Queue getQueue(QueueSession session, String name) 142 throws Exception 143 { 144 return (Queue )context.lookup(name); 145 } 146 147 public Topic getTopic(TopicSession session, String name) 148 throws Exception 149 { 150 return (Topic )context.lookup(name); 151 } 152 } | Popular Tags |