KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webapp > admin > users > DeleteGroupsAction


1 /*
2  * Copyright 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.users;
19
20
21 import java.io.IOException JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.Locale JavaDoc;
25 import javax.servlet.ServletException JavaDoc;
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27 import javax.servlet.http.HttpServletResponse JavaDoc;
28 import javax.servlet.http.HttpSession JavaDoc;
29 import org.apache.struts.action.Action;
30 import org.apache.struts.action.ActionErrors;
31 import org.apache.struts.action.ActionForm;
32 import org.apache.struts.action.ActionForward;
33 import org.apache.struts.action.ActionMapping;
34 import javax.management.Attribute JavaDoc;
35 import javax.management.MBeanServer JavaDoc;
36 import javax.management.MBeanServerFactory JavaDoc;
37 import javax.management.QueryExp JavaDoc;
38 import javax.management.Query JavaDoc;
39 import javax.management.ObjectInstance JavaDoc;
40 import javax.management.ObjectName JavaDoc;
41 import javax.management.JMException JavaDoc;
42 import javax.management.MBeanAttributeInfo JavaDoc;
43 import javax.management.MBeanOperationInfo JavaDoc;
44 import javax.management.MBeanInfo JavaDoc;
45 import org.apache.struts.util.MessageResources;
46 import org.apache.webapp.admin.ApplicationServlet;
47
48
49 /**
50  * <p>Implementation of <strong>Action</strong> that deletes the
51  * specified set of groups.</p>
52  *
53  * @author Craig R. McClanahan
54  * @version $Revision: 1.5 $ $Date: 2005/03/17 00:21:19 $
55  * @since 4.1
56  */

57
58 public final class DeleteGroupsAction extends Action {
59
60
61     // ----------------------------------------------------- Instance Variables
62

63
64     /**
65      * The MBeanServer we will be interacting with.
66      */

67     private MBeanServer JavaDoc mserver = null;
68
69
70     // --------------------------------------------------------- Public Methods
71

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

88     public ActionForward execute(ActionMapping mapping,
89                                  ActionForm form,
90                                  HttpServletRequest JavaDoc request,
91                                  HttpServletResponse JavaDoc response)
92         throws IOException JavaDoc, ServletException JavaDoc {
93
94         // Look up the components we will be using as needed
95
if (mserver == null) {
96             mserver = ((ApplicationServlet) getServlet()).getServer();
97         }
98         MessageResources resources = getResources(request);
99         HttpSession JavaDoc session = request.getSession();
100         Locale JavaDoc locale = getLocale(request);
101
102         // Has this transaction been cancelled?
103
if (isCancelled(request)) {
104             return (mapping.findForward("List Groups Setup"));
105         }
106
107         // Check the transaction token
108
if (!isTokenValid(request)) {
109             response.sendError
110                 (HttpServletResponse.SC_BAD_REQUEST,
111                  resources.getMessage(locale, "users.error.token"));
112             return (null);
113         }
114
115         // Perform any extra validation that is required
116
GroupsForm groupsForm = (GroupsForm) form;
117         String JavaDoc databaseName = groupsForm.getDatabaseName();
118         String JavaDoc groups[] = groupsForm.getGroups();
119         if (groups == null) {
120             groups = new String JavaDoc[0];
121         }
122
123         // Perform "Delete Group" transactions as required
124
try {
125
126             ObjectName JavaDoc dname = new ObjectName JavaDoc(databaseName);
127             String JavaDoc signature[] = new String JavaDoc[1];
128             signature[0] = "java.lang.String";
129             Object JavaDoc params[] = new String JavaDoc[1];
130
131             for (int i = 0; i < groups.length; i++) {
132                 ObjectName JavaDoc oname = new ObjectName JavaDoc(groups[i]);
133                 params[0] = ObjectName.unquote(oname.getKeyProperty("groupname"));
134                 mserver.invoke(dname, "removeGroup",
135                                params, signature);
136             }
137
138         } catch (Throwable JavaDoc t) {
139
140             getServlet().log
141                 (resources.getMessage(locale, "users.error.invoke",
142                                       "removeGroup"), t);
143             response.sendError
144                 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
145                  resources.getMessage(locale, "users.error.invoke",
146                                       "removeGroup"));
147             return (null);
148
149         }
150
151         // Save the updated database information
152
try {
153
154             ObjectName JavaDoc dname = new ObjectName JavaDoc(databaseName);
155             mserver.invoke(dname, "save",
156                            new Object JavaDoc[0], new String JavaDoc[0]);
157
158         } catch (Throwable JavaDoc t) {
159
160             getServlet().log
161                 (resources.getMessage(locale, "users.error.invoke",
162                                       "save"), t);
163             response.sendError
164                 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
165                  resources.getMessage(locale, "users.error.invoke",
166                                       "save"));
167             return (null);
168
169         }
170
171         // Proceed to the list groups screen
172
return (mapping.findForward("Groups List Setup"));
173
174     }
175
176
177 }
178
Popular Tags