KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > jonasadmin > resource > ListJmsResourcesAction


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  * Initial developer(s): Michel-Ange ANTON
22  * --------------------------------------------------------------------------
23  * $Id: ListJmsResourcesAction.java,v 1.2 2004/03/19 14:31:47 sauthieg Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.webapp.jonasadmin.resource;
28
29 import java.io.IOException JavaDoc;
30 import java.util.ArrayList JavaDoc;
31 import java.util.Collections JavaDoc;
32 import java.util.Set JavaDoc;
33
34 import javax.management.ObjectName JavaDoc;
35 import javax.servlet.ServletException JavaDoc;
36 import javax.servlet.http.HttpServletRequest JavaDoc;
37 import javax.servlet.http.HttpServletResponse JavaDoc;
38
39 import org.apache.struts.action.ActionForm;
40 import org.apache.struts.action.ActionForward;
41 import org.apache.struts.action.ActionMapping;
42 import org.objectweb.jonas.jmx.JonasManagementRepr;
43 import org.objectweb.jonas.jmx.JonasObjectName;
44 import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
45 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
46
47 /**
48  *
49  */

50
51 public class ListJmsResourcesAction extends JonasBaseAction {
52
53 // --------------------------------------------------------- Public Methods
54

55     /**
56      */

57     public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
58         , HttpServletRequest JavaDoc p_Request, HttpServletResponse JavaDoc p_Response)
59         throws IOException JavaDoc, ServletException JavaDoc {
60
61         try {
62             String JavaDoc asDestName = null;
63
64             // Prepare access to ejbContainer service in order to chech dependences
65
ObjectName JavaDoc ejbServiceMB = JonasObjectName.ejbService();
66             boolean registeredEjbService = JonasManagementRepr.isRegistered(ejbServiceMB);
67
68             // Get queues
69
ArrayList JavaDoc alQueues = new ArrayList JavaDoc();
70             ArrayList JavaDoc al = JonasAdminJmx.getQueuesList();
71             if (al != null) {
72                 for (int i = 0; i < al.size(); i++) {
73                     asDestName = al.get(i).toString();
74                     boolean deps = false;
75                     // Chech dependences
76
if (registeredEjbService) {
77                         deps = hasDeps(asDestName, ejbServiceMB);
78                     }
79                     alQueues.add(new DestinationItem(asDestName, "queue", deps));
80                 }
81                 Collections.sort(alQueues, new DestinationItemByNameComparator());
82             }
83             // Get topics
84
ArrayList JavaDoc alTopics = new ArrayList JavaDoc();
85             al = JonasAdminJmx.getTopicsList();
86             if (al != null) {
87                 for (int i = 0; i < al.size(); i++) {
88                     asDestName = al.get(i).toString();
89                     boolean deps = false;
90                     // Chech dependences
91
if (registeredEjbService) {
92                         deps = hasDeps(asDestName, ejbServiceMB);
93                     }
94                     alTopics.add(new DestinationItem(al.get(i).toString(), "topic", deps));
95                 }
96                 Collections.sort(alTopics, new DestinationItemByNameComparator());
97             }
98
99             // merge alQueues and alTopics in alDestinations
100
ArrayList JavaDoc alDestinations = new ArrayList JavaDoc(alQueues);
101             alDestinations.addAll(alTopics);
102
103             p_Request.setAttribute("destinationsList", alDestinations);
104         } catch (Throwable JavaDoc t) {
105             addGlobalError(t);
106             saveErrors(p_Request, m_Errors);
107             return (p_Mapping.findForward("Global Error"));
108         }
109
110         // Forward to the jsp.
111
return (p_Mapping.findForward("Jms Resources"));
112     }
113
114     private boolean hasDeps(String JavaDoc destName, ObjectName JavaDoc ejbServiceMB) {
115         String JavaDoc[] asParam = { destName };
116         String JavaDoc[] asSignature = { "java.lang.String" };
117         Set JavaDoc deps = (java.util.Set JavaDoc) JonasManagementRepr.invoke(ejbServiceMB, "getJmsDestinationDependence", asParam, asSignature);
118         boolean res = deps.size() > 0 ? true : false;
119         return res;
120     }
121 }
122
Popular Tags