KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > jonasadmin > service > jms > PresentTopicAction


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: PresentTopicAction.java,v 1.4 2004/03/19 14:31:48 sauthieg Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.webapp.jonasadmin.service.jms;
27
28 import java.io.IOException JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.Collections JavaDoc;
31
32 import javax.management.ObjectName JavaDoc;
33 import javax.servlet.ServletException JavaDoc;
34 import javax.servlet.http.HttpServletRequest JavaDoc;
35 import javax.servlet.http.HttpServletResponse JavaDoc;
36
37 import org.apache.struts.action.ActionForm;
38 import org.apache.struts.action.ActionForward;
39 import org.apache.struts.action.ActionMapping;
40 import org.objectweb.jonas.jmx.JonasManagementRepr;
41 import org.objectweb.jonas.jmx.JonasObjectName;
42 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
43 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
44 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItem;
45 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItemByNameComparator;
46
47 /**
48  * Action presenting a given JMS Topic destination's attributes.
49  * @author Adriana Danes
50  */

51 public class PresentTopicAction extends JonasBaseAction {
52     /**
53      */

54     public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
55         , HttpServletRequest JavaDoc p_Request, HttpServletResponse JavaDoc p_Response)
56         throws IOException JavaDoc, ServletException JavaDoc {
57
58         // Selected Topic
59
String JavaDoc topicName = p_Request.getParameter("name");
60
61         // Form used
62
TopicForm oForm = null;
63         if (topicName != null) {
64             // Build a new form
65
oForm = new TopicForm();
66             oForm.reset(p_Mapping, p_Request);
67             m_Session.setAttribute("topicForm", oForm);
68             oForm.setName(topicName);
69         }
70         else {
71             // Used last form in session
72
oForm = (TopicForm) m_Session.getAttribute("topicForm");
73         }
74
75         // Force the node selected in tree
76
m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER) + WhereAreYou.NODE_SEPARATOR
77             + "services" + WhereAreYou.NODE_SEPARATOR + "jms" + WhereAreYou.NODE_SEPARATOR
78             + "topic" + WhereAreYou.NODE_SEPARATOR + oForm.getName(), true);
79
80         // Populuate
81
try {
82             if (topicName != null) {
83                 ArrayList JavaDoc al = new ArrayList JavaDoc();
84                 String JavaDoc[] asParam = new String JavaDoc[1];
85                 String JavaDoc[] asSignature = new String JavaDoc[1];
86                 asSignature[0] = "java.lang.String";
87                 asParam[0] = topicName;
88                 ObjectName JavaDoc ejbServiceMB = JonasObjectName.ejbService();
89                 if (JonasManagementRepr.isRegistered(ejbServiceMB)) {
90                     java.util.Iterator JavaDoc it = ((java.util.Set JavaDoc) JonasManagementRepr.invoke(
91                         ejbServiceMB, "getJmsDestinationDependence", asParam
92                         , asSignature)).iterator();
93                     while (it.hasNext()) {
94                         al.add(new EjbItem((ObjectName JavaDoc) it.next()));
95                     }
96                     // Sort by name
97
Collections.sort(al, new EjbItemByNameComparator());
98                 }
99                 // Set list in form
100
oForm.setListUsedByEjb(al);
101
102                 // Set monitoting info
103
ObjectName JavaDoc jmsServiceMB = JonasObjectName.jmsService();
104                 int subscriptions = ((Integer JavaDoc) JonasManagementRepr.invoke(jmsServiceMB
105                     , "getSubscriptions", asParam, asSignature)).intValue();
106                 oForm.setSubscriptions(subscriptions);
107             }
108         }
109         catch (Throwable JavaDoc t) {
110             addGlobalError(t);
111             saveErrors(p_Request, m_Errors);
112             return (p_Mapping.findForward("Global Error"));
113         }
114
115         // Forward to the jsp.
116
return (p_Mapping.findForward("Topic"));
117     }
118 }
119
Popular Tags