001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2005 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: ApplyDomainDeployAction.java 9712 2006-10-10 13:42:20Z danesa $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.webapp.jonasadmin.deploy;
025:
026: import java.io.IOException;
027: import java.util.ArrayList;
028: import java.util.HashMap;
029: import java.util.Map;
030: import java.util.TreeMap;
031:
032: import javax.management.ObjectName;
033: import javax.servlet.ServletException;
034: import javax.servlet.http.HttpServletRequest;
035: import javax.servlet.http.HttpServletResponse;
036:
037: import org.apache.struts.action.ActionForm;
038: import org.apache.struts.action.ActionForward;
039: import org.apache.struts.action.ActionMapping;
040: import org.apache.struts.action.ActionMessage;
041:
042: /**
043: * @author Patrick Smith
044: * @author Gregory Lapouchnian
045: * @author Adriana Danes
046: */
047: public class ApplyDomainDeployAction extends BaseDeployAction {
048:
049: // --------------------------------------------------------- Public Methods
050:
051: /**
052: */
053: public ActionForward executeAction(ActionMapping p_Mapping,
054: ActionForm p_Form, HttpServletRequest p_Request,
055: HttpServletResponse p_Response) throws IOException,
056: ServletException {
057:
058: String sForwardDeploy = "Domain Deploy Confirm";
059: String sForwardUndeploy = "Domain Undeploy Confirm";
060: String sForward = null;
061:
062: // Form used
063: DomainDeployForm oForm = (DomainDeployForm) p_Form;
064: oForm.setDeploymentInProgress(false);
065: oForm.setDeploymentCompleted(false);
066:
067: try {
068:
069: // set the array lists of selected apps and targets based on
070: // the selections returned by struts
071: ArrayList appList = new ArrayList();
072: ArrayList targetList = new ArrayList();
073: ArrayList targetNamesList = new ArrayList();
074:
075: ArrayList allPossibleTargets = oForm.getListTargetNames();
076:
077: int clustIndex = 0;
078: boolean foundClust = false;
079: for (int i = 0; i < oForm.getTargetSelected().length; i++) {
080: //System.out.println(oForm.getTargetSelected()[i]);
081: String selectedTargetON = oForm.getTargetSelected()[i];
082: if (!targetList.contains(selectedTargetON)) {
083: targetList.add(selectedTargetON);
084: ObjectName selectedTargetOn = ObjectName
085: .getInstance(selectedTargetON);
086: String targetNameToPrint = selectedTargetOn
087: .getKeyProperty("name");
088: targetNamesList.add(targetNameToPrint);
089: }
090: }
091:
092: for (int i = 0; i < oForm.getDeploySelected().length; i++) {
093: appList.add(oForm.getDeploySelected()[i]);
094: }
095:
096: oForm.setListDeploy(appList);
097: oForm.setListTargetsSelected(targetList);
098: oForm.setListTargetSelectedNames(targetNamesList);
099:
100: // make sure that the action and the replacement option are transferred
101: // to the next action
102: oForm.setSelectedAction(oForm.getSelectedOption());
103: oForm.setReplacementOption(oForm.getReplaceOnTarget());
104:
105: // Fill up report with initial empty value for each application
106: Map blankReport = new TreeMap();
107: for (int i = 0; i < appList.size(); i++) {
108: HashMap appReport = new HashMap();
109: blankReport.put(appList.get(i), appReport);
110: }
111: oForm.setReports(blankReport);
112:
113: // at least one entry must be selected from the list of servers and
114: // from the list of applications
115: oForm.setConfirm(oForm.getDeploySelected().length > 0
116: && oForm.getTargetSelected().length > 0);
117:
118: if (!oForm.isConfirm()) {
119: m_Errors.add("error.domain.deploy.noselect",
120: new ActionMessage(
121: "error.domain.deploy.noselect"));
122: saveErrors(p_Request, m_Errors);
123: sForward = getForwardEdit();
124: }
125:
126: } catch (Throwable t) {
127: addGlobalError(t);
128: saveErrors(p_Request, m_Errors);
129: return (p_Mapping.findForward("Global Error"));
130: }
131:
132: if (oForm.getSelectedAction().equals(DomainDeployForm.UNDEPLOY)) {
133: sForward = sForwardUndeploy;
134: } else {
135: sForward = sForwardDeploy;
136: }
137: // Forward to the jsp.
138: return (p_Mapping.findForward(sForward));
139: }
140:
141: }
|