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: */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.List;
026:
027: import javax.management.InstanceNotFoundException;
028: import javax.management.ObjectName;
029: import javax.servlet.ServletException;
030: import javax.servlet.http.HttpServletRequest;
031: import javax.servlet.http.HttpServletResponse;
032:
033: import org.apache.struts.action.ActionForm;
034: import org.apache.struts.action.ActionForward;
035: import org.apache.struts.action.ActionMapping;
036: import org.objectweb.jonas.jmx.JonasManagementRepr;
037: import org.objectweb.jonas.jmx.JonasObjectName;
038: import org.objectweb.jonas.jmx.JoramObjectName;
039: import org.objectweb.jonas.webapp.jonasadmin.Jlists;
040: import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
041: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
042: import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItem;
043: import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItemByNameComparator;
044:
045: /**
046: * @author Adriana Danes
047: */
048:
049: public class EditJoramTopicAction extends EditJoramBaseAction {
050:
051: // --------------------------------------------------------- Public Methods
052:
053: public ActionForward executeAction(ActionMapping pMapping,
054: ActionForm pForm, HttpServletRequest pRequest,
055: HttpServletResponse pResponse) throws IOException,
056: ServletException {
057:
058: // Current JOnAS server
059: String serverName = m_WhereAreYou.getCurrentJonasServerName();
060:
061: String name = pRequest.getParameter("name");
062: // currently managed server id
063: String serverId = pRequest.getParameter("id");
064: if (serverId != null) {
065: m_Session.setAttribute("currentId", serverId);
066: } else {
067: serverId = (String) m_Session.getAttribute("currentId");
068: }
069: // local server id set by JonasTreeBuilder
070: String localId = (String) m_Session.getAttribute("localId");
071: try {
072: // Check that Joram RAR still deployed
073: if (JonasManagementRepr.queryNames(
074: JoramObjectName.joramAdapter(), serverName)
075: .isEmpty()) {
076: throw new InstanceNotFoundException();
077: }
078: // Form used
079: JoramTopicForm oForm = null;
080: MonitoringDestForm mForm = new MonitoringDestForm();
081: if (name != null) {
082: // Build a new form
083: oForm = new JoramTopicForm();
084: oForm.reset(pMapping, pRequest);
085: // Attach the form to the session object
086: m_Session.setAttribute("joramTopicForm", oForm);
087: // Object name used
088: ObjectName oObjectName = JoramObjectName
089: .joramTopic(name);
090: oForm.setOName(oObjectName);
091: oForm.setBooleanVals(Jlists.getBooleanValues());
092: populateDestination(oObjectName, oForm, serverName);
093: getStatistics(oObjectName, mForm, oForm, serverName);
094: oForm.setSubscriptions(getIntegerAttribute(oObjectName,
095: "Subscriptions"));
096: String[] subscriberIds = (String[]) JonasManagementRepr
097: .getAttribute(oObjectName, "SubscriberIds",
098: serverName);
099: StringBuffer buf = new StringBuffer();
100: for (int i = 0; i < subscriberIds.length; i++) {
101: String subscriberId = subscriberIds[i];
102: String subsriberName = getUserName(subscriberId,
103: serverName);
104: if (subsriberName == null) {
105: //throw new Exception("Problem with " + name + " topic subscribers: could not found any user having id=" + subscriberId);
106: subsriberName = subscriberId;
107: }
108: buf.append(subsriberName);
109: buf.append("\n");
110: }
111: oForm.setSubscribers(new String(buf));
112: m_Session.setAttribute("joramStatForm", mForm);
113: } else {
114: // Used last form in session
115: oForm = (JoramTopicForm) m_Session
116: .getAttribute("joramTopicForm");
117: if (!oForm.getFreelyReadable()) {
118: // update readers list
119: List readerList = getListAttribute(
120: oForm.getOName(), "ReaderList");
121: oForm.setReaderList(getBaseItemList(readerList,
122: serverName));
123: }
124: if (!oForm.getFreelyWriteable()) {
125: // update writers list
126: List writerList = getListAttribute(
127: oForm.getOName(), "WriterList");
128: oForm.setWriterList(getBaseItemList(writerList,
129: serverName));
130: }
131: name = oForm.getName();
132: if (localId == null) {
133: ObjectName joramPlatformON = JoramObjectName
134: .joramPlatform();
135: localId = getStringAttribute(joramPlatformON,
136: "LocalServerId");
137: m_Session.setAttribute("localId", localId);
138: }
139: }
140:
141: // Populuate dependency list
142: if (name != null) {
143: ArrayList al = new ArrayList();
144: String[] asParam = new String[1];
145: String[] asSignature = new String[1];
146: asSignature[0] = "java.lang.String";
147: asParam[0] = name;
148: ObjectName ejbServiceObjectName = JonasObjectName
149: .ejbService();
150: if (JonasManagementRepr.isRegistered(
151: ejbServiceObjectName, serverName)) {
152: java.util.Iterator it = ((java.util.Set) JonasManagementRepr
153: .invoke(ejbServiceObjectName,
154: "getJmsDestinationDependence",
155: asParam, asSignature, serverName))
156: .iterator();
157: while (it.hasNext()) {
158: al.add(new EjbItem((ObjectName) it.next(),
159: serverName));
160: }
161: // Sort by name
162: Collections.sort(al, new EjbItemByNameComparator());
163: // Set list in form
164: oForm.setListUsedByEjb(al);
165: }
166: }
167: } catch (Throwable t) {
168: return (treatError(t, pMapping, pRequest));
169: }
170:
171: boolean isLocalServer;
172: if (serverId.equals(localId)) {
173: isLocalServer = true;
174: } else {
175: isLocalServer = false;
176: }
177: m_Session.setAttribute("isLocalServer", new Boolean(
178: isLocalServer));
179:
180: // Force the node selected in tree and forward to the jsp.
181: String nodeName = null;
182: boolean collocatedServer = ((Boolean) m_Session
183: .getAttribute("collocatedServer")).booleanValue();
184: if (isLocalServer) {
185: if (collocatedServer) {
186: nodeName = getTreeBranchName(DEPTH_DOMAIN)
187: + WhereAreYou.NODE_SEPARATOR + "joramplatform"
188: + WhereAreYou.NODE_SEPARATOR
189: + "joramlocalserver"
190: + WhereAreYou.NODE_SEPARATOR + "joramtopic"
191: + name;
192: } else {
193: nodeName = getTreeBranchName(DEPTH_DOMAIN)
194: + WhereAreYou.NODE_SEPARATOR + "joramplatform"
195: + WhereAreYou.NODE_SEPARATOR
196: + "joramcurrentserver"
197: + WhereAreYou.NODE_SEPARATOR + "joramtopic"
198: + name;
199:
200: }
201: } else {
202: nodeName = getTreeBranchName(DEPTH_DOMAIN)
203: + WhereAreYou.NODE_SEPARATOR + "joramplatform"
204: + WhereAreYou.NODE_SEPARATOR + "joramremoteserver"
205: + serverId + WhereAreYou.NODE_SEPARATOR
206: + "joramtopic" + name;
207: }
208: m_WhereAreYou.selectNameNode(nodeName, true);
209: return (pMapping.findForward("JoramTopic"));
210: }
211:
212: }
|