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.io.IOException;
023: import java.util.ArrayList;
024: import java.util.Collections;
025: import java.util.Iterator;
026: import java.util.List;
027: import java.util.Set;
028:
029: import javax.management.InstanceNotFoundException;
030: import javax.management.ObjectName;
031: import javax.servlet.ServletException;
032: import javax.servlet.http.HttpServletRequest;
033: import javax.servlet.http.HttpServletResponse;
034:
035: import org.apache.struts.action.ActionForm;
036: import org.apache.struts.action.ActionForward;
037: import org.apache.struts.action.ActionMapping;
038: import org.objectweb.jonas.jmx.JonasManagementRepr;
039: import org.objectweb.jonas.jmx.JoramObjectName;
040: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
041:
042: /**
043: * @author Adriana Danes
044: */
045:
046: public class EditJoramServerAction extends EditJoramBaseAction {
047:
048: // --------------------------------------------------------- Public Methods
049:
050: public ActionForward executeAction(ActionMapping pMapping,
051: ActionForm pForm, HttpServletRequest pRequest,
052: HttpServletResponse pResponse) throws IOException,
053: ServletException {
054:
055: // Current JOnAS server
056: String serverName = m_WhereAreYou.getCurrentJonasServerName();
057:
058: // Serve id currently in management
059: String id = pRequest.getParameter("id");
060: if (id == null) {
061: id = (String) m_Session.getAttribute("currentId");
062: } else {
063: m_Session.setAttribute("currentId", id);
064: }
065: String localId = (String) m_Session.getAttribute("localId");
066: boolean collocatedServer = ((Boolean) m_Session
067: .getAttribute("collocatedServer")).booleanValue();
068: boolean isLocalServer;
069: if (localId.equals(id)) {
070: isLocalServer = true;
071: } else {
072: isLocalServer = false;
073: }
074:
075: m_Session.setAttribute("isLocalServer", new Boolean(
076: isLocalServer));
077: // Get reference on EJB container service in order to determine dependencies
078: // between the deployed EJBs and JMS destinations
079: initRefs(serverName);
080:
081: try {
082: Set adapterOns = JonasManagementRepr.queryNames(
083: JoramObjectName.joramAdapter(), serverName);
084: if (adapterOns.isEmpty()) {
085: throw new InstanceNotFoundException();
086: }
087: ObjectName joramAdapterON = (ObjectName) adapterOns
088: .iterator().next();
089: boolean isAdapterLoaded = JonasManagementRepr.isRegistered(
090: joramAdapterON, serverName);
091: ObjectName joramAdminON = JoramObjectName.joramAdmin();
092:
093: ArrayList destinationsArray = new ArrayList();
094: ArrayList topicsArray = new ArrayList();
095: Iterator destinationsList = ((List) JonasManagementRepr
096: .getAttribute(joramAdminON, "Destinations",
097: serverName)).iterator();
098: for (; destinationsList.hasNext();) {
099: String destinationString = (String) destinationsList
100: .next();
101: ItemDestination destinationItem = getDestinationItem(
102: destinationString, serverName);
103: String destName = destinationItem.getName();
104: if (destinationItem.getServerId().equals(id)
105: /*&& destinationItem.getOn() != null*/) {
106: // Put queues to destinationsArray and topics to TopicsArray
107: if (destinationItem.getType().equals("queue")) {
108: destinationsArray.add(destinationItem);
109: } else if (destinationItem.getType()
110: .equals("topic")) {
111: topicsArray.add(destinationItem);
112: }
113: //printDestination(destinationItem, serverName);
114: }
115: }
116: // sort queues
117: Collections.sort(destinationsArray,
118: new ItemDestinationByName());
119: // sort topics
120: Collections.sort(topicsArray, new ItemDestinationByName());
121: // append topics to queues
122: destinationsArray.addAll(topicsArray);
123:
124: ArrayList usersArray = new ArrayList();
125: Iterator usersList;
126: if (isLocalServer) {
127: usersList = ((List) JonasManagementRepr.getAttribute(
128: joramAdapterON, "LocalUsers", serverName))
129: .iterator();
130: } else {
131: usersList = ((List) JonasManagementRepr.getAttribute(
132: joramAdminON, "Users", serverName)).iterator();
133: }
134: for (; usersList.hasNext();) {
135: String userString = (String) usersList.next();
136: ItemUser userItem = getUserItem(userString, serverName);
137: if (userItem.getName() != null
138: && userItem.getServerId().equals(id)) {
139: usersArray.add(userItem);
140: //printUser(userItem);
141: }
142: }
143:
144: m_Session.setAttribute("destinations", destinationsArray);
145: m_Session.setAttribute("users", usersArray);
146: } catch (Throwable t) {
147: return (treatError(t, pMapping, pRequest));
148: }
149:
150: // Force the node selected in tree
151: String nodeName = null;
152: if (isLocalServer) {
153: if (collocatedServer) {
154: nodeName = getTreeBranchName(DEPTH_DOMAIN)
155: + WhereAreYou.NODE_SEPARATOR + "joramplatform"
156: + WhereAreYou.NODE_SEPARATOR
157: + "joramlocalserver";
158: } else {
159: nodeName = getTreeBranchName(DEPTH_DOMAIN)
160: + WhereAreYou.NODE_SEPARATOR + "joramplatform"
161: + WhereAreYou.NODE_SEPARATOR
162: + "joramcurrentserver";
163:
164: }
165: m_WhereAreYou.selectNameNode(nodeName, true);
166: // Forward to the jsp.
167: return (pMapping.findForward("JoramDestinations"));
168: } else {
169: nodeName = getTreeBranchName(DEPTH_DOMAIN)
170: + WhereAreYou.NODE_SEPARATOR + "joramplatform"
171: + WhereAreYou.NODE_SEPARATOR + "joramremoteserver"
172: + id;
173: m_WhereAreYou.selectNameNode(nodeName, true);
174: return (pMapping.findForward("JoramRemoteDestinations"));
175: }
176:
177: }
178:
179: }
|