001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer(s): Michel-Ange ANTON
022: * --------------------------------------------------------------------------
023: * $Id: ListJmsResourcesAction.java 9680 2006-10-06 12:08:33Z danesa $
024: * --------------------------------------------------------------------------
025: */
026:
027: package org.objectweb.jonas.webapp.jonasadmin.resource;
028:
029: import java.io.IOException;
030: import java.util.ArrayList;
031: import java.util.Collections;
032: import java.util.Set;
033:
034: import javax.management.ObjectName;
035: import javax.servlet.ServletException;
036: import javax.servlet.http.HttpServletRequest;
037: import javax.servlet.http.HttpServletResponse;
038:
039: import org.apache.struts.action.ActionForm;
040: import org.apache.struts.action.ActionForward;
041: import org.apache.struts.action.ActionMapping;
042: import org.objectweb.jonas.jmx.JonasManagementRepr;
043: import org.objectweb.jonas.jmx.JonasObjectName;
044: import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
045: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
046:
047: /**
048: *
049: */
050:
051: public class ListJmsResourcesAction extends JonasBaseAction {
052:
053: // --------------------------------------------------------- Public Methods
054:
055: /**
056: */
057: public ActionForward executeAction(ActionMapping p_Mapping,
058: ActionForm p_Form, HttpServletRequest p_Request,
059: HttpServletResponse p_Response) throws IOException,
060: ServletException {
061:
062: try {
063:
064: // Current server
065: String serverName = m_WhereAreYou
066: .getCurrentJonasServerName();
067:
068: String asDestName = null;
069:
070: // Prepare access to ejbContainer service in order to chech dependences
071: ObjectName ejbServiceMB = JonasObjectName.ejbService();
072: boolean registeredEjbService = JonasManagementRepr
073: .isRegistered(ejbServiceMB, serverName);
074:
075: // Get queues
076: ArrayList alQueues = new ArrayList();
077: ArrayList al = JonasAdminJmx.getQueuesList(serverName);
078: if (al != null) {
079: for (int i = 0; i < al.size(); i++) {
080: asDestName = al.get(i).toString();
081: boolean deps = false;
082: // Chech dependences
083: if (registeredEjbService) {
084: deps = hasDeps(asDestName, ejbServiceMB,
085: serverName);
086: }
087: alQueues.add(new DestinationItem(asDestName,
088: "queue", deps));
089: }
090: Collections.sort(alQueues,
091: new DestinationItemByNameComparator());
092: }
093: // Get topics
094: ArrayList alTopics = new ArrayList();
095: al = JonasAdminJmx.getTopicsList(serverName);
096: if (al != null) {
097: for (int i = 0; i < al.size(); i++) {
098: asDestName = al.get(i).toString();
099: boolean deps = false;
100: // Chech dependences
101: if (registeredEjbService) {
102: deps = hasDeps(asDestName, ejbServiceMB,
103: serverName);
104: }
105: alTopics.add(new DestinationItem(al.get(i)
106: .toString(), "topic", deps));
107: }
108: Collections.sort(alTopics,
109: new DestinationItemByNameComparator());
110: }
111:
112: // merge alQueues and alTopics in alDestinations
113: ArrayList alDestinations = new ArrayList(alQueues);
114: alDestinations.addAll(alTopics);
115:
116: p_Request.setAttribute("destinationsList", alDestinations);
117: } catch (Throwable t) {
118: addGlobalError(t);
119: saveErrors(p_Request, m_Errors);
120: return (p_Mapping.findForward("Global Error"));
121: }
122:
123: // Forward to the jsp.
124: return (p_Mapping.findForward("Jms Resources"));
125: }
126:
127: private boolean hasDeps(String destName, ObjectName ejbServiceMB,
128: String serverName) {
129: String[] asParam = { destName };
130: String[] asSignature = { "java.lang.String" };
131: Set deps = (java.util.Set) JonasManagementRepr.invoke(
132: ejbServiceMB, "getJmsDestinationDependence", asParam,
133: asSignature, serverName);
134: boolean res = deps.size() > 0 ? true : false;
135: return res;
136: }
137: }
|