KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 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 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29
30 import javax.management.ObjectName JavaDoc;
31 import javax.servlet.ServletException JavaDoc;
32 import javax.servlet.http.HttpServletRequest JavaDoc;
33 import javax.servlet.http.HttpServletResponse JavaDoc;
34
35 import org.apache.struts.action.ActionForm;
36 import org.apache.struts.action.ActionForward;
37 import org.apache.struts.action.ActionMapping;
38 import org.objectweb.jonas.jmx.JonasManagementRepr;
39 import org.objectweb.jonas.jmx.JoramObjectName;
40 import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
41 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
42
43 /**
44  * @author Adriana Danes
45  */

46
47 public class EditJoramServerAction 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         // Serve id currently in management
56
String JavaDoc id = pRequest.getParameter("id");
57         if (id == null) {
58             id = (String JavaDoc) m_Session.getAttribute("currentId");
59         } else {
60             m_Session.setAttribute("currentId", id);
61         }
62         String JavaDoc localId = (String JavaDoc) m_Session.getAttribute("localId");
63         boolean isLocalServer;
64         if (localId.equals(id)) {
65             isLocalServer = true;
66         } else {
67             isLocalServer = false;
68         }
69
70         m_Session.setAttribute("isLocalServer", new Boolean JavaDoc(isLocalServer));
71         // Get reference on EJB container service in order to determine dependencies
72
// between the deployed EJBs and JMS destinations
73
initRefs();
74
75         try {
76             ObjectName JavaDoc joramAdapterON = (ObjectName JavaDoc) JonasManagementRepr.queryNames(JoramObjectName.joramAdapter()).iterator().next();
77             boolean isAdapterLoaded = JonasManagementRepr.isRegistered(joramAdapterON);
78             ObjectName JavaDoc joramAdminON = JoramObjectName.joramAdmin();
79
80             ArrayList JavaDoc destinationsArray = new ArrayList JavaDoc();
81             ArrayList JavaDoc topicsArray = new ArrayList JavaDoc();
82             Iterator JavaDoc destinationsList = ((List JavaDoc) JonasManagementRepr.getAttribute(joramAdminON, "Destinations")).iterator();
83             for (; destinationsList.hasNext(); ) {
84                 String JavaDoc destinationString = (String JavaDoc) destinationsList.next();
85                 ItemDestination destinationItem = getDestinationItem(destinationString);
86                 if (destinationItem.getServerId().equals(id) &&
87                         destinationItem.getOn() != null) {
88                     // Put queues to destinationsArray and topics to TopicsArray
89
if (destinationItem.getType().equals("queue")) {
90                         destinationsArray.add(destinationItem);
91                     } else if (destinationItem.getType().equals("topic")) {
92                         topicsArray.add(destinationItem);
93                     }
94                     //printDestination(destinationItem);
95
}
96             }
97             // sort queues
98
Collections.sort(destinationsArray, new ItemDestinationByName());
99             // sort topics
100
Collections.sort(topicsArray, new ItemDestinationByName());
101             // append topics to queues
102
destinationsArray.addAll(topicsArray);
103
104             ArrayList JavaDoc usersArray = new ArrayList JavaDoc();
105             Iterator JavaDoc usersList;
106             if (isLocalServer) {
107                 usersList = ((List JavaDoc) JonasManagementRepr.getAttribute(joramAdapterON, "LocalUsers")).iterator();
108             } else {
109                 usersList = ((List JavaDoc) JonasManagementRepr.getAttribute(joramAdminON, "Users")).iterator();
110             }
111             for (;usersList.hasNext();) {
112                 String JavaDoc userString = (String JavaDoc) usersList.next();
113                 ItemUser userItem = getUserItem(userString);
114                 String JavaDoc name = userItem.getName();
115                 if (name != null) {
116                     usersArray.add(userItem);
117                     //printUser(userItem);
118
}
119             }
120
121             m_Session.setAttribute("destinations", destinationsArray);
122             m_Session.setAttribute("users", usersArray);
123         } catch (Throwable JavaDoc t) {
124             return (treatError(t, pMapping, pRequest));
125         }
126
127         // Force the node selected in tree
128
String JavaDoc nodeName = null;
129         if (isLocalServer) {
130             nodeName = getTreeBranchName(DEPTH_DOMAIN) + WhereAreYou.NODE_SEPARATOR
131                     + "joramplatform" + WhereAreYou.NODE_SEPARATOR
132                     + "joramlocalserver";
133         } else {
134             nodeName = getTreeBranchName(DEPTH_DOMAIN) + WhereAreYou.NODE_SEPARATOR
135             + "joramplatform" + WhereAreYou.NODE_SEPARATOR
136             + "joramremoteserver" + id;
137         }
138         m_WhereAreYou.selectNameNode(nodeName, true);
139
140         // Forward to the jsp.
141
return (pMapping.findForward("JoramDestinations"));
142     }
143
144 }
145
Popular Tags