KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webapp > admin > connector > DeleteConnectorsAction


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

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

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

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

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