KickJava   Java API By Example, From Geeks To Geeks.

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


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
21 import java.io.IOException JavaDoc;
22 import java.net.URLDecoder JavaDoc;
23 import java.util.Locale JavaDoc;
24 import javax.management.MBeanServer JavaDoc;
25 import javax.management.ObjectName JavaDoc;
26 import javax.servlet.ServletException JavaDoc;
27 import javax.servlet.http.HttpServletRequest JavaDoc;
28 import javax.servlet.http.HttpServletResponse JavaDoc;
29 import javax.servlet.http.HttpSession JavaDoc;
30 import org.apache.struts.action.Action;
31 import org.apache.struts.action.ActionForm;
32 import org.apache.struts.action.ActionForward;
33 import org.apache.struts.action.ActionMapping;
34 import org.apache.struts.util.MessageResources;
35 import org.apache.webapp.admin.ApplicationServlet;
36 import org.apache.webapp.admin.TomcatTreeBuilder;
37
38 /**
39  * <p>Retrieve the set of MBean names for all currently defined data sources,
40  * and expose them in a request attribute named "dataSourcesForm". This action
41  * requires the following request parameters to be set:</p>
42  * <ul>
43  * <li><strong>forward</strong> - Global forward to which we should
44  * go after stashing the dataSources list.</li>
45  * </ul>
46  *
47  * @author Manveen Kaur
48  * @author Amy Roh
49  * @version $Revision: 1.7 $ $Date: 2004/10/18 06:37:54 $
50  * @since 4.1
51  */

52
53 public class ListDataSourcesAction extends Action {
54
55     // ----------------------------------------------------- Instance Variables
56

57     /**
58      * The MBeanServer we will be interacting with.
59      */

60     private MBeanServer JavaDoc mserver = null;
61
62
63     // --------------------------------------------------------- Public Methods
64

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

81     public ActionForward execute(ActionMapping mapping,
82                                  ActionForm form,
83                                  HttpServletRequest JavaDoc request,
84                                  HttpServletResponse JavaDoc response)
85         throws IOException JavaDoc, ServletException JavaDoc {
86
87
88         // Look up the components we will be using as needed
89
if (mserver == null) {
90             mserver = ((ApplicationServlet) getServlet()).getServer();
91         }
92         MessageResources resources = getResources(request);
93         HttpSession JavaDoc session = request.getSession();
94         Locale JavaDoc locale = getLocale(request);
95         
96         String JavaDoc resourcetype = request.getParameter("resourcetype");
97         String JavaDoc path = request.getParameter("path");
98         String JavaDoc host = request.getParameter("host");
99         String JavaDoc domain = request.getParameter("domain");
100         
101         if (resourcetype != null) {
102             resourcetype = URLDecoder.decode(resourcetype,TomcatTreeBuilder.URL_ENCODING);
103         }
104         if (path != null) {
105             path = URLDecoder.decode(path,TomcatTreeBuilder.URL_ENCODING);
106         }
107         if (host != null) {
108             host = URLDecoder.decode(host,TomcatTreeBuilder.URL_ENCODING);
109         }
110         if (domain != null) {
111             domain = URLDecoder.decode(domain,TomcatTreeBuilder.URL_ENCODING);
112         }
113         
114         // Create a form bean containing the requested MBean Names
115
DataSourcesForm dataSourcesForm = null;
116         try {
117               dataSourcesForm =
118                 ResourceUtils.getDataSourcesForm(mserver, resourcetype,
119                                         path, host, domain);
120         } catch (Exception JavaDoc e) {
121             getServlet().log(resources.getMessage
122                              (locale,
123                               "users.error.attribute.get", "resources"), e);
124             response.sendError
125                 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
126                  resources.getMessage
127                  (locale, "users.error.attribute.get", "resources"));
128         }
129
130         // Stash the results in request scope
131
request.setAttribute("dataSourcesForm", dataSourcesForm);
132         saveToken(request);
133         String JavaDoc forward =
134             URLDecoder.decode(request.getParameter("forward"),TomcatTreeBuilder.URL_ENCODING);
135         
136         return (mapping.findForward(forward));
137     }
138
139 }
140
Popular Tags