KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webapp > admin > connector > DeleteConnectorAction


1 /*
2  * Copyright 2001-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.webapp.admin.connector;
18
19 import java.io.IOException JavaDoc;
20 import java.util.Collections JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Locale JavaDoc;
24 import java.util.TreeSet JavaDoc;
25 import java.util.Set JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import javax.servlet.ServletException JavaDoc;
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29 import javax.servlet.http.HttpServletResponse JavaDoc;
30 import javax.servlet.http.HttpSession JavaDoc;
31 import org.apache.struts.action.Action;
32 import org.apache.struts.action.ActionErrors;
33 import org.apache.struts.action.ActionForm;
34 import org.apache.struts.action.ActionForward;
35 import org.apache.struts.action.ActionMapping;
36
37 import javax.management.MBeanServer JavaDoc;
38 import javax.management.MBeanServerFactory JavaDoc;
39 import javax.management.QueryExp JavaDoc;
40 import javax.management.Query JavaDoc;
41 import javax.management.ObjectInstance JavaDoc;
42 import javax.management.ObjectName JavaDoc;
43 import javax.management.JMException JavaDoc;
44 import org.apache.struts.util.MessageResources;
45
46 import org.apache.webapp.admin.ApplicationServlet;
47 import org.apache.webapp.admin.TomcatTreeBuilder;
48
49 /**
50  * The <code>Action</code> that sets up <em>Delete Connectors</em> transactions.
51  *
52  * @author Manveen Kaur
53  * @version $Revision: 1.6 $ $Date: 2004/10/18 06:37:53 $
54  */

55
56 public class DeleteConnectorAction extends Action {
57         
58     /**
59      * The MBeanServer we will be interacting with.
60      */

61     private MBeanServer JavaDoc mBServer = null;
62     
63     
64     
65     
66     
67     // --------------------------------------------------------- Public Methods
68

69     /**
70      * Process the specified HTTP request, and create the corresponding HTTP
71      * response (or forward to another web component that will create it).
72      * Return an <code>ActionForward</code> instance describing where and how
73      * control should be forwarded, or <code>null</code> if the response has
74      * already been completed.
75      *
76      * @param mapping The ActionMapping used to select this instance
77      * @param actionForm The optional ActionForm bean for this request (if any)
78      * @param request The HTTP request we are processing
79      * @param response The HTTP response we are creating
80      *
81      * @exception IOException if an input/output error occurs
82      * @exception ServletException if a servlet exception occurs
83      */

84     public ActionForward execute(ActionMapping mapping,
85     ActionForm form,
86     HttpServletRequest JavaDoc request,
87     HttpServletResponse JavaDoc response)
88     throws IOException JavaDoc, ServletException JavaDoc {
89         
90         
91         // Acquire the resources that we need
92
HttpSession JavaDoc session = request.getSession();
93         Locale JavaDoc locale = getLocale(request);
94         MessageResources resources = getResources(request);
95         
96         // Acquire a reference to the MBeanServer containing our MBeans
97
try {
98             mBServer = ((ApplicationServlet) getServlet()).getServer();
99         } catch (Throwable JavaDoc t) {
100             throw new ServletException JavaDoc
101             ("Cannot acquire MBeanServer reference", t);
102         }
103         
104         String JavaDoc domain = null;
105         // Set up a form bean containing the currently selected
106
// objects to be deleted
107
ConnectorsForm connectorsForm = new ConnectorsForm();
108         String JavaDoc select = request.getParameter("select");
109         if (select != null) {
110             String JavaDoc connectors[] = new String JavaDoc[1];
111             connectors[0] = select;
112             connectorsForm.setConnectors(connectors);
113                         
114             // get the service Name this selected host belongs to
115
try {
116                 domain = (new ObjectName JavaDoc(select)).getDomain();
117             } catch (Exception JavaDoc e) {
118                 throw new ServletException JavaDoc
119                 ("Error extracting service name from the connector to be deleted", e);
120             }
121         }
122         request.setAttribute("connectorsForm", connectorsForm);
123         
124         // Accumulate a list of all available connectors
125
ArrayList JavaDoc list = new ArrayList JavaDoc();
126          try {
127             String JavaDoc pattern = domain + TomcatTreeBuilder.CONNECTOR_TYPE +
128                 TomcatTreeBuilder.WILDCARD;
129             Iterator JavaDoc items =
130                 mBServer.queryNames(new ObjectName JavaDoc(pattern), null).iterator();
131             while (items.hasNext()) {
132                 Object JavaDoc item = items.next();
133                 list.add(item.toString());
134             }
135         } catch (Exception JavaDoc e) {
136             getServlet().log
137                 (resources.getMessage(locale, "users.error.select"));
138             response.sendError
139                 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
140                  resources.getMessage(locale, "users.error.select"));
141             return (null);
142         }
143         Collections.sort(list);
144         request.setAttribute("connectorsList", list);
145         
146         // Forward to the list display page
147
return (mapping.findForward("Connectors"));
148     }
149 }
150
Popular Tags