KickJava   Java API By Example, From Geeks To Geeks.

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


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 environment entries,
40  * and expose them in a request attribute named "enventriesForm". 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 env entries list.</li>
45  * </ul>
46  *
47  * @author Manveen Kaur
48  * @version $Revision: 1.5 $ $Date: 2004/10/18 06:37:54 $
49  * @since 4.1
50  */

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

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

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

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

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