ApplyDatasourcePropertiesAction.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: ApplyDatasourcePropertiesAction.java,v 1.8 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.WhereAreYou;
00041 import org.objectweb.jonas.webapp.jonasadmin.deploy.BaseDeployAction;
00042 
00047 public class ApplyDatasourcePropertiesAction extends BaseDeployAction {
00048 
00049 // --------------------------------------------------------- Public Methods
00050 
00051     public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
00052         , HttpServletRequest p_Request, HttpServletResponse p_Response)
00053         throws IOException, ServletException {
00054 
00055         // Form used
00056         DatasourcePropertiesForm oForm = (DatasourcePropertiesForm) p_Form;
00057         try {
00058             // populate and deploy (load resource)
00059             populate(oForm);
00060             // refresh tree
00061             m_WhereAreYou.setCurrentJonasDeploymentType(WhereAreYou.DEPLOYMENT_DATASOURCE);
00062             refreshTree(p_Request);
00063         }
00064         catch (Throwable t) {
00065             addGlobalError(t);
00066             saveErrors(p_Request, m_Errors);
00067             return (p_Mapping.findForward("Global Error"));
00068         }
00069         // Remove form
00070         m_Session.removeAttribute("datasourcePropertiesForm");
00071         // Forward to the jsp.
00072         return (p_Mapping.findForward("ActionListDatasources"));
00073     }
00074 
00075 // --------------------------------------------------------- Protected Methods
00076 
00077     private static final String DEF_CLASSNAME = "no class name";
00078     private static final String DEF_URL = "no url";
00079     private static final String DEF_DESCRIPTION = "no desc";
00080     private static final String DEF_USERNAME = "";
00081     private static final String DEF_PASSWORD = "";
00082     private static final String DEF_FACTORY = "none";
00083     private static final String DEF_MAPPERNAME = "rdb";
00084 
00085     protected void populate(DatasourcePropertiesForm p_Form)
00086         throws Exception {
00087         Properties oProps = new Properties();
00088         setStringAttribute(oProps, "datasource.name", p_Form.getDatasourceName());
00089         setStringAttribute(oProps, "datasource.description", p_Form.getDatasourceDescription()
00090             , DEF_DESCRIPTION);
00091         setStringAttribute(oProps, "datasource.url", p_Form.getDatasourceUrl(), DEF_URL);
00092         setStringAttribute(oProps, "datasource.classname", p_Form.getDatasourceClassname()
00093             , DEF_CLASSNAME);
00094         setStringAttribute(oProps, "datasource.username", p_Form.getDatasourceUsername()
00095             , DEF_USERNAME);
00096         setStringAttribute(oProps, "datasource.password", p_Form.getDatasourcePassword()
00097             , DEF_PASSWORD);
00098         setStringAttribute(oProps, "datasource.mapper", p_Form.getDatasourceMapper()
00099             , DEF_MAPPERNAME);
00100         setStringAttribute(oProps, "jdbc.connmaxage", p_Form.getJdbcConnmaxage());
00101         setStringAttribute(oProps, "jdbc.maxopentime", p_Form.getJdbcMaxopentime());
00102         setStringAttribute(oProps, "jdbc.connchecklevel", p_Form.getJdbcConnchecklevel());
00103         setStringAttribute(oProps, "jdbc.connteststmt", p_Form.getJdbcConnteststmt());
00104         setStringAttribute(oProps, "jdbc.minconpool", p_Form.getJdbcMinconpool());
00105         setStringAttribute(oProps, "jdbc.maxconpool", p_Form.getJdbcMaxconpool());
00106         setStringAttribute(oProps, "jdbc.maxwaittime", p_Form.getJdbcMaxwaittime());
00107         setStringAttribute(oProps, "jdbc.maxwaiters", p_Form.getJdbcMaxwaiters());
00108         setStringAttribute(oProps, "jdbc.samplingperiod", p_Form.getJdbcSamplingperiod());
00109 
00110         // Load Datasource
00111         Object[] aoParam = {
00112             p_Form.getName(), oProps, new Boolean(false)};
00113         String[] asSign_3 = {
00114             "java.lang.String", "java.util.Properties", "java.lang.Boolean"};
00115         JonasManagementRepr.invoke(JonasObjectName.databaseService(), "loadDataSource", aoParam
00116             , asSign_3);
00117 
00118     }
00119 }

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