ListWebContainersAction.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  * --------------------------------------------------------------------------
00022  * $Id: ListWebContainersAction.java,v 1.16 2004/03/25 15:58:20 sauthieg Exp $
00023  * --------------------------------------------------------------------------
00024  */
00025 
00026 package org.objectweb.jonas.webapp.jonasadmin.service.container;
00027 
00028 import java.io.IOException;
00029 import java.net.URL;
00030 import java.util.ArrayList;
00031 import java.util.Collections;
00032 import java.util.HashMap;
00033 import java.util.Iterator;
00034 
00035 import javax.management.ObjectName;
00036 import javax.servlet.ServletException;
00037 import javax.servlet.http.HttpServletRequest;
00038 import javax.servlet.http.HttpServletResponse;
00039 
00040 import org.apache.struts.action.ActionForm;
00041 import org.apache.struts.action.ActionForward;
00042 import org.apache.struts.action.ActionMapping;
00043 import org.objectweb.jonas.jmx.J2eeObjectName;
00044 import org.objectweb.jonas.jmx.JonasManagementRepr;
00045 import org.objectweb.jonas.jmx.JonasObjectName;
00046 import org.objectweb.jonas.webapp.jonasadmin.JettyObjectName;
00047 import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
00048 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
00049 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
00050 
00055 public class ListWebContainersAction extends JonasBaseAction {
00056 
00057 // --------------------------------------------------------- Public Methods
00058 
00059     public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
00060         , HttpServletRequest p_Request, HttpServletResponse p_Response)
00061         throws IOException, ServletException {
00062 
00063         // Force the node selected in tree
00064         m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER) + WhereAreYou.NODE_SEPARATOR
00065             + "services" + WhereAreYou.NODE_SEPARATOR + "web", true);
00066         // Force the deployment type to use the refreshing method
00067         m_WhereAreYou.setCurrentJonasDeploymentType(WhereAreYou.DEPLOYMENT_WAR);
00068         // Delete last list if used
00069         m_Session.removeAttribute("itemsWebContainersForm");
00070 
00071         // no Form used
00072         try {
00073             ArrayList al = new ArrayList();
00074             ObjectName on;
00075             String sPathContext;
00076             HashMap hWebAppItems = new HashMap();
00077 
00078             // Get the list of Catalina contexts
00079             if (m_WhereAreYou.isCatalinaServer() == true) {
00080                 WebAppItem oItem;
00081                 String p_domainName = m_WhereAreYou.getCurrentDomainName();
00082                 String p_serverName = m_WhereAreYou.getApplicationJonasServerName();
00083                 ObjectName onContainers = J2eeObjectName.getWebModules(p_domainName, p_serverName);
00084                 Iterator itOns = JonasAdminJmx.getListMbean(onContainers).iterator();
00085                 while (itOns.hasNext()) {
00086                         ObjectName onWebModule = (ObjectName) itOns.next();
00087                     oItem = new WebAppItem(onWebModule);
00088                     String webModulePath = ((URL) JonasManagementRepr.getAttribute(onWebModule, "warURL")).toString();
00089                     String sFile = JonasAdminJmx.extractFilename(webModulePath);
00090                     oItem.setFile(sFile);
00091                     oItem.setPath(webModulePath);
00092                     hWebAppItems.put(oItem.getPathContext(), oItem);
00093                 }
00094             }
00095             // Get the list of Jetty contexts
00096             else if (m_WhereAreYou.isJettyServer() == true) {
00097                 Iterator itOnContexts = JonasAdminJmx.getListMbean(JettyObjectName.jettyContexts()).
00098                     iterator();
00099                 while (itOnContexts.hasNext()) {
00100                     on = (ObjectName) itOnContexts.next();
00101                     sPathContext = on.getKeyProperty("context");
00102                     if (sPathContext != null) {
00103                         if (hWebAppItems.containsKey(sPathContext) == false) {
00104                             hWebAppItems.put(sPathContext, new WebAppItem(sPathContext, on.toString()));
00105                         }
00106                     }
00107                 }
00108 
00109                 // Get the list of JOnAS War
00110                 /* This code is only executed with Jetty because the transfere
00111                 * of management attributes from 'War' MBeans to JettyMBeans is 
00112                 * not done yet
00113                 */ 
00114                 String sPath;
00115                 String sFile;
00116                 WebAppItem oWeb;
00117                 Iterator itOnWars = JonasAdminJmx.getListMbean(JonasObjectName.allWars()).iterator();
00118                 while (itOnWars.hasNext()) {
00119                     on = (ObjectName) itOnWars.next();
00120                     sPath = on.getKeyProperty("fname");
00121                     sFile = JonasAdminJmx.extractFilename(sPath);
00122                     sPathContext = getStringAttribute(on, "ContextRoot");
00123                     if (sPathContext.charAt(0) != '/') {
00124                         sPathContext = "/" + sPathContext;
00125                     }
00126                     oWeb = (WebAppItem) hWebAppItems.get(sPathContext);
00127                     if (oWeb != null) {
00128                         oWeb.setFile(sFile);
00129                         oWeb.setPath(sPath);
00130                     }
00131                 }
00132             }
00133 
00134             // Prepare to display and sort
00135             al.addAll(hWebAppItems.values());
00136             Collections.sort(al, new WebAppItemByPathContext());
00137 
00138             // Set list in the request
00139             p_Request.setAttribute("listWebContainers", al);
00140         }
00141         catch (Throwable t) {
00142             addGlobalError(t);
00143             saveErrors(p_Request, m_Errors);
00144             return (p_Mapping.findForward("Global Error"));
00145         }
00146         // Forward to the jsp.
00147         return (p_Mapping.findForward("Web Containers"));
00148     }
00149 }

Generated on Tue Feb 15 15:05:31 2005 for JOnAS by  doxygen 1.3.9.1