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: ApplyDatasourcePropertiesAction.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.WhereAreYou;
041: import org.objectweb.jonas.webapp.jonasadmin.deploy.BaseDeployAction;
042:
043: /**
044: * @author Michel-Ange ANTON
045: */
046:
047: public class ApplyDatasourcePropertiesAction extends BaseDeployAction {
048:
049: // --------------------------------------------------------- Public Methods
050:
051: public ActionForward executeAction(ActionMapping p_Mapping,
052: ActionForm p_Form, HttpServletRequest p_Request,
053: HttpServletResponse p_Response) throws IOException,
054: ServletException {
055:
056: // Current server
057: String serverName = m_WhereAreYou.getCurrentJonasServerName();
058:
059: // Form used
060: DatasourcePropertiesForm oForm = (DatasourcePropertiesForm) p_Form;
061: try {
062: // populate and deploy (load resource)
063: populate(oForm, serverName);
064: // refresh tree
065: m_WhereAreYou
066: .setCurrentJonasDeploymentType(WhereAreYou.DEPLOYMENT_DATASOURCE);
067: refreshTree(p_Request);
068: } catch (Throwable t) {
069: addGlobalError(t);
070: saveErrors(p_Request, m_Errors);
071: return (p_Mapping.findForward("Global Error"));
072: }
073: // Remove form
074: m_Session.removeAttribute("datasourcePropertiesForm");
075: // Forward to the jsp.
076: return (p_Mapping.findForward("ActionListDatasources"));
077: }
078:
079: // --------------------------------------------------------- Protected Methods
080:
081: private static final String DEF_CLASSNAME = "no class name";
082: private static final String DEF_URL = "no url";
083: private static final String DEF_DESCRIPTION = "no desc";
084: private static final String DEF_USERNAME = "";
085: private static final String DEF_PASSWORD = "";
086: private static final String DEF_FACTORY = "none";
087: private static final String DEF_MAPPERNAME = "rdb";
088:
089: protected void populate(DatasourcePropertiesForm p_Form,
090: String serverName) throws Exception {
091: Properties oProps = new Properties();
092: setStringAttribute(oProps, "datasource.name", p_Form
093: .getDatasourceName());
094: setStringAttribute(oProps, "datasource.description", p_Form
095: .getDatasourceDescription(), DEF_DESCRIPTION);
096: setStringAttribute(oProps, "datasource.url", p_Form
097: .getDatasourceUrl(), DEF_URL);
098: setStringAttribute(oProps, "datasource.classname", p_Form
099: .getDatasourceClassname(), DEF_CLASSNAME);
100: setStringAttribute(oProps, "datasource.username", p_Form
101: .getDatasourceUsername(), DEF_USERNAME);
102: setStringAttribute(oProps, "datasource.password", p_Form
103: .getDatasourcePassword(), DEF_PASSWORD);
104: setStringAttribute(oProps, "datasource.mapper", p_Form
105: .getDatasourceMapper(), DEF_MAPPERNAME);
106: setStringAttribute(oProps, "jdbc.connmaxage", p_Form
107: .getJdbcConnmaxage());
108: setStringAttribute(oProps, "jdbc.maxopentime", p_Form
109: .getJdbcMaxopentime());
110: setStringAttribute(oProps, "jdbc.connchecklevel", p_Form
111: .getJdbcConnchecklevel());
112: setStringAttribute(oProps, "jdbc.connteststmt", p_Form
113: .getJdbcConnteststmt());
114: setStringAttribute(oProps, "jdbc.minconpool", p_Form
115: .getJdbcMinconpool());
116: setStringAttribute(oProps, "jdbc.maxconpool", p_Form
117: .getJdbcMaxconpool());
118: setStringAttribute(oProps, "jdbc.maxwaittime", p_Form
119: .getJdbcMaxwaittime());
120: setStringAttribute(oProps, "jdbc.maxwaiters", p_Form
121: .getJdbcMaxwaiters());
122: setStringAttribute(oProps, "jdbc.samplingperiod", p_Form
123: .getJdbcSamplingperiod());
124:
125: // Load Datasource
126: Object[] aoParam = { p_Form.getName(), oProps,
127: new Boolean(false) };
128: String[] asSign_3 = { "java.lang.String",
129: "java.util.Properties", "java.lang.Boolean" };
130: JonasManagementRepr.invoke(JonasObjectName.databaseService(),
131: "loadDataSource", aoParam, asSign_3, serverName);
132:
133: }
134: }
|