KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.apache.webapp.admin.resources;
18
19 import java.io.IOException JavaDoc;
20 import java.net.URLDecoder JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.Locale JavaDoc;
23 import javax.management.Attribute JavaDoc;
24 import javax.management.MBeanServer JavaDoc;
25 import javax.management.MBeanServerFactory JavaDoc;
26 import javax.management.QueryExp JavaDoc;
27 import javax.management.Query JavaDoc;
28 import javax.management.ObjectInstance JavaDoc;
29 import javax.management.ObjectName JavaDoc;
30 import javax.management.JMException JavaDoc;
31 import javax.management.MBeanAttributeInfo JavaDoc;
32 import javax.management.MBeanOperationInfo JavaDoc;
33 import javax.management.MBeanInfo JavaDoc;
34 import javax.servlet.ServletException JavaDoc;
35 import javax.servlet.http.HttpServletRequest JavaDoc;
36 import javax.servlet.http.HttpServletResponse JavaDoc;
37 import javax.servlet.http.HttpSession JavaDoc;
38 import org.apache.struts.action.Action;
39 import org.apache.struts.action.ActionErrors;
40 import org.apache.struts.action.ActionForm;
41 import org.apache.struts.action.ActionForward;
42 import org.apache.struts.action.ActionMapping;
43 import org.apache.struts.util.MessageResources;
44 import org.apache.webapp.admin.ApplicationServlet;
45
46
47 /**
48  * <p>Implementation of <strong>Action</strong> that sets up and stashes
49  * a <code>EnvEntryForm</code> bean in request scope. The form bean will have
50  * a null <code>objectName</code> property if this form represents a EnvEntry
51  * being added, or a non-null value for an existing EnvEntry.</p>
52  *
53  * @author Manveen Kaur
54  * @version $Revision: 1.5 $ $Date: 2004/10/18 06:37:54 $
55  * @since 4.1
56  */

57
58 public final class SetUpEnvEntryAction extends Action {
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         // Set up the form bean based on the creating or editing state
102
String JavaDoc objectName = request.getParameter("objectName");
103         String JavaDoc resourcetype = request.getParameter("resourcetype");
104         String JavaDoc path = request.getParameter("path");
105         String JavaDoc host = request.getParameter("host");
106         String JavaDoc domain = request.getParameter("domain");
107         
108         EnvEntryForm envEntryForm = new EnvEntryForm();
109         envEntryForm.setResourcetype(resourcetype);
110         envEntryForm.setPath(path);
111         envEntryForm.setHost(host);
112         envEntryForm.setDomain(domain);
113         if (objectName == null) {
114             envEntryForm.setNodeLabel
115                 (resources.getMessage(locale, "resources.actions.env.create"));
116             envEntryForm.setObjectName(null);
117         } else {
118             envEntryForm.setNodeLabel
119                 (resources.getMessage(locale, "resources.actions.env.edit"));
120             envEntryForm.setObjectName(objectName);
121             
122             String JavaDoc attribute = null;
123             try {
124                 ObjectName JavaDoc oname = new ObjectName JavaDoc(objectName);
125                 attribute = "name";
126                 envEntryForm.setName
127                     ((String JavaDoc) mserver.getAttribute(oname, attribute));
128                 attribute = "type";
129                 envEntryForm.setEntryType
130                     ((String JavaDoc) mserver.getAttribute(oname, attribute));
131                 attribute = "value";
132                 envEntryForm.setValue
133                     ((String JavaDoc) mserver.getAttribute(oname, attribute));
134                 attribute = "override";
135                 envEntryForm.setOverride(
136                     ((Boolean JavaDoc) mserver.getAttribute(oname, attribute)).booleanValue());
137                 attribute = "description";
138                 envEntryForm.setDescription
139                     ((String JavaDoc) mserver.getAttribute(oname, attribute));
140             } catch (Exception JavaDoc e) {
141                 getServlet().log
142                     (resources.getMessage(locale,
143                         "users.error.attribute.get", attribute), e);
144                 response.sendError
145                     (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
146                      resources.getMessage
147                          (locale, "users.error.attribute.get", attribute));
148                 return (null);
149             }
150         }
151             
152         // Stash the form bean and forward to the display page
153
saveToken(request);
154         request.setAttribute("envEntryForm", envEntryForm);
155         return (mapping.findForward("EnvEntry"));
156
157     }
158 }
159
Popular Tags