1 7 package org.ejtools.jndi.browser.model.service; 8 9 import java.beans.beancontext.BeanContextServices ; 10 import java.util.Iterator ; 11 import java.util.ResourceBundle ; 12 import java.util.Vector ; 13 14 import javax.jms.QueueConnectionFactory ; 15 import javax.jms.TopicConnectionFactory ; 16 import javax.swing.JOptionPane ; 17 18 import org.ejtools.beans.beancontext.CustomBeanContextServiceProvider; 19 import org.ejtools.jndi.browser.model.jms.ConnectionFactoryProxy; 20 21 31 public class JMSConnectionServiceProvider extends CustomBeanContextServiceProvider implements JMSConnectionService 32 { 33 34 protected int defaultQueueConnectionFactory = 0; 35 36 protected int defaultTopicConnectionFactory = 0; 37 38 protected Vector queueConnectionFactories = new Vector (); 39 40 protected Vector topicConnectionFactories = new Vector (); 41 42 private static ResourceBundle resources = ResourceBundle.getBundle("org.ejtools.jndi.browser.Resources"); 43 44 45 52 public Iterator getCurrentServiceSelectors(BeanContextServices bcs, java.lang.Class serviceClass) 53 { 54 return (new Vector ()).iterator(); 55 } 56 57 58 63 public QueueConnectionFactory getDefaultQueueConnectionFactory() 64 { 65 if (queueConnectionFactories.size() == 0) 66 { 67 JOptionPane.showMessageDialog(null, 68 resources.getString("text.information.noDefaultFactory.queue"), 69 resources.getString("title.information.defaultFactory.queue"), 70 JOptionPane.INFORMATION_MESSAGE); 71 } 72 else 73 { 74 ConnectionFactoryProxy proxy = (ConnectionFactoryProxy) queueConnectionFactories.elementAt(defaultQueueConnectionFactory); 75 return proxy.getQueueConnectionFactory(); 76 } 77 return null; 78 } 79 80 81 86 public TopicConnectionFactory getDefaultTopicConnectionFactory() 87 { 88 if (topicConnectionFactories.size() == 0) 89 { 90 JOptionPane.showMessageDialog(null, 91 resources.getString("text.information.noDefaultFactory.topic"), 92 resources.getString("title.information.defaultFactory.topic"), 93 JOptionPane.INFORMATION_MESSAGE); 94 } 95 else 96 { 97 ConnectionFactoryProxy proxy = (ConnectionFactoryProxy) topicConnectionFactories.elementAt(defaultTopicConnectionFactory); 98 return proxy.getTopicConnectionFactory(); 99 } 100 return null; 101 } 102 103 104 113 public Object getService(BeanContextServices bcs, java.lang.Object requestor, java.lang.Class serviceClass, java.lang.Object serviceSelector) 114 { 115 if (requestor instanceof ConnectionFactoryProxy) 116 { 117 ConnectionFactoryProxy proxy = (ConnectionFactoryProxy) requestor; 118 if (proxy.isQueueConnectionFactory()) 119 { 120 queueConnectionFactories.add(proxy); 121 } 122 if (proxy.isTopicConnectionFactory()) 123 { 124 topicConnectionFactories.add(proxy); 125 } 126 } 127 return this; 128 } 129 130 131 138 public void releaseService(BeanContextServices bcs, java.lang.Object requestor, java.lang.Object service) 139 { 140 if (requestor instanceof ConnectionFactoryProxy) 141 { 142 ConnectionFactoryProxy proxy = (ConnectionFactoryProxy) requestor; 143 if (proxy.isQueueConnectionFactory()) 144 { 145 queueConnectionFactories.remove(proxy); 146 if ((this.defaultQueueConnectionFactory >= queueConnectionFactories.size()) 147 && (this.defaultQueueConnectionFactory > 0)) 148 { 149 this.defaultQueueConnectionFactory = queueConnectionFactories.size() - 1; 150 } 151 } 152 if (proxy.isTopicConnectionFactory()) 153 { 154 topicConnectionFactories.remove(proxy); 155 if ((this.defaultTopicConnectionFactory >= topicConnectionFactories.size()) 156 && (this.defaultTopicConnectionFactory > 0)) 157 { 158 this.defaultTopicConnectionFactory = topicConnectionFactories.size() - 1; 159 } 160 } 161 } 162 } 163 164 165 170 public void selectFactory(String type) 171 { 172 if (JMSConnectionService.QUEUE_CONNECTION_FACTORY.equals(type)) 173 { 174 selectQueueConnectionFactory(); 175 } 176 if (JMSConnectionService.TOPIC_CONNECTION_FACTORY.equals(type)) 177 { 178 selectTopicConnectionFactory(); 179 } 180 } 181 182 183 184 public void selectQueueConnectionFactory() 185 { 186 if (queueConnectionFactories.size() > 0) 187 { 188 Object selectedValue = JOptionPane.showInputDialog(null, 189 resources.getString("text.question.defaultFactory.queue"), 190 resources.getString("title.question.defaultFactory.queue"), 191 JOptionPane.QUESTION_MESSAGE, 192 null, 193 queueConnectionFactories.toArray(), 194 queueConnectionFactories.elementAt(defaultQueueConnectionFactory)); 195 if (selectedValue != null) 196 { 197 defaultQueueConnectionFactory = queueConnectionFactories.indexOf(selectedValue); 198 } 199 else 200 { 201 return; 202 } 203 } 204 else 205 { 206 JOptionPane.showMessageDialog(null, 207 resources.getString("text.information.noDefaultFactory.queue"), 208 resources.getString("title.information.defaultFactory.queue"), 209 JOptionPane.INFORMATION_MESSAGE); 210 } 211 } 212 213 214 215 public void selectTopicConnectionFactory() 216 { 217 if (topicConnectionFactories.size() > 0) 218 { 219 Object selectedValue = JOptionPane.showInputDialog(null, 220 resources.getString("text.question.defaultFactory.topic"), 221 resources.getString("title.question.defaultFactory.topic"), 222 JOptionPane.QUESTION_MESSAGE, 223 null, 224 topicConnectionFactories.toArray(), 225 topicConnectionFactories.elementAt(defaultTopicConnectionFactory)); 226 if (selectedValue != null) 227 { 228 defaultTopicConnectionFactory = topicConnectionFactories.indexOf(selectedValue); 229 } 230 else 231 { 232 return; 233 } 234 } 235 else 236 { 237 JOptionPane.showMessageDialog(null, 238 resources.getString("text.information.noDefaultFactory.topic"), 239 resources.getString("title.information.defaultFactory.topic"), 240 JOptionPane.INFORMATION_MESSAGE); 241 } 242 } 243 244 245 248 protected Class [] getServiceClass() 249 { 250 return new Class []{JMSConnectionService.class}; 251 } 252 } 253 254 | Popular Tags |