KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > jonasadmin > service > container > ListWebContainersAction


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: ListWebContainersAction.java,v 1.18 2005/07/22 13:57:15 kemlerp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.webapp.jonasadmin.service.container;
27
28 import java.io.IOException JavaDoc;
29 import java.net.URL JavaDoc;
30 import java.util.ArrayList JavaDoc;
31 import java.util.Collections JavaDoc;
32 import java.util.HashMap JavaDoc;
33 import java.util.Iterator JavaDoc;
34
35 import javax.management.ObjectName JavaDoc;
36 import javax.servlet.ServletException JavaDoc;
37 import javax.servlet.http.HttpServletRequest JavaDoc;
38 import javax.servlet.http.HttpServletResponse JavaDoc;
39
40 import org.apache.struts.action.ActionForm;
41 import org.apache.struts.action.ActionForward;
42 import org.apache.struts.action.ActionMapping;
43 import org.objectweb.jonas.jmx.J2eeObjectName;
44 import org.objectweb.jonas.jmx.JonasManagementRepr;
45 import org.objectweb.jonas.jmx.JonasObjectName;
46 import org.objectweb.jonas.webapp.jonasadmin.JettyObjectName;
47 import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
48 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
49 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
50
51 /**
52  * @author Michel-Ange ANTON
53  */

54
55 public class ListWebContainersAction extends JonasBaseAction {
56
57 // --------------------------------------------------------- Public Methods
58

59     public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
60         , HttpServletRequest JavaDoc p_Request, HttpServletResponse JavaDoc p_Response)
61         throws IOException JavaDoc, ServletException JavaDoc {
62
63         // Force the node selected in tree
64
m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER) + WhereAreYou.NODE_SEPARATOR
65             + "services" + WhereAreYou.NODE_SEPARATOR + "web", true);
66         // Force the deployment type to use the refreshing method
67
m_WhereAreYou.setCurrentJonasDeploymentType(WhereAreYou.DEPLOYMENT_WAR);
68         // Delete last list if used
69
m_Session.removeAttribute("itemsWebContainersForm");
70
71         // no Form used
72
try {
73             ArrayList JavaDoc al = new ArrayList JavaDoc();
74             ObjectName JavaDoc on;
75             String JavaDoc sPathContext;
76             HashMap JavaDoc hWebAppItems = new HashMap JavaDoc();
77
78             // Get the list of Catalina contexts
79
if (m_WhereAreYou.isCatalinaServer() == true) {
80                 WebAppItem oItem;
81                 String JavaDoc p_domainName = m_WhereAreYou.getCurrentDomainName();
82                 String JavaDoc p_serverName = m_WhereAreYou.getAdminJonasServerName();
83                 ObjectName JavaDoc onContainers = J2eeObjectName.getWebModules(p_domainName, p_serverName);
84                 Iterator JavaDoc itOns = JonasAdminJmx.getListMbean(onContainers).iterator();
85                 while (itOns.hasNext()) {
86                     ObjectName JavaDoc onWebModule = (ObjectName JavaDoc) itOns.next();
87                     oItem = new WebAppItem(onWebModule);
88                     String JavaDoc webModulePath = ((URL JavaDoc) JonasManagementRepr.getAttribute(onWebModule, "warURL")).toString();
89                     String JavaDoc sFile = JonasAdminJmx.extractFilename(webModulePath);
90                     oItem.setFile(sFile);
91                     oItem.setPath(webModulePath);
92                     hWebAppItems.put(oItem.getPathContext(), oItem);
93                 }
94             } else if (m_WhereAreYou.isJettyServer()) {
95                 // Get the list of Jetty contexts
96
Iterator JavaDoc itOnContexts = JonasAdminJmx.getListMbean(JettyObjectName.jettyContexts()).
97                     iterator();
98                 while (itOnContexts.hasNext()) {
99                     on = (ObjectName JavaDoc) itOnContexts.next();
100                     sPathContext = on.getKeyProperty("context");
101                     if (sPathContext != null) {
102                         if (!hWebAppItems.containsKey(sPathContext) && on.getKeyProperty("WebApplicationContext") != null &&
103                             on.getKeyProperty("WebApplicationHandler") == null && on.getKeyProperty("config") == null) {
104                             hWebAppItems.put(sPathContext, new WebAppItem(sPathContext, on.toString()));
105                         }
106                     }
107                 }
108
109                 // Get the list of JOnAS War
110
/* This code is only executed with Jetty because the transfere
111                 * of management attributes from 'War' MBeans to JettyMBeans is
112                 * not done yet
113                 */

114                 String JavaDoc sPath;
115                 String JavaDoc sFile;
116                 WebAppItem oWeb;
117                 Iterator JavaDoc itOnWars = JonasAdminJmx.getListMbean(JonasObjectName.allWars()).iterator();
118                 while (itOnWars.hasNext()) {
119                     on = (ObjectName JavaDoc) itOnWars.next();
120                     sPath = on.getKeyProperty("fname");
121                     sFile = JonasAdminJmx.extractFilename(sPath);
122                     sPathContext = getStringAttribute(on, "ContextRoot");
123                     if (sPathContext.charAt(0) != '/') {
124                         sPathContext = "/" + sPathContext;
125                     }
126                     oWeb = (WebAppItem) hWebAppItems.get(sPathContext);
127                     if (oWeb != null) {
128                         oWeb.setFile(sFile);
129                         oWeb.setPath(sPath);
130                     }
131                 }
132             }
133
134             // Prepare to display and sort
135
al.addAll(hWebAppItems.values());
136             Collections.sort(al, new WebAppItemByPathContext());
137
138             // Set list in the request
139
p_Request.setAttribute("listWebContainers", al);
140         } catch (Throwable JavaDoc t) {
141             addGlobalError(t);
142             saveErrors(p_Request, m_Errors);
143             return (p_Mapping.findForward("Global Error"));
144         }
145         // Forward to the jsp.
146
return (p_Mapping.findForward("Web Containers"));
147     }
148 }
149
Popular Tags