KickJava   Java API By Example, From Geeks To Geeks.

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


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