KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webapp > admin > realm > DeleteRealmAction


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

57
58 public class DeleteRealmAction 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         String JavaDoc pattern = null;
105         // Set up a form bean containing the currently selected
106
// objects to be deleted
107
RealmsForm realmsForm = new RealmsForm();
108         String JavaDoc select = request.getParameter("select");
109         if (select != null) {
110             String JavaDoc realms[] = new String JavaDoc[1];
111             realms[0] = select;
112             realmsForm.setRealms(realms);
113             pattern = select;
114         }
115         request.setAttribute("realmsForm", realmsForm);
116         
117         // Accumulate a list of all available realms
118
ArrayList JavaDoc list = new ArrayList JavaDoc();
119         String JavaDoc parent = request.getParameter("parent");
120         
121         if (parent != null) {
122             try {
123                 pattern = ValveUtil.getObjectName(
124                              parent,TomcatTreeBuilder.REALM_TYPE);
125             } catch (Exception JavaDoc e) {
126                 getServlet().log
127                 (resources.getMessage(locale, "users.error.select"));
128                 response.sendError
129                 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
130                 resources.getMessage(locale, "users.error.select"));
131                 return (null);
132             }
133         }
134         
135         try {
136             Iterator JavaDoc items =
137             mBServer.queryNames(new ObjectName JavaDoc(pattern), null).iterator();
138             while (items.hasNext()) {
139                 list.add(items.next().toString());
140             }
141         } catch (Exception JavaDoc e) {
142             getServlet().log
143             (resources.getMessage(locale, "users.error.select"));
144             response.sendError
145             (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
146             resources.getMessage(locale, "users.error.select"));
147             return (null);
148         }
149         
150         Collections.sort(list);
151         request.setAttribute("realmsList", list);
152         
153         // Forward to the list display page
154
return (mapping.findForward("Realms"));
155         
156     }
157
158 }
159
Popular Tags