KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webapp > admin > users > SetUpRoleAction


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

59
60 public final class SetUpRoleAction extends Action {
61
62
63     // ----------------------------------------------------- Instance Variables
64

65
66     /**
67      * The MBeanServer we will be interacting with.
68      */

69     private MBeanServer JavaDoc mserver = null;
70
71
72     // --------------------------------------------------------- Public Methods
73

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

90     public ActionForward execute(ActionMapping mapping,
91                                  ActionForm form,
92                                  HttpServletRequest JavaDoc request,
93                                  HttpServletResponse JavaDoc response)
94         throws IOException JavaDoc, ServletException JavaDoc {
95
96         // Look up the components we will be using as needed
97
if (mserver == null) {
98             mserver = ((ApplicationServlet) getServlet()).getServer();
99         }
100         MessageResources resources = getResources(request);
101         HttpSession JavaDoc session = request.getSession();
102         Locale JavaDoc locale = getLocale(request);
103         String JavaDoc databaseName =
104             URLDecoder.decode(request.getParameter("databaseName"),TomcatTreeBuilder.URL_ENCODING);
105
106         // Set up the form bean based on the creating or editing state
107
String JavaDoc objectName = request.getParameter("objectName");
108         RoleForm roleForm = new RoleForm();
109         if (objectName == null) {
110             roleForm.setNodeLabel
111                 (resources.getMessage(locale, "users.role.newRole"));
112             roleForm.setObjectName(null);
113         } else {
114             roleForm.setNodeLabel
115                 (resources.getMessage(locale, "users.role.oldRole"));
116             roleForm.setObjectName(objectName);
117             String JavaDoc attribute = null;
118             try {
119                 ObjectName JavaDoc oname = new ObjectName JavaDoc(objectName);
120                 attribute = "rolename";
121                 roleForm.setRolename
122                     ((String JavaDoc) mserver.getAttribute(oname, attribute));
123                 attribute = "description";
124                 roleForm.setDescription
125                     ((String JavaDoc) mserver.getAttribute(oname, attribute));
126             } catch (Exception JavaDoc e) {
127                 getServlet().log
128                     (resources.getMessage(locale,
129                         "users.error.attribute.get", attribute), e);
130                 response.sendError
131                     (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
132                      resources.getMessage
133                          (locale, "users.error.attribute.get", attribute));
134                 return (null);
135             }
136         }
137         roleForm.setDatabaseName(databaseName);
138
139         // Stash the form bean and forward to the display page
140
saveToken(request);
141         request.setAttribute("roleForm", roleForm);
142         return (mapping.findForward("Role"));
143
144     }
145
146 }
147
Popular Tags