KickJava   Java API By Example, From Geeks To Geeks.

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


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

53
54 public class DeleteRealmsAction extends Action {
55
56
57     /**
58      * Signature for the <code>removeRealm</code> operation.
59      */

60     private String JavaDoc removeRealmTypes[] =
61     { "java.lang.String", // Object name
62
};
63
64
65     /**
66      * The MBeanServer we will be interacting with.
67      */

68     private MBeanServer JavaDoc mBServer = null;
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         
95         // Look up the components we will be using as needed
96
HttpSession JavaDoc session = request.getSession();
97         Locale JavaDoc locale = getLocale(request);
98         MessageResources resources = getResources(request);
99
100         // Acquire a reference to the MBeanServer containing our MBeans
101
try {
102             mBServer = ((ApplicationServlet) getServlet()).getServer();
103         } catch (Throwable JavaDoc t) {
104             throw new ServletException JavaDoc
105             ("Cannot acquire MBeanServer reference", t);
106         }
107         
108         // Delete the specified Realms
109
String JavaDoc realms[] = ((RealmsForm) form).getRealms();
110         String JavaDoc values[] = new String JavaDoc[1];
111         String JavaDoc operation = "removeRealm";
112         try {
113
114             // Look up our tree control data structure
115
TreeControl control = (TreeControl)
116                 session.getAttribute("treeControlTest");
117
118             // Remove the specified realms
119
for (int i = 0; i < realms.length; i++) {
120                 values[0] = realms[i];
121                 if (control != null) {
122                     control.selectNode(null);
123                     TreeControlNode node = control.findNode(realms[i]);
124                     String JavaDoc domain = node.getDomain();
125                     ObjectName JavaDoc fname =
126                         TomcatTreeBuilder.getMBeanFactory();
127                     mBServer.invoke(fname, operation,
128                                 values, removeRealmTypes);
129                     if (node != null) {
130                         node.remove();
131                     } else {
132                         getServlet().log("Missing TreeControlNode for " +
133                                          realms[i]);
134                     }
135                 } else {
136                     getServlet().log("Missing TreeControl attribute");
137                 }
138             }
139
140         } catch (Exception JavaDoc e) {
141
142             getServlet().log
143                 (resources.getMessage(locale, "users.error.invoke",
144                                       operation), e);
145             response.sendError
146                 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
147                  resources.getMessage(locale, "users.error.invoke",
148                                       operation));
149             return (null);
150
151         }
152
153         // Report successful completion of this transaction
154
return (mapping.findForward("Save Successful"));
155
156     }
157     
158 }
159
Popular Tags