KickJava   Java API By Example, From Geeks To Geeks.

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


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.apache.struts.action.ActionForward;
19 import org.apache.struts.action.ActionMapping;
20 import org.apache.struts.action.ActionForm;
21 import org.jmanage.webui.util.WebContext;
22 import org.jmanage.webui.util.Forwards;
23 import org.jmanage.webui.util.RequestParams;
24 import org.jmanage.webui.util.Utils;
25 import org.jmanage.webui.forms.GraphForm;
26 import org.jmanage.webui.actions.BaseAction;
27 import org.jmanage.core.config.ApplicationConfig;
28 import org.jmanage.core.config.GraphConfig;
29 import org.jmanage.core.config.GraphAttributeConfig;
30 import org.jmanage.core.services.ConfigurationService;
31 import org.jmanage.core.services.ServiceFactory;
32 import org.jmanage.core.util.Expression;
33
34 import javax.servlet.http.HttpServletRequest JavaDoc;
35 import javax.servlet.http.HttpServletResponse JavaDoc;
36 import java.util.List JavaDoc;
37 import java.util.ArrayList JavaDoc;
38
39 /**
40  * Date: Jun 23, 2005 8:03:09 PM
41  * @author Bhavana
42  */

43 public class AddGraphAction extends BaseAction{
44     /**
45      * @param context
46      * @param mapping
47      * @param actionForm
48      * @param request
49      * @param response
50      * @return
51      * @throws Exception
52      */

53     public ActionForward execute(WebContext context,
54                                  ActionMapping mapping,
55                                  ActionForm actionForm,
56                                  HttpServletRequest JavaDoc request,
57                                  HttpServletResponse JavaDoc response)
58             throws Exception JavaDoc {
59
60         ApplicationConfig appConfig = context.getApplicationConfig();
61         GraphForm form = (GraphForm)actionForm;
62         String JavaDoc[] attributes = form.getAttributes();
63         String JavaDoc[] displayNames = request.getParameterValues("displayNames");
64         List JavaDoc graphAttrConfigs = new ArrayList JavaDoc(attributes.length);
65         for(int i=0; i<attributes.length; i++){
66             Expression expression = new Expression(attributes[i]);
67             GraphAttributeConfig graphAttrConfig = new GraphAttributeConfig(
68                     expression.getMBeanName(),expression.getTargetName(),
69                     displayNames[i]);
70             graphAttrConfigs.add(graphAttrConfig);
71         }
72         String JavaDoc graphId = request.getParameter(RequestParams.GRAPH_ID);
73         GraphConfig graphConfig = null;
74         if(graphId==null || graphId.equals("")){
75             graphConfig = new GraphConfig(GraphConfig.getNextGraphId(),
76                     form.getGraphName(), Long.parseLong(form.getPollInterval()),
77                     appConfig, graphAttrConfigs);
78             graphConfig.setYAxisLabel(form.getYAxisLabel());
79             if(form.getScaleFactor() != null){
80                 graphConfig.setScaleFactor(new Double JavaDoc(form.getScaleFactor()));
81                 graphConfig.setScaleUp(Boolean.valueOf(form.getScaleUp()));
82             }
83             appConfig.addGraph(graphConfig);
84         }else{
85             graphConfig = appConfig.findGraph(graphId);
86             graphConfig.setName(form.getGraphName());
87             graphConfig.setAttributes(graphAttrConfigs);
88             graphConfig.setPollingInterval(Long.parseLong(form.getPollInterval()));
89             graphConfig.setYAxisLabel(form.getYAxisLabel());
90             if(form.getScaleFactor() != null){
91                 graphConfig.setScaleFactor(new Double JavaDoc(form.getScaleFactor()));
92                 graphConfig.setScaleUp(Boolean.valueOf(form.getScaleUp()));
93             }else{
94                 graphConfig.setScaleFactor(null);
95                 graphConfig.setScaleUp(null);
96             }
97             graphConfig.setAppConfig(appConfig);
98         }
99
100         ConfigurationService service = ServiceFactory.getConfigurationService();
101         service.addGraph(Utils.getServiceContext(context), graphConfig);
102         return mapping.findForward(Forwards.SUCCESS);
103     }
104 }
105
Popular Tags