KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > webui > actions > config > ShowAddAlertAction


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.config;
17
18 import org.jmanage.webui.actions.BaseAction;
19 import org.jmanage.webui.util.*;
20 import org.jmanage.webui.forms.AlertForm;
21 import org.jmanage.core.config.ApplicationConfigManager;
22 import org.jmanage.core.config.AlertSourceConfig;
23 import org.jmanage.core.util.Expression;
24 import org.jmanage.core.services.AccessController;
25 import org.jmanage.core.services.MBeanService;
26 import org.jmanage.core.services.ServiceFactory;
27 import org.jmanage.core.management.ObjectAttribute;
28 import org.apache.struts.action.ActionForward;
29 import org.apache.struts.action.ActionMapping;
30 import org.apache.struts.action.ActionForm;
31
32 import javax.servlet.http.HttpServletRequest JavaDoc;
33 import javax.servlet.http.HttpServletResponse JavaDoc;
34
35 /**
36  * Date: May 26, 2005 4:16:42 PM
37  * @author Bhavana
38  */

39 public class ShowAddAlertAction extends BaseAction{
40     /**
41      * Get all configured alert delivery mechanism
42      *
43      * @param context
44      * @param mapping
45      * @param actionForm
46      * @param request
47      * @param response
48      * @return
49      * @throws Exception
50      */

51     public ActionForward execute(WebContext context,
52                                  ActionMapping mapping,
53                                  ActionForm actionForm,
54                                  HttpServletRequest JavaDoc request,
55                                  HttpServletResponse JavaDoc response)
56             throws Exception JavaDoc {
57
58         AccessController.checkAccess(Utils.getServiceContext(context), ACL_ADD_ALERT);
59         AlertForm alertForm = (AlertForm)actionForm;
60         String JavaDoc sourceType = request.getParameter(RequestParams.ALERT_SOURCE_TYPE);
61         request.setAttribute("alertSourceType",
62                             sourceType);
63         if(sourceType.equals(AlertSourceConfig.SOURCE_TYPE_NOTIFICATION)){
64             Expression expr = new Expression(alertForm.getExpression());
65             request.setAttribute("sourceMBean", expr.getMBeanName());
66             request.setAttribute("notificationType", expr.getTargetName());
67         }else if(sourceType.equals(AlertSourceConfig.SOURCE_TYPE_GAUGE_MONITOR)
68                 || sourceType.equals(AlertSourceConfig.SOURCE_TYPE_STRING_MONITOR)){
69             Expression expr = new Expression(alertForm.getExpression());
70             request.setAttribute("sourceMBean", expr.getMBeanName());
71             request.setAttribute("attribute", expr.getTargetName());
72             MBeanService mbeanService = ServiceFactory.getMBeanService();
73             ObjectAttribute objAttr = mbeanService.getObjectAttribute(
74                     Utils.getServiceContext(context, expr),
75                     expr.getTargetName());
76             request.setAttribute("currentAttrValue",
77                     objAttr.getDisplayValue());
78
79         }
80
81         request.setAttribute("applications",
82                 ApplicationConfigManager.getAllApplications());
83         /*set current page for navigation*/
84         request.setAttribute(RequestAttributes.NAV_CURRENT_PAGE, "Add Alert");
85         return mapping.findForward(Forwards.SUCCESS);
86     }
87 }
88
Popular Tags