KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > jonasadmin > resource > EditDatasourcePropertiesAction


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: EditDatasourcePropertiesAction.java,v 1.9 2004/09/01 16:48:28 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.webapp.jonasadmin.resource;
27
28 import java.io.IOException JavaDoc;
29 import java.util.Properties JavaDoc;
30
31 import javax.servlet.ServletException JavaDoc;
32 import javax.servlet.http.HttpServletRequest JavaDoc;
33 import javax.servlet.http.HttpServletResponse JavaDoc;
34
35 import org.apache.struts.action.ActionForm;
36 import org.apache.struts.action.ActionForward;
37 import org.apache.struts.action.ActionMapping;
38 import org.objectweb.jonas.jmx.JonasManagementRepr;
39 import org.objectweb.jonas.jmx.JonasObjectName;
40 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
41
42 /**
43  * @author Michel-Ange ANTON
44  */

45
46 public class EditDatasourcePropertiesAction extends JonasBaseAction {
47
48 // --------------------------------------------------------- Public Methods
49

50     public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
51         , HttpServletRequest JavaDoc p_Request, HttpServletResponse JavaDoc p_Response)
52         throws IOException JavaDoc, ServletException JavaDoc {
53
54         // Datasource to create
55
String JavaDoc sAction = p_Request.getParameter("action");
56         if (sAction == null) {
57             sAction ="edit";
58         }
59         // Datasource to edit
60
String JavaDoc sName = p_Request.getParameter("name");
61
62         DatasourcePropertiesForm oForm = null;
63         oForm = new DatasourcePropertiesForm();
64         m_Session.setAttribute("datasourcePropertiesForm", oForm);
65         oForm.reset(p_Mapping, p_Request);
66         oForm.setAction(sAction);
67
68         // Populate
69
if (sName != null) {
70             try {
71                 populate(sName, oForm);
72             }
73             catch (Throwable JavaDoc t) {
74                 addGlobalError(t);
75                 saveErrors(p_Request, m_Errors);
76                 return (p_Mapping.findForward("Global Error"));
77             }
78         }
79         // Forward to the jsp.
80
return (p_Mapping.findForward("Datasource Properties"));
81     }
82
83 // --------------------------------------------------------- Protected Methods
84

85     protected void populate(String JavaDoc p_Name, DatasourcePropertiesForm p_Form)
86         throws Exception JavaDoc {
87
88         String JavaDoc[] asParam = new String JavaDoc[1];
89         String JavaDoc[] asSignature = new String JavaDoc[1];
90         asParam[0] = p_Name;
91         asSignature[0] = "java.lang.String";
92
93         Properties JavaDoc oProps = (Properties JavaDoc) JonasManagementRepr.invoke(JonasObjectName.databaseService()
94             , "getDataSourcePropertiesFile", asParam, asSignature);
95         // Populate
96
p_Form.setName(p_Name);
97         p_Form.setDatasourceName(getStringAttribute(oProps, "datasource.name"
98             , p_Form.getDatasourceName()));
99         p_Form.setDatasourceDescription(getStringAttribute(oProps, "datasource.description"
100             , p_Form.getDatasourceDescription()));
101         p_Form.setDatasourceUrl(getStringAttribute(oProps, "datasource.url"
102             , p_Form.getDatasourceUrl()));
103         p_Form.setDatasourceClassname(getStringAttribute(oProps, "datasource.classname"
104             , p_Form.getDatasourceClassname()));
105         p_Form.setDatasourceUsername(getStringAttribute(oProps, "datasource.username"
106             , p_Form.getDatasourceUsername()));
107         p_Form.setDatasourcePassword(getStringAttribute(oProps, "datasource.password"
108             , p_Form.getDatasourcePassword()));
109         p_Form.setDatasourceMapper(getStringAttribute(oProps, "datasource.mapper"
110             , p_Form.getDatasourceMapper()));
111         p_Form.setJdbcConnmaxage(getStringAttribute(oProps, "jdbc.connmaxage"
112             , p_Form.getJdbcConnmaxage()));
113         p_Form.setJdbcMaxopentime(getStringAttribute(oProps, "jdbc.maxopentime"
114             , p_Form.getJdbcMaxopentime()));
115         p_Form.setJdbcConnchecklevel(getStringAttribute(oProps, "jdbc.connchecklevel"
116             , p_Form.getJdbcConnchecklevel()));
117         p_Form.setJdbcConnteststmt(getStringAttribute(oProps, "jdbc.connteststmt"
118             , p_Form.getJdbcConnteststmt()));
119         p_Form.setJdbcMinconpool(getStringAttribute(oProps, "jdbc.minconpool"
120             , p_Form.getJdbcMinconpool()));
121         p_Form.setJdbcMaxconpool(getStringAttribute(oProps, "jdbc.maxconpool"
122             , p_Form.getJdbcMaxconpool()));
123         p_Form.setJdbcMaxwaittime(getStringAttribute(oProps, "jdbc.maxwaittime"
124             , p_Form.getJdbcMaxwaittime()));
125         p_Form.setJdbcMaxwaiters(getStringAttribute(oProps, "jdbc.maxwaiters"
126             , p_Form.getJdbcMaxwaiters()));
127         p_Form.setJdbcSamplingperiod(getStringAttribute(oProps, "jdbc.samplingperiod"
128             , p_Form.getJdbcSamplingperiod()));
129     }
130 }
131
Popular Tags