KickJava   Java API By Example, From Geeks To Geeks.

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


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 ListEnvEntriesAction 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 resourcetype = request.getParameter("resourcetype");
98         String JavaDoc path = request.getParameter("path");
99         String JavaDoc host = request.getParameter("host");
100         String JavaDoc domain = request.getParameter("domain");
101         
102         if (resourcetype != null) {
103             resourcetype = URLDecoder.decode(resourcetype,TomcatTreeBuilder.URL_ENCODING);
104         }
105         if (path != null) {
106             path = URLDecoder.decode(path,TomcatTreeBuilder.URL_ENCODING);
107         }
108         if (host != null) {
109             host = URLDecoder.decode(host,TomcatTreeBuilder.URL_ENCODING);
110         }
111         if (domain != null) {
112             domain = URLDecoder.decode(domain,TomcatTreeBuilder.URL_ENCODING);
113         }
114         // Create a form bean containing the requested MBean Names
115
EnvEntriesForm envEntriesForm = null;
116         try {
117            envEntriesForm =
118                     ResourceUtils.getEnvEntriesForm(mserver, resourcetype,
119                                         path, host, domain);
120         } catch (Exception JavaDoc e) {
121             getServlet().log(resources.getMessage
122                              (locale,
123                               "users.error.attribute.get", "environments"), e);
124             response.sendError
125                 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
126                  resources.getMessage
127                  (locale, "users.error.attribute.get", "environments"));
128         }
129
130         // Stash the results in request scope
131
request.setAttribute("envEntriesForm", envEntriesForm);
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