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: */package org.objectweb.jonas.webapp.jonasadmin.joramplatform;
021:
022: import java.util.ArrayList;
023: import java.util.Iterator;
024: import java.util.List;
025: import java.util.Set;
026:
027: import javax.management.InstanceNotFoundException;
028: import javax.management.ObjectName;
029: import javax.servlet.http.HttpServletRequest;
030: import javax.servlet.http.HttpServletResponse;
031:
032: import org.apache.struts.action.ActionForm;
033: import org.apache.struts.action.ActionForward;
034: import org.apache.struts.action.ActionMapping;
035: import org.objectweb.jonas.jmx.JonasManagementRepr;
036: import org.objectweb.jonas.jmx.JoramObjectName;
037: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
038:
039: /**
040: * @author Frederic MAISTRE
041: */
042:
043: public class EditJoramPlatformAction extends EditJoramBaseAction {
044:
045: // --------------------------------------------------------- Public Methods
046:
047: public ActionForward executeAction(ActionMapping pMapping,
048: ActionForm pForm, HttpServletRequest pRequest,
049: HttpServletResponse pResponse) {
050:
051: // Current JOnAS server
052: String jonasServerName = m_WhereAreYou
053: .getCurrentJonasServerName();
054:
055: // Force the node selected in tree
056: m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_DOMAIN)
057: + WhereAreYou.NODE_SEPARATOR + "joramplatform", true);
058:
059: // Form used
060: JoramPlatformForm oForm = new JoramPlatformForm();
061: try {
062: // Object name used
063: ObjectName joramPlatformON = JoramObjectName
064: .joramPlatform();
065: Set adapterOns = JonasManagementRepr.queryNames(
066: JoramObjectName.joramAdapter(), jonasServerName);
067: if (adapterOns.isEmpty()) {
068: throw new InstanceNotFoundException();
069: }
070: ObjectName joramAdapterON = (ObjectName) adapterOns
071: .iterator().next();
072: boolean isAdapterLoaded = JonasManagementRepr.isRegistered(
073: joramAdapterON, jonasServerName);
074: Integer localServerIdValue = (Integer) JonasManagementRepr
075: .getAttribute(joramPlatformON, "LocalServerId",
076: jonasServerName);
077: Iterator serverIdsList = ((List) JonasManagementRepr
078: .getAttribute(joramPlatformON, "ServersIds",
079: jonasServerName)).iterator();
080: ArrayList serverIds = new ArrayList();
081: int nbRemoteServers = 0;
082: for (; serverIdsList.hasNext();) {
083: Integer serverIdValue = (Integer) serverIdsList.next();
084: if (!serverIdValue.equals(localServerIdValue)) {
085: serverIds.add(serverIdValue.toString());
086: nbRemoteServers++;
087: }
088: }
089: oForm.setAdapterLoaded(isAdapterLoaded);
090: oForm.setLocalServer(localServerIdValue.toString());
091: String[] remoteServers = new String[nbRemoteServers];
092: for (int i = 0; i < nbRemoteServers; i++) {
093: remoteServers[i] = (String) serverIds.get(i);
094: }
095: oForm.setRemoteServers(remoteServers);
096: oForm.setConfiguration((String) JonasManagementRepr
097: .getAttribute(joramPlatformON, "Configuration",
098: jonasServerName));
099: oForm.setLocalPort(getIntegerAttribute(joramPlatformON,
100: "LocalPort"));
101: oForm.setLocalHost(getStringAttribute(joramPlatformON,
102: "LocalHost"));
103: oForm.setDefaultThreshold(getIntegerAttribute(
104: joramPlatformON, "DefaultThreshold"));
105: if (isAdapterLoaded) {
106: // Get configuration info from RA
107: oForm.setVersion(joramAdapterON
108: .getKeyProperty("version"));
109: oForm.setCollocatedServer(getBooleanAttribute(
110: joramAdapterON, "CollocatedServer"));
111: oForm.setConfigDir(getStringAttribute(joramAdapterON,
112: "PlatformConfigDir"));
113: oForm.setAdminFile(getStringAttribute(joramAdapterON,
114: "AdminFileXML"));
115: oForm.setPersistentServer(getBooleanAttribute(
116: joramAdapterON, "PersistentPlatform"));
117: oForm.setServerIdTxt(toStringShortAttribute(
118: joramAdapterON, "ServerId"));
119: oForm.setServerName(getStringAttribute(joramAdapterON,
120: "ServerName"));
121: oForm.setHostName(getStringAttribute(joramAdapterON,
122: "HostName"));
123: oForm.setServerPortTxt(toStringIntegerAttribute(
124: joramAdapterON, "ServerPort"));
125: oForm.setCnxPendingTimerTxt(toStringIntegerAttribute(
126: joramAdapterON, "CnxPendingTimer"));
127: oForm.setConnectingTimerTxt(toStringIntegerAttribute(
128: joramAdapterON, "ConnectingTimer"));
129: oForm.setTxPendingTimerTxt(toStringIntegerAttribute(
130: joramAdapterON, "TxPendingTimer"));
131: oForm.setTimeOutToAbortRequest(getLongAttribute(
132: joramAdapterON, "TimeOutToAbortRequest"));
133: Object defaultDMQinstance = JonasManagementRepr
134: .getAttribute(joramAdapterON, "DefaultDMQ",
135: jonasServerName);
136: if (defaultDMQinstance != null) {
137: oForm.setDefaultDMQ(defaultDMQinstance.toString());
138: }
139: } else {
140: ObjectName joramAdminON = JoramObjectName.joramAdmin();
141: oForm.setTimeOutToAbortRequest(getLongAttribute(
142: joramAdminON, "TimeOutToAbortRequest"));
143: oForm.setDefaultDMQ(JonasManagementRepr.getAttribute(
144: joramAdminON, "DefaultDMQ", jonasServerName)
145: .toString());
146: }
147: m_Session.setAttribute("joramPlatformForm", oForm);
148: m_Session.setAttribute("localId", oForm.getLocalServer());
149: } catch (Throwable t) {
150: return (treatError(t, pMapping, pRequest));
151: }
152:
153: // Forward to the jsp.
154: return (pMapping.findForward("JoramPlatform"));
155: }
156:
157: }
|