KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > jndi > browser > model > service > JMSConnectionServiceProvider


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.jndi.browser.model.service;
8
9 import java.beans.beancontext.BeanContextServices JavaDoc;
10 import java.util.Iterator JavaDoc;
11 import java.util.ResourceBundle JavaDoc;
12 import java.util.Vector JavaDoc;
13
14 import javax.jms.QueueConnectionFactory JavaDoc;
15 import javax.jms.TopicConnectionFactory JavaDoc;
16 import javax.swing.JOptionPane JavaDoc;
17
18 import org.ejtools.beans.beancontext.CustomBeanContextServiceProvider;
19 import org.ejtools.jndi.browser.model.jms.ConnectionFactoryProxy;
20
21 /**
22  * Description of the Class
23  *
24  * @author letiemble
25  * @created 13 décembre 2001
26  * @version $Revision: 1.2 $
27  * @todo Javadoc to complete
28  * @todo Add log4j logs
29  * @todo int argument for selectFactory
30  */

31 public class JMSConnectionServiceProvider extends CustomBeanContextServiceProvider implements JMSConnectionService
32 {
33    /** Description of the Field */
34    protected int defaultQueueConnectionFactory = 0;
35    /** Description of the Field */
36    protected int defaultTopicConnectionFactory = 0;
37    /** Description of the Field */
38    protected Vector JavaDoc queueConnectionFactories = new Vector JavaDoc();
39    /** Description of the Field */
40    protected Vector JavaDoc topicConnectionFactories = new Vector JavaDoc();
41    /** Bundle for I18N */
42    private static ResourceBundle JavaDoc resources = ResourceBundle.getBundle("org.ejtools.jndi.browser.Resources");
43
44
45    /**
46     * Getter for the currentServiceSelectors attribute
47     *
48     * @param bcs Description of Parameter
49     * @param serviceClass Description of Parameter
50     * @return The value
51     */

52    public Iterator JavaDoc getCurrentServiceSelectors(BeanContextServices JavaDoc bcs, java.lang.Class JavaDoc serviceClass)
53    {
54       return (new Vector JavaDoc()).iterator();
55    }
56
57
58    /**
59     * Getter for the defaultQueueConnectionFactory attribute
60     *
61     * @return The value of defaultQueueConnectionFactory attribute
62     */

63    public QueueConnectionFactory JavaDoc 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    /**
82     * Getter for the defaultTopicConnectionFactory attribute
83     *
84     * @return The value of defaultTopicConnectionFactory attribute
85     */

86    public TopicConnectionFactory JavaDoc 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    /**
105     * Getter for the service attribute
106     *
107     * @param bcs Description of Parameter
108     * @param requestor Description of Parameter
109     * @param serviceClass Description of Parameter
110     * @param serviceSelector Description of Parameter
111     * @return The value
112     */

113    public Object JavaDoc getService(BeanContextServices JavaDoc bcs, java.lang.Object JavaDoc requestor, java.lang.Class JavaDoc serviceClass, java.lang.Object JavaDoc 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    /**
132     * Description of the Method
133     *
134     * @param bcs Description of Parameter
135     * @param requestor Description of Parameter
136     * @param service Description of Parameter
137     */

138    public void releaseService(BeanContextServices JavaDoc bcs, java.lang.Object JavaDoc requestor, java.lang.Object JavaDoc 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    /**
166     * Description of the Method
167     *
168     * @param type Description of the Parameter
169     */

170    public void selectFactory(String JavaDoc 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    /** Description of the Method */
184    public void selectQueueConnectionFactory()
185    {
186       if (queueConnectionFactories.size() > 0)
187       {
188          Object JavaDoc 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    /** Description of the Method */
215    public void selectTopicConnectionFactory()
216    {
217       if (topicConnectionFactories.size() > 0)
218       {
219          Object JavaDoc 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    /**
246     * @return The serviceClass value
247     */

248    protected Class JavaDoc[] getServiceClass()
249    {
250       return new Class JavaDoc[]{JMSConnectionService.class};
251    }
252 }
253
254
Popular Tags