KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webapp > admin > host > DeleteAliasesAction


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.host;
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
42 /**
43  * The <code>Action</code> that completes <em>Delete Aliases</em>
44  * transactions.
45  *
46  * @author Manveen Kaur
47  * @version $Revision: 1.4 $ $Date: 2004/10/18 06:37:53 $
48  */

49
50 public class DeleteAliasesAction extends Action {
51
52
53     /**
54      * Signature for the <code>removeAlias</code> operation.
55      */

56     private String JavaDoc removeAliasTypes[] =
57     { "java.lang.String", // Object name
58
};
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     /**
71      * Process the specified HTTP request, and create the corresponding HTTP
72      * response (or forward to another web component that will create it).
73      * Return an <code>ActionForward</code> instance describing where and how
74      * control should be forwarded, or <code>null</code> if the response has
75      * already been completed.
76      *
77      * @param mapping The ActionMapping used to select this instance
78      * @param actionForm The optional ActionForm bean for this request (if any)
79      * @param request The HTTP request we are processing
80      * @param response The HTTP response we are creating
81      *
82      * @exception IOException if an input/output error occurs
83      * @exception ServletException if a servlet exception occurs
84      */

85     public ActionForward execute(ActionMapping mapping,
86                                  ActionForm form,
87                                  HttpServletRequest JavaDoc request,
88                                  HttpServletResponse JavaDoc response)
89         throws IOException JavaDoc, ServletException JavaDoc {
90         
91         
92         // Look up the components we will be using as needed
93
HttpSession JavaDoc session = request.getSession();
94         Locale JavaDoc locale = getLocale(request);
95         MessageResources resources = getResources(request);
96
97         // Acquire a reference to the MBeanServer containing our MBeans
98
try {
99             mBServer = ((ApplicationServlet) getServlet()).getServer();
100         } catch (Throwable JavaDoc t) {
101             throw new ServletException JavaDoc
102             ("Cannot acquire MBeanServer reference", t);
103         }
104         
105         AliasesForm aliasesFm = (AliasesForm) form;
106         // the host Name is needed to delete the existing aliases from
107
String JavaDoc hostName = aliasesFm.getHostName();
108         
109         // Delete the specified Aliases
110
String JavaDoc aliases[] = aliasesFm.getAliases();
111         String JavaDoc values[] = new String JavaDoc[1];
112         String JavaDoc operation = "removeAlias";
113
114         try {
115             
116             ObjectName JavaDoc hname = new ObjectName JavaDoc(hostName);
117
118             // Remove the specified hosts
119
for (int i = 0; i < aliases.length; i++) {
120                 values[0] = aliases[i];
121                 mBServer.invoke(hname, operation, values, removeAliasTypes);
122             }
123
124         } catch (Exception JavaDoc e) {
125             getServlet().log
126                 (resources.getMessage(locale, "users.error.invoke",
127                                       operation), e);
128             response.sendError
129                 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
130                  resources.getMessage(locale, "users.error.invoke",
131                                       operation));
132             return (null);
133
134         }
135
136         // Report successful completion of this transaction
137
return (mapping.findForward("Save Successful"));
138
139     }
140     
141 }
142
Popular Tags