KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webapp > admin > resources > DeleteDataSourcesAction


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.resources;
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 javax.servlet.ServletException JavaDoc;
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26 import javax.servlet.http.HttpServletResponse JavaDoc;
27 import javax.servlet.http.HttpSession JavaDoc;
28 import org.apache.struts.action.Action;
29 import org.apache.struts.action.ActionErrors;
30 import org.apache.struts.action.ActionForm;
31 import org.apache.struts.action.ActionForward;
32 import org.apache.struts.action.ActionMapping;
33 import javax.management.Attribute JavaDoc;
34 import javax.management.MBeanServer JavaDoc;
35 import javax.management.MBeanServerFactory JavaDoc;
36 import javax.management.QueryExp JavaDoc;
37 import javax.management.Query JavaDoc;
38 import javax.management.ObjectInstance JavaDoc;
39 import javax.management.ObjectName JavaDoc;
40 import javax.management.JMException JavaDoc;
41 import javax.management.MBeanAttributeInfo JavaDoc;
42 import javax.management.MBeanOperationInfo JavaDoc;
43 import javax.management.MBeanInfo JavaDoc;
44 import org.apache.struts.util.MessageResources;
45 import org.apache.webapp.admin.ApplicationServlet;
46
47
48 /**
49  * <p>Implementation of <strong>Action</strong> that deletes the
50  * specified set of dataSource entries.</p>
51  *
52  * @author Manveen Kaur
53  * @version $Revision: 1.8 $ $Date: 2004/10/18 06:37:54 $
54  * @since 4.1
55  */

56
57 public final class DeleteDataSourcesAction extends Action {
58
59
60     // ----------------------------------------------------- Instance Variables
61

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

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

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

87     public ActionForward execute(ActionMapping mapping,
88                                  ActionForm form,
89                                  HttpServletRequest JavaDoc request,
90                                  HttpServletResponse JavaDoc response)
91         throws IOException JavaDoc, ServletException JavaDoc {
92
93         // Look up the components we will be using as needed
94
if (mserver == null) {
95             mserver = ((ApplicationServlet) getServlet()).getServer();
96         }
97         MessageResources resources = getResources(request);
98         HttpSession JavaDoc session = request.getSession();
99         Locale JavaDoc locale = getLocale(request);
100
101         // Has this transaction been cancelled?
102
if (isCancelled(request)) {
103             return (mapping.findForward("List DataSources Setup"));
104         }
105
106         // Check the transaction token
107
if (!isTokenValid(request)) {
108             response.sendError
109                 (HttpServletResponse.SC_BAD_REQUEST,
110                  resources.getMessage(locale, "users.error.token"));
111             return (null);
112         }
113
114         // Perform any extra validation that is required
115
DataSourcesForm dataSourcesForm = (DataSourcesForm) form;
116         String JavaDoc dataSources[] = dataSourcesForm.getDataSources();
117         if (dataSources == null) {
118             dataSources = new String JavaDoc[0];
119         }
120
121         // Perform "Delete EnvEntry" transactions as required
122
try {
123             
124             String JavaDoc resourcetype = dataSourcesForm.getResourcetype();
125             String JavaDoc path = dataSourcesForm.getPath();
126             String JavaDoc host = dataSourcesForm.getHost();
127             //String domain = dataSourcesForm.getDomain();
128

129             ObjectName JavaDoc dname = null;
130
131             String JavaDoc signature[] = new String JavaDoc[1];
132             signature[0] = "java.lang.String";
133             Object JavaDoc params[] = new String JavaDoc[1];
134              
135             for (int i = 0; i < dataSources.length; i++) {
136                 ObjectName JavaDoc oname = new ObjectName JavaDoc(dataSources[i]);
137                 String JavaDoc domain = oname.getDomain();
138                 dname = ResourceUtils.getNamingResourceObjectName(domain,
139                             resourcetype, path, host);
140                 params[0] = oname.getKeyProperty("name");
141                 mserver.invoke(dname, "removeResource",
142                                params, signature);
143             }
144           
145         } catch (Throwable JavaDoc t) {
146
147             getServlet().log
148                 (resources.getMessage(locale, "users.error.invoke",
149                                       "removeResource"), t);
150             response.sendError
151                 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
152                  resources.getMessage(locale, "users.error.invoke",
153                                       "removeResource"));
154             return (null);
155
156         }
157
158         // Proceed to the list envEntrys screen
159
return (mapping.findForward("DataSources List Setup"));
160
161     }
162
163 }
164
Popular Tags