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: * --------------------------------------------------------------------------
022: * $Id: EditContainerAction.java 9680 2006-10-06 12:08:33Z danesa $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.webapp.jonasadmin.service.container;
027:
028: import java.io.IOException;
029: import java.net.URL;
030: import java.util.ArrayList;
031: import java.util.Collections;
032: import java.util.Iterator;
033:
034: import javax.management.MalformedObjectNameException;
035: import javax.management.ObjectName;
036: import javax.servlet.ServletException;
037: import javax.servlet.http.HttpServletRequest;
038: import javax.servlet.http.HttpServletResponse;
039:
040: import org.apache.struts.action.ActionForm;
041: import org.apache.struts.action.ActionForward;
042: import org.apache.struts.action.ActionMapping;
043: import org.objectweb.jonas.jmx.J2eeObjectName;
044: import org.objectweb.jonas.jmx.JonasManagementRepr;
045: import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
046: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
047: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
048: import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItem;
049: import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItemByNameComparator;
050:
051: /**
052: * @author Michel-Ange ANTON
053: */
054:
055: public class EditContainerAction extends JonasBaseAction {
056:
057: // --------------------------------------------------------- Public Methods
058:
059: public ActionForward executeAction(ActionMapping p_Mapping,
060: ActionForm p_Form, HttpServletRequest p_Request,
061: HttpServletResponse p_Response) throws IOException,
062: ServletException {
063:
064: // Current server
065: WhereAreYou oWhere = (WhereAreYou) p_Request.getSession()
066: .getAttribute(WhereAreYou.SESSION_NAME);
067: String serverName = oWhere.getCurrentJonasServerName();
068:
069: // Selected container
070: String sObjectName = p_Request.getParameter("select");
071: if (sObjectName == null) {
072: // Accept request attribute forced by a EditEjbAction
073: sObjectName = (String) p_Request.getAttribute("select");
074: }
075: // Get next forward if the access is throught a ejb else by default is null
076: String sNextForward = (String) p_Request
077: .getAttribute("NextForward");
078:
079: // Determine the ObjectName of the managed container (module)
080: ObjectName oObjectName = null;
081: try {
082: if (sNextForward != null) {
083: oObjectName = getModuleObjectName(sObjectName);
084: } else {
085: oObjectName = new ObjectName(sObjectName);
086: }
087: } catch (Throwable t) {
088: addGlobalError(t);
089: saveErrors(p_Request, m_Errors);
090: return (p_Mapping.findForward("Global Error"));
091: }
092:
093: // Form used
094: ContainerForm oForm = null;
095: String sPath = null;
096: // Build a new form
097: if (oObjectName != null) {
098: oForm = new ContainerForm();
099: oForm.reset(p_Mapping, p_Request);
100: m_Session.setAttribute("containerForm", oForm);
101: sPath = getStringAttribute(oObjectName, "fileName");
102:
103: oForm.setPath(sPath);
104: oForm.setFilename(JonasAdminJmx.extractFilename(sPath));
105:
106: oForm
107: .setInEar(getBooleanAttribute(oObjectName,
108: "inEarCase"));
109: oForm.setEarPath((URL) JonasManagementRepr.getAttribute(
110: oObjectName, "earURL", serverName));
111: oForm.setEarON((String) JonasManagementRepr.getAttribute(
112: oObjectName, "earON", serverName));
113: } else {
114: // Used last form in session
115: oForm = (ContainerForm) m_Session
116: .getAttribute("containerForm");
117: }
118:
119: // Force the node selected in tree only when no next forward
120: if (sNextForward == null) {
121: m_WhereAreYou.selectNameNode(
122: getTreeBranchName(DEPTH_SERVER)
123: + WhereAreYou.NODE_SEPARATOR + "services"
124: + WhereAreYou.NODE_SEPARATOR
125: + "ejbContainers"
126: + WhereAreYou.NODE_SEPARATOR
127: + oForm.getFilename(), true);
128: }
129:
130: // Populate
131: if (oObjectName != null) {
132: try {
133: oForm.setContainerName(getStringAttribute(oObjectName,
134: "containerName"));
135: oForm.setCurrentNumberOfMDBType(getIntegerAttribute(
136: oObjectName, "currentNumberOfMDB"));
137: oForm.setCurrentNumberOfSBFType(getIntegerAttribute(
138: oObjectName, "currentNumberOfSBF"));
139: oForm.setCurrentNumberOfBMPType(getIntegerAttribute(
140: oObjectName, "currentNumberOfBMP"));
141: oForm.setCurrentNumberOfSBLType(getIntegerAttribute(
142: oObjectName, "currentNumberOfSBL"));
143: oForm.setCurrentNumberOfCMPType(getIntegerAttribute(
144: oObjectName, "currentNumberOfCMP"));
145: oForm.setCurrentNumberOfBeanType(getIntegerAttribute(
146: oObjectName, "currentNumberOfEJB"));
147: // Prepare Ejb list in this container
148: searchEjbs(oForm, sPath, oObjectName, serverName);
149: } catch (Throwable t) {
150: addGlobalError(t);
151: saveErrors(p_Request, m_Errors);
152: return (p_Mapping.findForward("Global Error"));
153: }
154: }
155:
156: // Replace the normal forward if exists
157: if (sNextForward == null) {
158: sNextForward = "Container";
159: }
160: // Forward to the jsp
161: return (p_Mapping.findForward(sNextForward));
162: }
163:
164: protected void searchEjbs(ContainerForm p_Form, String p_Path,
165: ObjectName p_ObjectName, String serverName)
166: throws Exception {
167: String sName;
168: String sTypeResource;
169: Iterator itNames;
170: ArrayList al = new ArrayList();
171: String p_DomainName = p_ObjectName.getDomain();
172: String p_ServerName = p_ObjectName.getKeyProperty("J2EEServer");
173: String p_moduleName = p_ObjectName.getKeyProperty("name");
174:
175: ObjectName on = J2eeObjectName.getEntityBeans(p_DomainName,
176: p_moduleName, p_ServerName);
177: itNames = JonasAdminJmx.getListMbean(on, serverName).iterator();
178: while (itNames.hasNext()) {
179: al.add(new EjbItem((ObjectName) itNames.next(),
180: p_ServerName));
181: }
182: on = J2eeObjectName.getStatefulSessionBeans(p_DomainName,
183: p_moduleName, p_ServerName);
184: itNames = JonasAdminJmx.getListMbean(on, serverName).iterator();
185: while (itNames.hasNext()) {
186: al.add(new EjbItem((ObjectName) itNames.next(),
187: p_ServerName));
188: }
189: on = J2eeObjectName.getStatelessSessionBeans(p_DomainName,
190: p_moduleName, p_ServerName);
191: itNames = JonasAdminJmx.getListMbean(on, serverName).iterator();
192: while (itNames.hasNext()) {
193: al.add(new EjbItem((ObjectName) itNames.next(),
194: p_ServerName));
195: }
196: on = J2eeObjectName.getMessageDrivenBeans(p_DomainName,
197: p_moduleName, p_ServerName);
198: itNames = JonasAdminJmx.getListMbean(on, serverName).iterator();
199: while (itNames.hasNext()) {
200: al.add(new EjbItem((ObjectName) itNames.next(),
201: p_ServerName));
202: }
203:
204: // Sort by name
205: Collections.sort(al, new EjbItemByNameComparator());
206: // Save in form
207: p_Form.setEjbs(al);
208: }
209:
210: ObjectName getModuleObjectName(String ejbObjectName)
211: throws MalformedObjectNameException {
212: ObjectName o_ejbObjectName = new ObjectName(ejbObjectName);
213: String domainName = o_ejbObjectName.getDomain();
214: String moduleName = o_ejbObjectName.getKeyProperty("EJBModule");
215: String serverName = o_ejbObjectName
216: .getKeyProperty("J2EEServer");
217: String appName = o_ejbObjectName
218: .getKeyProperty("J2EEApplication");
219: return J2eeObjectName.getEJBModule(domainName, serverName,
220: appName, moduleName);
221: }
222: }
|