KickJava   Java API By Example, From Geeks To Geeks.

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


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: EditContainerAction.java,v 1.12 2004/03/19 14:31:50 sauthieg Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.webapp.jonasadmin.service.container;
27
28 import java.io.IOException JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.Collections JavaDoc;
31 import java.util.Iterator JavaDoc;
32
33 import javax.management.MalformedObjectNameException JavaDoc;
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.J2eeObjectName;
43 import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
44 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
45 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
46 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItem;
47 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItemByNameComparator;
48
49 /**
50  * @author Michel-Ange ANTON
51  */

52
53 public class EditContainerAction extends JonasBaseAction {
54
55 // --------------------------------------------------------- Public Methods
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         // Selected container
61
String JavaDoc sObjectName = p_Request.getParameter("select");
62         if (sObjectName == null) {
63             // Accept request attribute forced by a EditEjbAction
64
sObjectName = (String JavaDoc) p_Request.getAttribute("select");
65         }
66         // Get next forward if the access is throught a ejb else by default is null
67
String JavaDoc sNextForward = (String JavaDoc) p_Request.getAttribute("NextForward");
68
69         // Determine the ObjectName of the managed container (module)
70
ObjectName JavaDoc oObjectName = null;
71         try {
72             if (sNextForward != null) {
73                 oObjectName = getModuleObjectName(sObjectName);
74             } else {
75                 oObjectName = new ObjectName JavaDoc(sObjectName);
76             }
77         } catch (Throwable JavaDoc t) {
78             addGlobalError(t);
79             saveErrors(p_Request, m_Errors);
80             return (p_Mapping.findForward("Global Error"));
81         }
82
83         // Form used
84
ContainerForm oForm = null;
85         String JavaDoc sPath = null;
86         // Build a new form
87
if (oObjectName != null) {
88             oForm = new ContainerForm();
89             oForm.reset(p_Mapping, p_Request);
90             m_Session.setAttribute("containerForm", oForm);
91             sPath = getStringAttribute(oObjectName, "fileName");
92             
93             oForm.setPath(sPath);
94             oForm.setFilename(JonasAdminJmx.extractFilename(sPath));
95         }
96         else {
97             // Used last form in session
98
oForm = (ContainerForm) m_Session.getAttribute("containerForm");
99         }
100
101         // Force the node selected in tree only when no next forward
102
if (sNextForward == null) {
103             m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER)
104                 + WhereAreYou.NODE_SEPARATOR + "services" + WhereAreYou.NODE_SEPARATOR
105                 + "ejbContainers" + WhereAreYou.NODE_SEPARATOR + oForm.getFilename(), true);
106         }
107
108         // Populate
109
if (oObjectName != null) {
110             try {
111                 oForm.setContainerName(getStringAttribute(oObjectName, "containerName"));
112                 oForm.setCurrentNumberOfMDBType(getIntegerAttribute(oObjectName
113                     , "currentNumberOfMDB"));
114                 oForm.setCurrentNumberOfSBFType(getIntegerAttribute(oObjectName
115                     , "currentNumberOfSBF"));
116                 oForm.setCurrentNumberOfBMPType(getIntegerAttribute(oObjectName
117                     , "currentNumberOfBMP"));
118                 oForm.setCurrentNumberOfSBLType(getIntegerAttribute(oObjectName
119                     , "currentNumberOfSBL"));
120                 oForm.setCurrentNumberOfCMPType(getIntegerAttribute(oObjectName
121                     , "currentNumberOfCMP"));
122                 oForm.setCurrentNumberOfBeanType(getIntegerAttribute(oObjectName
123                     , "currentNumberOfEJB"));
124                 // Prepare Ejb list in this container
125
searchEjbs(oForm, sPath, oObjectName);
126             }
127             catch (Throwable JavaDoc t) {
128                 addGlobalError(t);
129                 saveErrors(p_Request, m_Errors);
130                 return (p_Mapping.findForward("Global Error"));
131             }
132         }
133
134         // Replace the normal forward if exists
135
if (sNextForward == null) {
136             sNextForward = "Container";
137         }
138         // Forward to the jsp
139
return (p_Mapping.findForward(sNextForward));
140     }
141
142     protected void searchEjbs(ContainerForm p_Form, String JavaDoc p_Path, ObjectName JavaDoc p_ObjectName)
143         throws Exception JavaDoc {
144         String JavaDoc sName;
145         String JavaDoc sTypeResource;
146         Iterator JavaDoc itNames;
147         ArrayList JavaDoc al = new ArrayList JavaDoc();
148         String JavaDoc p_DomainName = p_ObjectName.getDomain();
149         String JavaDoc p_ServerName = p_ObjectName.getKeyProperty("J2EEServer");
150         String JavaDoc p_moduleName = p_ObjectName.getKeyProperty("name");
151
152         ObjectName JavaDoc on = J2eeObjectName.getEntityBeans(p_DomainName, p_moduleName, p_ServerName);
153         itNames = JonasAdminJmx.getListMbean(on).iterator();
154         while (itNames.hasNext()) {
155             al.add(new EjbItem((ObjectName JavaDoc) itNames.next()));
156         }
157         on = J2eeObjectName.getStatefulSessionBeans(p_DomainName, p_moduleName, p_ServerName);
158         itNames = JonasAdminJmx.getListMbean(on).iterator();
159         while (itNames.hasNext()) {
160             al.add(new EjbItem((ObjectName JavaDoc) itNames.next()));
161         }
162         on = J2eeObjectName.getStatelessSessionBeans(p_DomainName, p_moduleName, p_ServerName);
163         itNames = JonasAdminJmx.getListMbean(on).iterator();
164         while (itNames.hasNext()) {
165             al.add(new EjbItem((ObjectName JavaDoc) itNames.next()));
166         }
167         on = J2eeObjectName.getMessageDrivenBeans(p_DomainName, p_moduleName, p_ServerName);
168         itNames = JonasAdminJmx.getListMbean(on).iterator();
169         while (itNames.hasNext()) {
170             al.add(new EjbItem((ObjectName JavaDoc) itNames.next()));
171         }
172
173         // Sort by name
174
Collections.sort(al, new EjbItemByNameComparator());
175         // Save in form
176
p_Form.setEjbs(al);
177     }
178
179     ObjectName JavaDoc getModuleObjectName(String JavaDoc ejbObjectName) throws MalformedObjectNameException JavaDoc {
180         ObjectName JavaDoc o_ejbObjectName = new ObjectName JavaDoc(ejbObjectName);
181         String JavaDoc domainName = o_ejbObjectName.getDomain();
182         String JavaDoc moduleName = o_ejbObjectName.getKeyProperty("EJBModule");
183         String JavaDoc serverName = o_ejbObjectName.getKeyProperty("J2EEServer");
184         String JavaDoc appName = o_ejbObjectName.getKeyProperty("J2EEApplication");
185         return J2eeObjectName.getEJBModule(domainName, serverName, appName, moduleName);
186     }
187 }
188
Popular Tags