KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > jonasadmin > joramplatform > EditJoramTopicAction


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2005 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  */

21
22 package org.objectweb.jonas.webapp.jonasadmin.joramplatform;
23
24 import java.io.IOException JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.Collections JavaDoc;
27
28 import javax.management.ObjectName JavaDoc;
29 import javax.servlet.ServletException JavaDoc;
30 import javax.servlet.http.HttpServletRequest JavaDoc;
31 import javax.servlet.http.HttpServletResponse JavaDoc;
32
33 import org.apache.struts.action.ActionForm;
34 import org.apache.struts.action.ActionForward;
35 import org.apache.struts.action.ActionMapping;
36 import org.objectweb.jonas.jmx.JonasManagementRepr;
37 import org.objectweb.jonas.jmx.JonasObjectName;
38 import org.objectweb.jonas.jmx.JoramObjectName;
39 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
40 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItem;
41 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItemByNameComparator;
42
43 /**
44  * @author Adriana Danes
45  */

46
47 public class EditJoramTopicAction extends EditJoramBaseAction {
48
49 // --------------------------------------------------------- Public Methods
50

51     public ActionForward executeAction(ActionMapping pMapping, ActionForm pForm
52             , HttpServletRequest JavaDoc pRequest, HttpServletResponse JavaDoc pResponse)
53     throws IOException JavaDoc, ServletException JavaDoc {
54
55         String JavaDoc name = pRequest.getParameter("name");
56         // currently managed server id
57
String JavaDoc serverId = pRequest.getParameter("id");
58         if (serverId != null) {
59             m_Session.setAttribute("currentId", serverId);
60         } else {
61             serverId = (String JavaDoc) m_Session.getAttribute("currentId");
62         }
63         // local server id set by JonasTreeBuilder
64
String JavaDoc localId = (String JavaDoc) m_Session.getAttribute("localId");
65         try {
66             // Form used
67
JoramTopicForm oForm = null;
68             MonitoringDestForm mForm = new MonitoringDestForm();
69             if (name != null) {
70                 // Build a new form
71
oForm = new JoramTopicForm();
72                 oForm.reset(pMapping, pRequest);
73                 // Attach the form to the session object
74
m_Session.setAttribute("joramTopicForm", oForm);
75                 // Object name used
76
ObjectName JavaDoc oObjectName = JoramObjectName.joramTopic(name);
77                 populateDestination(oObjectName, oForm);
78                 getStatistics(oObjectName, mForm, oForm);
79                 oForm.setSubscriptions(getIntegerAttribute(oObjectName, "Subscriptions"));
80                 oForm.setSubscriberIds((String JavaDoc []) JonasManagementRepr.getAttribute(oObjectName, "SubscriberIds"));
81                 m_Session.setAttribute("joramStatForm", mForm);
82             } else {
83                 // Used last form in session
84
oForm = (JoramTopicForm) m_Session.getAttribute("joramTopicForm");
85                 serverId = oForm.getId();
86                 localId = (String JavaDoc) m_Session.getAttribute("localId");
87                 if (localId == null) {
88                     ObjectName JavaDoc joramPlatformON = JoramObjectName.joramPlatform();
89                     localId = getStringAttribute(joramPlatformON, "LocalServerId");
90                     m_Session.setAttribute("localId", localId);
91                 }
92             }
93
94             // Populuate dependency list
95
if (name != null) {
96                 ArrayList JavaDoc al = new ArrayList JavaDoc();
97                 String JavaDoc[] asParam = new String JavaDoc[1];
98                 String JavaDoc[] asSignature = new String JavaDoc[1];
99                 asSignature[0] = "java.lang.String";
100                 asParam[0] = name;
101                 ObjectName JavaDoc ejbServiceObjectName = JonasObjectName.ejbService();
102                 if (JonasManagementRepr.isRegistered(ejbServiceObjectName)) {
103                     java.util.Iterator JavaDoc it = ((java.util.Set JavaDoc) JonasManagementRepr.invoke(
104                             ejbServiceObjectName, "getJmsDestinationDependence", asParam
105                             , asSignature)).iterator();
106                     while (it.hasNext()) {
107                         al.add(new EjbItem((ObjectName JavaDoc) it.next()));
108                     }
109                     // Sort by name
110
Collections.sort(al, new EjbItemByNameComparator());
111                     // Set list in form
112
oForm.setListUsedByEjb(al);
113                 }
114             }
115         } catch (Throwable JavaDoc t) {
116             return (treatError(t, pMapping, pRequest));
117         }
118
119         boolean isLocalServer;
120         if (serverId.equals(localId)) {
121             isLocalServer = true;
122         } else {
123             isLocalServer = false;
124         }
125         m_Session.setAttribute("isLocalServer", new Boolean JavaDoc(isLocalServer));
126
127         // Force the node selected in tree and forward to the jsp.
128
String JavaDoc nodeName = null;
129         if (isLocalServer) {
130             nodeName = getTreeBranchName(DEPTH_DOMAIN) + WhereAreYou.NODE_SEPARATOR
131             + "joramplatform" + WhereAreYou.NODE_SEPARATOR
132             + "joramlocalserver" + WhereAreYou.NODE_SEPARATOR
133             + "joramtopic" + name;
134         } else {
135             nodeName = getTreeBranchName(DEPTH_DOMAIN) + WhereAreYou.NODE_SEPARATOR
136             + "joramplatform" + WhereAreYou.NODE_SEPARATOR
137             + "joramremoteserver" + serverId + WhereAreYou.NODE_SEPARATOR
138             + "joramtopic" + name;
139         }
140         m_WhereAreYou.selectNameNode(nodeName, true);
141         return (pMapping.findForward("JoramTopic"));
142     }
143
144 }
145
Popular Tags