KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webapp > admin > valve > SaveRequestDumperValveAction


1 /*
2  * Copyright 2001-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.valve;
18
19 import java.util.Locale JavaDoc;
20 import java.io.IOException JavaDoc;
21 import javax.management.Attribute JavaDoc;
22 import javax.management.MBeanServer JavaDoc;
23 import javax.management.MBeanServerFactory JavaDoc;
24 import javax.management.QueryExp JavaDoc;
25 import javax.management.Query JavaDoc;
26 import javax.management.ObjectName JavaDoc;
27 import javax.management.JMException JavaDoc;
28 import javax.servlet.ServletException JavaDoc;
29 import javax.servlet.http.HttpServletRequest JavaDoc;
30 import javax.servlet.http.HttpServletResponse JavaDoc;
31 import javax.servlet.http.HttpSession JavaDoc;
32 import org.apache.struts.action.Action;
33 import org.apache.struts.action.ActionError;
34 import org.apache.struts.action.ActionErrors;
35 import org.apache.struts.action.ActionForm;
36 import org.apache.struts.action.ActionForward;
37 import org.apache.struts.action.ActionMapping;
38 import org.apache.struts.util.MessageResources;
39 import org.apache.webapp.admin.ApplicationServlet;
40
41 /**
42  * The <code>Action</code> that completes <em>Add Valve</em> and
43  * <em>Edit Valve</em> transactions for Request Dumper valve.
44  *
45  * @author Manveen Kaur
46  * @version $Revision: 1.9 $ $Date: 2004/10/18 06:37:55 $
47  */

48
49 public final class SaveRequestDumperValveAction extends Action {
50
51
52     // ----------------------------------------------------- Instance Variables
53

54     /**
55      * The MBeanServer we will be interacting with.
56      */

57     private MBeanServer JavaDoc mBServer = null;
58     
59     // --------------------------------------------------------- Public Methods
60

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

77     public ActionForward execute(ActionMapping mapping,
78                                  ActionForm form,
79                                  HttpServletRequest JavaDoc request,
80                                  HttpServletResponse JavaDoc response)
81         throws IOException JavaDoc, ServletException JavaDoc {
82         
83         // Acquire the resources that we need
84
HttpSession JavaDoc session = request.getSession();
85         Locale JavaDoc locale = getLocale(request);
86         MessageResources resources = getResources(request);
87         
88         // Acquire a reference to the MBeanServer containing our MBeans
89
try {
90             mBServer = ((ApplicationServlet) getServlet()).getServer();
91         } catch (Throwable JavaDoc t) {
92             throw new ServletException JavaDoc
93             ("Cannot acquire MBeanServer reference", t);
94         }
95         
96         // Identify the requested action
97
RequestDumperValveForm vform = (RequestDumperValveForm) form;
98         String JavaDoc adminAction = vform.getAdminAction();
99         String JavaDoc vObjectName = vform.getObjectName();
100         String JavaDoc parent = vform.getParentObjectName();
101         String JavaDoc valveType = vform.getValveType();
102             
103         // Perform a "Create Valve" transaction (if requested)
104
if ("Create".equals(adminAction)) {
105         
106             vObjectName = ValveUtil.createValve(parent, valveType,
107                                 response, request, mapping,
108                                 (ApplicationServlet) getServlet());
109            
110         }
111
112         // Perform attribute updates as requested
113
String JavaDoc attribute = null;
114                 
115         // Forward to the success reporting page
116
session.removeAttribute(mapping.getAttribute());
117         return (mapping.findForward("Save Successful"));
118     }
119 }
120
Popular Tags