KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webapp > admin > host > DeleteAliasAction


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

57
58 public class DeleteAliasAction extends Action {
59     
60
61     /**
62      * The MBeanServer we will be interacting with.
63      */

64     private MBeanServer JavaDoc mBServer = null;
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         // Set up a form bean containing the currently selected
105
// objects to be deleted
106
AliasesForm aliasesFm = new AliasesForm();
107         ArrayList JavaDoc aliasesList = null;
108         
109         String JavaDoc hostName = request.getParameter("hostName");
110         aliasesFm.setHostName(hostName);
111         
112         // retrieve all aliases
113
String JavaDoc operation = null;
114         try {
115             ObjectName JavaDoc hname = new ObjectName JavaDoc(hostName);
116
117             operation = "findAliases";
118             String JavaDoc aliases[] =
119                 (String JavaDoc[]) mBServer.invoke(hname, operation, null, null);
120             aliasesFm.setAliases(aliases);
121             aliasesList = new ArrayList JavaDoc(Arrays.asList(aliases));
122
123         } catch (Throwable JavaDoc t) {
124             getServlet().log
125             (resources.getMessage(locale, "users.error.invoke",
126                                   operation), t);
127             response.sendError
128                 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
129                 resources.getMessage(locale, "users.error.invoke",
130                                      operation));
131             return (null);
132         }
133                 
134         Collections.sort(aliasesList);
135         request.setAttribute("aliasesForm", aliasesFm);
136         request.setAttribute("aliasesList", aliasesList);
137         
138         // Forward to the list display page
139
return (mapping.findForward("Aliases"));
140
141     }
142
143 }
144
Popular Tags