KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webapp > admin > valve > DeleteValvesAction


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.valve;
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 Valves</em>
48  * transactions.
49  *
50  * @author Manveen Kaur
51  * @version $Revision: 1.6 $ $Date: 2004/10/18 06:37:55 $
52  */

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

60     private String JavaDoc removeValveTypes[] =
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
71     // --------------------------------------------------------- Public Methods
72

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

89     public ActionForward execute(ActionMapping mapping,
90                                  ActionForm form,
91                                  HttpServletRequest JavaDoc request,
92                                  HttpServletResponse JavaDoc response)
93         throws IOException JavaDoc, ServletException JavaDoc {
94         
95         
96         // Look up the components we will be using as needed
97
HttpSession JavaDoc session = request.getSession();
98         Locale JavaDoc locale = getLocale(request);
99         MessageResources resources = getResources(request);
100
101         // Acquire a reference to the MBeanServer containing our MBeans
102
try {
103             mBServer = ((ApplicationServlet) getServlet()).getServer();
104         } catch (Throwable JavaDoc t) {
105             throw new ServletException JavaDoc
106             ("Cannot acquire MBeanServer reference", t);
107         }
108         
109         // Delete the specified Valves
110
String JavaDoc valves[] = ((ValvesForm) form).getValves();
111         String JavaDoc values[] = new String JavaDoc[1];
112         String JavaDoc operation = "removeValve";
113         try {
114
115             // Look up our tree control data structure
116
TreeControl control = (TreeControl)
117                 session.getAttribute("treeControlTest");
118
119             // Remove the specified valves
120
for (int i = 0; i < valves.length; i++) {
121                 values[0] = valves[i];
122                 String JavaDoc domain = (new ObjectName JavaDoc(valves[i])).getDomain();
123                 ObjectName JavaDoc fname = TomcatTreeBuilder.getMBeanFactory();
124                 mBServer.invoke(fname, operation,
125                                 values, removeValveTypes);
126                 if (control != null) {
127                     control.selectNode(null);
128                     TreeControlNode node = control.findNode(valves[i]);
129                     if (node != null) {
130                         node.remove();
131                     } else {
132                         getServlet().log("Missing TreeControlNode for " +
133                                          valves[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