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: EditJvmAction.java 9680 2006-10-06 12:08:33Z danesa $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.webapp.jonasadmin.jonasserver;
025:
026: import java.io.IOException;
027:
028: import javax.management.MalformedObjectNameException;
029: import javax.management.ObjectName;
030: import javax.servlet.ServletException;
031: import javax.servlet.http.HttpServletRequest;
032: import javax.servlet.http.HttpServletResponse;
033:
034: import org.apache.struts.action.ActionMessage;
035: import org.apache.struts.action.ActionMessages;
036: import org.apache.struts.action.ActionForm;
037: import org.apache.struts.action.ActionForward;
038: import org.apache.struts.action.ActionMapping;
039: import org.objectweb.jonas.jmx.JonasManagementRepr;
040: import org.objectweb.jonas.jmx.JonasObjectName;
041: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
042:
043: /**
044: * @author Adriana DANES
045: */
046:
047: public class EditJvmAction extends JonasBaseAction {
048:
049: // --------------------------------------------------------- Public Methods
050:
051: /**
052: * Execute action for JVM management
053: * @param pMapping mapping info
054: * @param pForm form object
055: * @param pRequest HTTP request
056: * @param pResponse HTTP response
057: *
058: * @return An <code>ActionForward</code> instance or <code>null</code>
059: *
060: * @exception IOException if an input/output error occurs
061: * @exception ServletException if a servlet exception occurs
062: */
063: public ActionForward executeAction(ActionMapping pMapping,
064: ActionForm pForm, HttpServletRequest pRequest,
065: HttpServletResponse pResponse) throws IOException,
066: ServletException {
067: // Force the node selected in tree
068: m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER),
069: true);
070:
071: ActionMessages oErrors = new ActionMessages();
072:
073: // The MBean of current Jonas server
074: ObjectName onServer = m_WhereAreYou.getCurrentJonasServer();
075: String serverName = m_WhereAreYou.getCurrentJonasServerName();
076: // JVM MBean
077: ObjectName oObjectName = null;
078: // List of JVMs - in reality we have only one
079: String[] jvms = (String[]) JonasManagementRepr.getAttribute(
080: onServer, "javaVMs", serverName);
081: try {
082: if (jvms.length > 0) {
083: oObjectName = new ObjectName(jvms[0]);
084: } else {
085: oErrors.add("JVMs", new ActionMessage(
086: "error.server.jonas.jvms"));
087: saveErrors(pRequest, oErrors);
088: return (pMapping.findForward("Global Error"));
089: }
090: } catch (MalformedObjectNameException e) {
091: addGlobalError(e);
092: saveErrors(pRequest, m_Errors);
093: return (pMapping.findForward("Global Error"));
094: }
095:
096: // Form used
097: JvmForm oForm = (JvmForm) pForm;
098: try {
099: // Copy scalar properties
100: oForm.setJavaVendor(getStringAttribute(oObjectName,
101: "javaVendor"));
102: oForm.setJavaVersion(getStringAttribute(oObjectName,
103: "javaVersion"));
104: oForm.setNode(getStringAttribute(oObjectName, "node"));
105: if (JonasManagementRepr.isRegistered(JonasObjectName
106: .webContainerService(), serverName)) {
107: oForm.setPresentServletContainer(true);
108: } else {
109: oForm.setPresentServletContainer(false);
110: }
111: } catch (Throwable t) {
112: addGlobalError(t);
113: saveErrors(pRequest, m_Errors);
114: return (pMapping.findForward("Global Error"));
115: }
116:
117: // Forward to the jsp.
118: return (pMapping.findForward("Jvm"));
119: }
120:
121: }
|