EditDatasourcePropertiesAction.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  * --------------------------------------------------------------------------
00022  * $Id: EditDatasourcePropertiesAction.java,v 1.9 2004/09/01 16:48:28 durieuxp Exp $
00023  * --------------------------------------------------------------------------
00024  */
00025 
00026 package org.objectweb.jonas.webapp.jonasadmin.resource;
00027 
00028 import java.io.IOException;
00029 import java.util.Properties;
00030 
00031 import javax.servlet.ServletException;
00032 import javax.servlet.http.HttpServletRequest;
00033 import javax.servlet.http.HttpServletResponse;
00034 
00035 import org.apache.struts.action.ActionForm;
00036 import org.apache.struts.action.ActionForward;
00037 import org.apache.struts.action.ActionMapping;
00038 import org.objectweb.jonas.jmx.JonasManagementRepr;
00039 import org.objectweb.jonas.jmx.JonasObjectName;
00040 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
00041 
00046 public class EditDatasourcePropertiesAction extends JonasBaseAction {
00047 
00048 // --------------------------------------------------------- Public Methods
00049 
00050     public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
00051         , HttpServletRequest p_Request, HttpServletResponse p_Response)
00052         throws IOException, ServletException {
00053 
00054         // Datasource to create
00055         String sAction = p_Request.getParameter("action");
00056         if (sAction == null) {
00057             sAction ="edit";
00058         }
00059         // Datasource to edit
00060         String sName = p_Request.getParameter("name");
00061 
00062         DatasourcePropertiesForm oForm = null;
00063         oForm = new DatasourcePropertiesForm();
00064         m_Session.setAttribute("datasourcePropertiesForm", oForm);
00065         oForm.reset(p_Mapping, p_Request);
00066         oForm.setAction(sAction);
00067 
00068         // Populate
00069         if (sName != null) {
00070             try {
00071                 populate(sName, oForm);
00072             }
00073             catch (Throwable t) {
00074                 addGlobalError(t);
00075                 saveErrors(p_Request, m_Errors);
00076                 return (p_Mapping.findForward("Global Error"));
00077             }
00078         }
00079         // Forward to the jsp.
00080         return (p_Mapping.findForward("Datasource Properties"));
00081     }
00082 
00083 // --------------------------------------------------------- Protected Methods
00084 
00085     protected void populate(String p_Name, DatasourcePropertiesForm p_Form)
00086         throws Exception {
00087 
00088         String[] asParam = new String[1];
00089         String[] asSignature = new String[1];
00090         asParam[0] = p_Name;
00091         asSignature[0] = "java.lang.String";
00092 
00093         Properties oProps = (Properties) JonasManagementRepr.invoke(JonasObjectName.databaseService()
00094             , "getDataSourcePropertiesFile", asParam, asSignature);
00095         // Populate
00096         p_Form.setName(p_Name);
00097         p_Form.setDatasourceName(getStringAttribute(oProps, "datasource.name"
00098             , p_Form.getDatasourceName()));
00099         p_Form.setDatasourceDescription(getStringAttribute(oProps, "datasource.description"
00100             , p_Form.getDatasourceDescription()));
00101         p_Form.setDatasourceUrl(getStringAttribute(oProps, "datasource.url"
00102             , p_Form.getDatasourceUrl()));
00103         p_Form.setDatasourceClassname(getStringAttribute(oProps, "datasource.classname"
00104             , p_Form.getDatasourceClassname()));
00105         p_Form.setDatasourceUsername(getStringAttribute(oProps, "datasource.username"
00106             , p_Form.getDatasourceUsername()));
00107         p_Form.setDatasourcePassword(getStringAttribute(oProps, "datasource.password"
00108             , p_Form.getDatasourcePassword()));
00109         p_Form.setDatasourceMapper(getStringAttribute(oProps, "datasource.mapper"
00110             , p_Form.getDatasourceMapper()));
00111         p_Form.setJdbcConnmaxage(getStringAttribute(oProps, "jdbc.connmaxage"
00112             , p_Form.getJdbcConnmaxage()));
00113         p_Form.setJdbcMaxopentime(getStringAttribute(oProps, "jdbc.maxopentime"
00114             , p_Form.getJdbcMaxopentime()));
00115         p_Form.setJdbcConnchecklevel(getStringAttribute(oProps, "jdbc.connchecklevel"
00116             , p_Form.getJdbcConnchecklevel()));
00117         p_Form.setJdbcConnteststmt(getStringAttribute(oProps, "jdbc.connteststmt"
00118             , p_Form.getJdbcConnteststmt()));
00119         p_Form.setJdbcMinconpool(getStringAttribute(oProps, "jdbc.minconpool"
00120             , p_Form.getJdbcMinconpool()));
00121         p_Form.setJdbcMaxconpool(getStringAttribute(oProps, "jdbc.maxconpool"
00122             , p_Form.getJdbcMaxconpool()));
00123         p_Form.setJdbcMaxwaittime(getStringAttribute(oProps, "jdbc.maxwaittime"
00124             , p_Form.getJdbcMaxwaittime()));
00125         p_Form.setJdbcMaxwaiters(getStringAttribute(oProps, "jdbc.maxwaiters"
00126             , p_Form.getJdbcMaxwaiters()));
00127         p_Form.setJdbcSamplingperiod(getStringAttribute(oProps, "jdbc.samplingperiod"
00128             , p_Form.getJdbcSamplingperiod()));
00129     }
00130 }

Generated on Tue Feb 15 15:05:30 2005 for JOnAS by  doxygen 1.3.9.1