001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: EditDatasourcePropertiesAction.java 9680 2006-10-06 12:08:33Z danesa $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.webapp.jonasadmin.resource;
027:
028: import java.io.IOException;
029: import java.util.Properties;
030:
031: import javax.servlet.ServletException;
032: import javax.servlet.http.HttpServletRequest;
033: import javax.servlet.http.HttpServletResponse;
034:
035: import org.apache.struts.action.ActionForm;
036: import org.apache.struts.action.ActionForward;
037: import org.apache.struts.action.ActionMapping;
038: import org.objectweb.jonas.jmx.JonasManagementRepr;
039: import org.objectweb.jonas.jmx.JonasObjectName;
040: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
041:
042: /**
043: * @author Michel-Ange ANTON
044: */
045:
046: public class EditDatasourcePropertiesAction extends JonasBaseAction {
047:
048: // --------------------------------------------------------- Public Methods
049:
050: public ActionForward executeAction(ActionMapping p_Mapping,
051: ActionForm p_Form, HttpServletRequest p_Request,
052: HttpServletResponse p_Response) throws IOException,
053: ServletException {
054:
055: // Current server
056: String serverName = m_WhereAreYou.getCurrentJonasServerName();
057:
058: // Datasource to create
059: String sAction = p_Request.getParameter("action");
060: if (sAction == null) {
061: sAction = "edit";
062: }
063: // Datasource to edit
064: String sName = p_Request.getParameter("name");
065:
066: DatasourcePropertiesForm oForm = null;
067: oForm = new DatasourcePropertiesForm();
068: m_Session.setAttribute("datasourcePropertiesForm", oForm);
069: oForm.reset(p_Mapping, p_Request);
070: oForm.setAction(sAction);
071:
072: // Populate
073: if (sName != null) {
074: try {
075: populate(sName, oForm, serverName);
076: } catch (Throwable t) {
077: addGlobalError(t);
078: saveErrors(p_Request, m_Errors);
079: return (p_Mapping.findForward("Global Error"));
080: }
081: }
082: // Forward to the jsp.
083: return (p_Mapping.findForward("Datasource Properties"));
084: }
085:
086: // --------------------------------------------------------- Protected Methods
087:
088: protected void populate(String p_Name,
089: DatasourcePropertiesForm p_Form, String serverName)
090: throws Exception {
091:
092: String[] asParam = new String[1];
093: String[] asSignature = new String[1];
094: asParam[0] = p_Name;
095: asSignature[0] = "java.lang.String";
096:
097: Properties oProps = (Properties) JonasManagementRepr.invoke(
098: JonasObjectName.databaseService(),
099: "getDataSourcePropertiesFile", asParam, asSignature,
100: serverName);
101: // Populate
102: p_Form.setName(p_Name);
103: p_Form.setDatasourceName(getStringAttribute(oProps,
104: "datasource.name", p_Form.getDatasourceName()));
105: p_Form.setDatasourceDescription(getStringAttribute(oProps,
106: "datasource.description", p_Form
107: .getDatasourceDescription()));
108: p_Form.setDatasourceUrl(getStringAttribute(oProps,
109: "datasource.url", p_Form.getDatasourceUrl()));
110: p_Form
111: .setDatasourceClassname(getStringAttribute(oProps,
112: "datasource.classname", p_Form
113: .getDatasourceClassname()));
114: p_Form.setDatasourceUsername(getStringAttribute(oProps,
115: "datasource.username", p_Form.getDatasourceUsername()));
116: p_Form.setDatasourcePassword(getStringAttribute(oProps,
117: "datasource.password", p_Form.getDatasourcePassword()));
118: p_Form.setDatasourceMapper(getStringAttribute(oProps,
119: "datasource.mapper", p_Form.getDatasourceMapper()));
120: p_Form.setJdbcConnmaxage(getStringAttribute(oProps,
121: "jdbc.connmaxage", p_Form.getJdbcConnmaxage()));
122: p_Form.setJdbcMaxopentime(getStringAttribute(oProps,
123: "jdbc.maxopentime", p_Form.getJdbcMaxopentime()));
124: p_Form.setJdbcConnchecklevel(getStringAttribute(oProps,
125: "jdbc.connchecklevel", p_Form.getJdbcConnchecklevel()));
126: p_Form.setJdbcConnteststmt(getStringAttribute(oProps,
127: "jdbc.connteststmt", p_Form.getJdbcConnteststmt()));
128: p_Form.setJdbcMinconpool(getStringAttribute(oProps,
129: "jdbc.minconpool", p_Form.getJdbcMinconpool()));
130: p_Form.setJdbcMaxconpool(getStringAttribute(oProps,
131: "jdbc.maxconpool", p_Form.getJdbcMaxconpool()));
132: p_Form.setJdbcMaxwaittime(getStringAttribute(oProps,
133: "jdbc.maxwaittime", p_Form.getJdbcMaxwaittime()));
134: p_Form.setJdbcMaxwaiters(getStringAttribute(oProps,
135: "jdbc.maxwaiters", p_Form.getJdbcMaxwaiters()));
136: p_Form.setJdbcSamplingperiod(getStringAttribute(oProps,
137: "jdbc.samplingperiod", p_Form.getJdbcSamplingperiod()));
138: }
139: }
|