KickJava   Java API By Example, From Geeks To Geeks.

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


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: ApplyDatasourcePropertiesAction.java,v 1.8 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.WhereAreYou;
41 import org.objectweb.jonas.webapp.jonasadmin.deploy.BaseDeployAction;
42
43 /**
44  * @author Michel-Ange ANTON
45  */

46
47 public class ApplyDatasourcePropertiesAction extends BaseDeployAction {
48
49 // --------------------------------------------------------- Public Methods
50

51     public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
52         , HttpServletRequest JavaDoc p_Request, HttpServletResponse JavaDoc p_Response)
53         throws IOException JavaDoc, ServletException JavaDoc {
54
55         // Form used
56
DatasourcePropertiesForm oForm = (DatasourcePropertiesForm) p_Form;
57         try {
58             // populate and deploy (load resource)
59
populate(oForm);
60             // refresh tree
61
m_WhereAreYou.setCurrentJonasDeploymentType(WhereAreYou.DEPLOYMENT_DATASOURCE);
62             refreshTree(p_Request);
63         }
64         catch (Throwable JavaDoc t) {
65             addGlobalError(t);
66             saveErrors(p_Request, m_Errors);
67             return (p_Mapping.findForward("Global Error"));
68         }
69         // Remove form
70
m_Session.removeAttribute("datasourcePropertiesForm");
71         // Forward to the jsp.
72
return (p_Mapping.findForward("ActionListDatasources"));
73     }
74
75 // --------------------------------------------------------- Protected Methods
76

77     private static final String JavaDoc DEF_CLASSNAME = "no class name";
78     private static final String JavaDoc DEF_URL = "no url";
79     private static final String JavaDoc DEF_DESCRIPTION = "no desc";
80     private static final String JavaDoc DEF_USERNAME = "";
81     private static final String JavaDoc DEF_PASSWORD = "";
82     private static final String JavaDoc DEF_FACTORY = "none";
83     private static final String JavaDoc DEF_MAPPERNAME = "rdb";
84
85     protected void populate(DatasourcePropertiesForm p_Form)
86         throws Exception JavaDoc {
87         Properties JavaDoc oProps = new Properties JavaDoc();
88         setStringAttribute(oProps, "datasource.name", p_Form.getDatasourceName());
89         setStringAttribute(oProps, "datasource.description", p_Form.getDatasourceDescription()
90             , DEF_DESCRIPTION);
91         setStringAttribute(oProps, "datasource.url", p_Form.getDatasourceUrl(), DEF_URL);
92         setStringAttribute(oProps, "datasource.classname", p_Form.getDatasourceClassname()
93             , DEF_CLASSNAME);
94         setStringAttribute(oProps, "datasource.username", p_Form.getDatasourceUsername()
95             , DEF_USERNAME);
96         setStringAttribute(oProps, "datasource.password", p_Form.getDatasourcePassword()
97             , DEF_PASSWORD);
98         setStringAttribute(oProps, "datasource.mapper", p_Form.getDatasourceMapper()
99             , DEF_MAPPERNAME);
100         setStringAttribute(oProps, "jdbc.connmaxage", p_Form.getJdbcConnmaxage());
101         setStringAttribute(oProps, "jdbc.maxopentime", p_Form.getJdbcMaxopentime());
102         setStringAttribute(oProps, "jdbc.connchecklevel", p_Form.getJdbcConnchecklevel());
103         setStringAttribute(oProps, "jdbc.connteststmt", p_Form.getJdbcConnteststmt());
104         setStringAttribute(oProps, "jdbc.minconpool", p_Form.getJdbcMinconpool());
105         setStringAttribute(oProps, "jdbc.maxconpool", p_Form.getJdbcMaxconpool());
106         setStringAttribute(oProps, "jdbc.maxwaittime", p_Form.getJdbcMaxwaittime());
107         setStringAttribute(oProps, "jdbc.maxwaiters", p_Form.getJdbcMaxwaiters());
108         setStringAttribute(oProps, "jdbc.samplingperiod", p_Form.getJdbcSamplingperiod());
109
110         // Load Datasource
111
Object JavaDoc[] aoParam = {
112             p_Form.getName(), oProps, new Boolean JavaDoc(false)};
113         String JavaDoc[] asSign_3 = {
114             "java.lang.String", "java.util.Properties", "java.lang.Boolean"};
115         JonasManagementRepr.invoke(JonasObjectName.databaseService(), "loadDataSource", aoParam
116             , asSign_3);
117
118     }
119 }
120
Popular Tags