00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00049
00050 public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
00051 , HttpServletRequest p_Request, HttpServletResponse p_Response)
00052 throws IOException, ServletException {
00053
00054
00055 String sAction = p_Request.getParameter("action");
00056 if (sAction == null) {
00057 sAction ="edit";
00058 }
00059
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
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
00080 return (p_Mapping.findForward("Datasource Properties"));
00081 }
00082
00083
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
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 }