EditContainerAction.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: EditContainerAction.java,v 1.12 2004/03/19 14:31:50 sauthieg Exp $
00023  * --------------------------------------------------------------------------
00024  */
00025 
00026 package org.objectweb.jonas.webapp.jonasadmin.service.container;
00027 
00028 import java.io.IOException;
00029 import java.util.ArrayList;
00030 import java.util.Collections;
00031 import java.util.Iterator;
00032 
00033 import javax.management.MalformedObjectNameException;
00034 import javax.management.ObjectName;
00035 import javax.servlet.ServletException;
00036 import javax.servlet.http.HttpServletRequest;
00037 import javax.servlet.http.HttpServletResponse;
00038 
00039 import org.apache.struts.action.ActionForm;
00040 import org.apache.struts.action.ActionForward;
00041 import org.apache.struts.action.ActionMapping;
00042 import org.objectweb.jonas.jmx.J2eeObjectName;
00043 import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
00044 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
00045 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
00046 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItem;
00047 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItemByNameComparator;
00048 
00053 public class EditContainerAction extends JonasBaseAction {
00054 
00055 // --------------------------------------------------------- Public Methods
00056 
00057     public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
00058         , HttpServletRequest p_Request, HttpServletResponse p_Response)
00059         throws IOException, ServletException {
00060         // Selected container
00061         String sObjectName = p_Request.getParameter("select");
00062         if (sObjectName == null) {
00063             // Accept request attribute forced by a EditEjbAction
00064             sObjectName = (String) p_Request.getAttribute("select");
00065         }
00066         // Get next forward if the access is throught a ejb else by default is null
00067         String sNextForward = (String) p_Request.getAttribute("NextForward");
00068 
00069         // Determine the ObjectName of the managed container (module)
00070         ObjectName oObjectName = null;
00071         try {
00072             if (sNextForward != null) {
00073                 oObjectName = getModuleObjectName(sObjectName);
00074             } else {
00075                 oObjectName = new ObjectName(sObjectName);
00076             }
00077         } catch (Throwable t) {
00078             addGlobalError(t);
00079             saveErrors(p_Request, m_Errors);
00080             return (p_Mapping.findForward("Global Error"));
00081         }
00082 
00083         // Form used
00084         ContainerForm oForm = null;
00085         String sPath = null;
00086         // Build a new form
00087         if (oObjectName != null) {
00088             oForm = new ContainerForm();
00089             oForm.reset(p_Mapping, p_Request);
00090             m_Session.setAttribute("containerForm", oForm);
00091             sPath = getStringAttribute(oObjectName, "fileName");
00092             
00093             oForm.setPath(sPath);
00094             oForm.setFilename(JonasAdminJmx.extractFilename(sPath));
00095         }
00096         else {
00097             // Used last form in session
00098             oForm = (ContainerForm) m_Session.getAttribute("containerForm");
00099         }
00100 
00101         // Force the node selected in tree only when no next forward
00102         if (sNextForward == null) {
00103             m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER)
00104                 + WhereAreYou.NODE_SEPARATOR + "services" + WhereAreYou.NODE_SEPARATOR
00105                 + "ejbContainers" + WhereAreYou.NODE_SEPARATOR + oForm.getFilename(), true);
00106         }
00107 
00108         // Populate
00109         if (oObjectName != null) {
00110             try {
00111                 oForm.setContainerName(getStringAttribute(oObjectName, "containerName"));
00112                 oForm.setCurrentNumberOfMDBType(getIntegerAttribute(oObjectName
00113                     , "currentNumberOfMDB"));
00114                 oForm.setCurrentNumberOfSBFType(getIntegerAttribute(oObjectName
00115                     , "currentNumberOfSBF"));
00116                 oForm.setCurrentNumberOfBMPType(getIntegerAttribute(oObjectName
00117                     , "currentNumberOfBMP"));
00118                 oForm.setCurrentNumberOfSBLType(getIntegerAttribute(oObjectName
00119                     , "currentNumberOfSBL"));
00120                 oForm.setCurrentNumberOfCMPType(getIntegerAttribute(oObjectName
00121                     , "currentNumberOfCMP"));
00122                 oForm.setCurrentNumberOfBeanType(getIntegerAttribute(oObjectName
00123                     , "currentNumberOfEJB"));
00124                 // Prepare Ejb list in this container
00125                 searchEjbs(oForm, sPath, oObjectName);
00126             }
00127             catch (Throwable t) {
00128                 addGlobalError(t);
00129                 saveErrors(p_Request, m_Errors);
00130                 return (p_Mapping.findForward("Global Error"));
00131             }
00132         }
00133 
00134         // Replace the normal forward if exists
00135         if (sNextForward == null) {
00136             sNextForward = "Container";
00137         }
00138         // Forward to the jsp
00139         return (p_Mapping.findForward(sNextForward));
00140     }
00141 
00142     protected void searchEjbs(ContainerForm p_Form, String p_Path, ObjectName p_ObjectName)
00143         throws Exception {
00144         String sName;
00145         String sTypeResource;
00146         Iterator itNames;
00147         ArrayList al = new ArrayList();
00148         String p_DomainName = p_ObjectName.getDomain();
00149         String p_ServerName = p_ObjectName.getKeyProperty("J2EEServer");
00150         String p_moduleName = p_ObjectName.getKeyProperty("name");
00151 
00152         ObjectName on = J2eeObjectName.getEntityBeans(p_DomainName, p_moduleName, p_ServerName);
00153         itNames = JonasAdminJmx.getListMbean(on).iterator();
00154         while (itNames.hasNext()) {
00155             al.add(new EjbItem((ObjectName) itNames.next()));
00156         }
00157         on = J2eeObjectName.getStatefulSessionBeans(p_DomainName, p_moduleName, p_ServerName);
00158         itNames = JonasAdminJmx.getListMbean(on).iterator();
00159         while (itNames.hasNext()) {
00160             al.add(new EjbItem((ObjectName) itNames.next()));
00161         }
00162         on = J2eeObjectName.getStatelessSessionBeans(p_DomainName, p_moduleName, p_ServerName);
00163         itNames = JonasAdminJmx.getListMbean(on).iterator();
00164         while (itNames.hasNext()) {
00165             al.add(new EjbItem((ObjectName) itNames.next()));
00166         } 
00167         on = J2eeObjectName.getMessageDrivenBeans(p_DomainName, p_moduleName, p_ServerName);
00168         itNames = JonasAdminJmx.getListMbean(on).iterator();
00169         while (itNames.hasNext()) {
00170             al.add(new EjbItem((ObjectName) itNames.next()));
00171         }
00172 
00173         // Sort by name
00174         Collections.sort(al, new EjbItemByNameComparator());
00175         // Save in form
00176         p_Form.setEjbs(al);
00177     }
00178 
00179     ObjectName getModuleObjectName(String ejbObjectName) throws MalformedObjectNameException {
00180         ObjectName o_ejbObjectName = new ObjectName(ejbObjectName);
00181         String domainName = o_ejbObjectName.getDomain();
00182         String moduleName = o_ejbObjectName.getKeyProperty("EJBModule");
00183         String serverName = o_ejbObjectName.getKeyProperty("J2EEServer");
00184         String appName = o_ejbObjectName.getKeyProperty("J2EEApplication");
00185         return J2eeObjectName.getEJBModule(domainName, serverName, appName, moduleName);
00186     }
00187 }

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