KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > webui > actions > app > ExecuteMBeanOperationAction


1 /**
2  * Copyright 2004-2005 jManage.org
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 package org.jmanage.webui.actions.app;
17
18 import org.apache.struts.action.ActionForm;
19 import org.apache.struts.action.ActionForward;
20 import org.apache.struts.action.ActionMapping;
21 import org.jmanage.core.data.OperationResultData;
22 import org.jmanage.core.services.MBeanService;
23 import org.jmanage.core.services.ServiceFactory;
24 import org.jmanage.core.util.Loggers;
25 import org.jmanage.core.management.ObjectOperationInfo;
26 import org.jmanage.webui.actions.BaseAction;
27 import org.jmanage.webui.util.Forwards;
28 import org.jmanage.webui.util.Utils;
29 import org.jmanage.webui.util.WebContext;
30 import org.jmanage.webui.util.RequestAttributes;
31
32 import javax.servlet.http.HttpServletRequest JavaDoc;
33 import javax.servlet.http.HttpServletResponse JavaDoc;
34 import java.util.logging.Logger JavaDoc;
35
36 /**
37  * Executes mbean operation for Application as well as Application Cluster.
38  *
39  * date: Jun 21, 2004
40  * @author Rakesh Kalra
41  */

42 public class ExecuteMBeanOperationAction extends BaseAction {
43
44     private static final Logger JavaDoc logger =
45             Loggers.getLogger(ExecuteMBeanOperationAction.class);
46
47     public ActionForward execute(WebContext context,
48                                  ActionMapping mapping,
49                                  ActionForm actionForm,
50                                  HttpServletRequest JavaDoc request,
51                                  HttpServletResponse JavaDoc response)
52         throws Exception JavaDoc{
53
54         /* get the information about the operation to be executed */
55         final String JavaDoc operationName = request.getParameter("operationName");
56         final int paramCount =
57                 Integer.parseInt(request.getParameter("paramCount"));
58         String JavaDoc[] params = new String JavaDoc[paramCount];
59         String JavaDoc[] signature = new String JavaDoc[paramCount];
60         for(int paramIndex=0; paramIndex < paramCount; paramIndex ++){
61             params[paramIndex] =
62                     request.getParameter(operationName + paramIndex + "_value");
63             signature[paramIndex] =
64                     request.getParameter(operationName + paramIndex + "_type");
65         }
66
67         MBeanService service = ServiceFactory.getMBeanService();
68         ObjectOperationInfo operationInfo = service.getOperationInfo(
69                 Utils.getServiceContext(context),
70                 operationName, signature);
71         OperationResultData[] resultData =
72                 service.invoke(Utils.getServiceContext(context),
73                         operationName,
74                         params, signature);
75         request.setAttribute("operationResultData", resultData);
76         request.setAttribute("operationInfo", operationInfo);
77
78         /*set current page for navigation*/
79         request.setAttribute(RequestAttributes.NAV_CURRENT_PAGE, "Execute Operation");
80         return mapping.findForward(Forwards.SUCCESS);
81     }
82 }
83
Popular Tags