View Javadoc

1   /***
2    * Redistribution and use of this software and associated documentation
3    * ("Software"), with or without modification, are permitted provided
4    * that the following conditions are met:
5    *
6    * 1. Redistributions of source code must retain copyright
7    *    statements and notices.  Redistributions must also contain a
8    *    copy of this document.
9    *
10   * 2. Redistributions in binary form must reproduce the
11   *    above copyright notice, this list of conditions and the
12   *    following disclaimer in the documentation and/or other
13   *    materials provided with the distribution.
14   *
15   * 3. The name "Exolab" must not be used to endorse or promote
16   *    products derived from this Software without prior written
17   *    permission of Exoffice Technologies.  For written permission,
18   *    please contact info@exolab.org.
19   *
20   * 4. Products derived from this Software may not be called "Exolab"
21   *    nor may "Exolab" appear in their names without prior written
22   *    permission of Exoffice Technologies. Exolab is a registered
23   *    trademark of Exoffice Technologies.
24   *
25   * 5. Due credit should be given to the Exolab Project
26   *    (http://www.exolab.org/).
27   *
28   * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
32   * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39   * OF THE POSSIBILITY OF SUCH DAMAGE.
40   *
41   * Copyright 2001,2003 (C) Exoffice Technologies Inc. All Rights Reserved.
42   *
43   * $Id: OpenJMSTopic.java,v 1.1 2004/11/26 01:51:15 tanderson Exp $
44   *
45   * Date         Author  Changes
46   * $Date	    jimm    Created
47   */
48  
49  
50  package org.exolab.jms.tools.admin;
51  
52  import java.awt.event.ActionEvent;
53  import java.awt.event.ActionListener;
54  import java.util.Enumeration;
55  
56  import javax.swing.JMenuItem;
57  import javax.swing.JOptionPane;
58  import javax.swing.JPopupMenu;
59  import javax.swing.JTree;
60  
61  
62  /***
63   * Extends the OpenJMSDestination node and defines a topic specific node
64   *
65   * @version     $Revision: 1.1 $ $Date: 2004/11/26 01:51:15 $
66   * @author      <a href="mailto:mourikis@exolab.org">Jim Mourikis</a>
67   * @see         OpenJMSObject
68   */
69  public class OpenJMSTopic extends OpenJMSObject {
70  
71      /***
72       * Construct a node with the specified topic name and the a reference
73       * to the parent node in the tree.
74       *
75       * @param name This topic name
76       * @param tree The parent tree that this node will belong too
77       */
78      public OpenJMSTopic(String topic, JTree tree) {
79          super(topic, tree);
80      }
81  
82      // implementation of OpenJMSDestination.createCommands
83      protected void createCommands() {
84          _commands = new JPopupMenu();
85          JMenuItem m = new JMenuItem("Add Consumer");
86          m.addActionListener(new ActionListener() {
87  
88              public void actionPerformed(ActionEvent evt) {
89                  addConsumer();
90              }
91          }
92          );
93          _commands.add(m);
94  
95          m = new JMenuItem("Delete Topic");
96          m.addActionListener(new ActionListener() {
97  
98              public void actionPerformed(ActionEvent evt) {
99                  deleteTopic();
100             }
101         }
102         );
103         _commands.add(m);
104     }
105 
106     /***
107      * The edit queue/topic option has been selected.
108      * Not currently implemented.
109      *
110      */
111     static private void editTopic() {
112         OpenJMSTopic This = (OpenJMSTopic) getInstanceSelected();
113         System.out.println("editTopic");
114     }
115 
116     /***
117      * As a performance enhancement, no consumer is added to a topic
118      * node until a request is made to expand the node, or a new consumer
119      * is to be added to the node. This metgod is then called to fetch
120      * all consumers from the database, and display the as children of
121      * this node.
122      *
123      */
124     public void update() {
125         if (!_isExplored) {
126             Enumeration e = AbstractAdminConnection.instance().getDurableConsumers(
127                 _name);
128 
129             if (e != null) {
130                 while (e.hasMoreElements()) {
131                     String consumer = (String) e.nextElement();
132                     add(new OpenJMSConsumer(consumer, _tree));
133                 }
134                 refresh();
135             }
136 
137             _isExplored = true;
138         }
139     }
140 
141     /***
142      * A new consumer is being added for this queue/topic. Popup a consumer
143      * add dialog, to collect relevent information, then update the database.
144      * If the database update is successful, add the consumer node as a child
145      * of this queue/topic node, and refresh.
146      *
147      */
148     static private void addConsumer() {
149 
150         OpenJMSTopic This = (OpenJMSTopic) getInstanceSelected();
151         CreateTopicDialog.instance().displayCreateConsumer();
152         if (CreateTopicDialog.instance().isConfirmed()) {
153             boolean err = false;
154             String errMessage = null;
155 
156             if (!This._isExplored) {
157                 This.update();
158             }
159 
160             // First check to see that the durable consumer does not already
161             // exist. If it does then display an error. If the durable
162             // consumer does not exist then create it.
163             if (!AbstractAdminConnection.instance().durableConsumerExists(
164                 CreateTopicDialog.instance().getName())) {
165                 if (AbstractAdminConnection.instance().addDurableConsumer(
166                     This._name, CreateTopicDialog.instance().getName())) {
167                     This.add(new OpenJMSConsumer
168                         (CreateTopicDialog.instance().getName(), _tree));
169                     This.refresh();
170                 } else {
171                     err = true;
172                     errMessage = "Failed to update database";
173                 }
174             } else {
175                 err = true;
176                 errMessage = "Consumer already exists";
177             }
178             if (err) {
179                 JOptionPane.showMessageDialog
180                     (_tree, errMessage, "Create Consumer Error",
181                         JOptionPane.ERROR_MESSAGE);
182             }
183         }
184     }
185 
186     /***
187      * Delete the selected topic object. Display a confirmation dialog
188      * and wait for its return. If the user has confirmed the action, first
189      * delete it from the database and if that is successful remove the node
190      * from the tree.
191      *
192      * <P>Note: deleting a queue/topic also deletes all consumers of this
193      * queue/topic.
194      *
195      */
196     static private void deleteTopic() {
197         OpenJMSTopic This = (OpenJMSTopic) getInstanceSelected();
198         QueryDialog.instance().display(
199             "Are you sure you want to delete \nselected Topic: "
200             + This._name);
201         if (org.exolab.jms.tools.admin.QueryDialog.instance().isConfirmed()) {
202             if (AbstractAdminConnection.instance().removeDestination(
203                 This._name)) {
204                 This.removeFromParent();
205                 This.refresh();
206             } else {
207                 JOptionPane.showMessageDialog
208                     (_tree, "Failed to destroy Topic",
209                         "Destroy Topic Error", JOptionPane.ERROR_MESSAGE);
210             }
211         }
212     }
213 }