001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999-2004 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: ApplyResourceAdapterAction.java 9680 2006-10-06 12:08:33Z danesa $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.webapp.jonasadmin.service.resource;
025:
026: import java.io.IOException;
027: import java.util.HashMap;
028:
029: import javax.management.ObjectName;
030: import javax.servlet.ServletException;
031: import javax.servlet.http.HttpServletRequest;
032: import javax.servlet.http.HttpServletResponse;
033:
034: import org.apache.struts.action.ActionForm;
035: import org.apache.struts.action.ActionForward;
036: import org.apache.struts.action.ActionMapping;
037: import org.apache.struts.action.ActionMessage;
038: import org.objectweb.jonas.jmx.JonasManagementRepr;
039: import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
040: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
041:
042: /**
043: * @author Eric Hardesty
044: */
045:
046: public class ApplyResourceAdapterAction 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: // Form used
056: ResourceAdapterForm oForm = (ResourceAdapterForm) p_Form;
057: try {
058: String domainName = m_WhereAreYou.getCurrentDomainName();
059: String serverName = m_WhereAreYou
060: .getCurrentJonasServerName();
061: populate(oForm);
062: if (oForm.getAction().equals("save") == true) {
063: save(oForm, domainName, serverName);
064: }
065: } catch (Throwable t) {
066: addGlobalError(t);
067: saveErrors(p_Request, m_Errors);
068: return (p_Mapping.findForward("Global Error"));
069: }
070: // Forward to the jsp and add the parameter 'name' with the good value.
071: return new ActionForward(p_Mapping.findForward(
072: "ActionEditResourceAdapter").getPath()
073: + "?select=" + oForm.getOName());
074: }
075:
076: // --------------------------------------------------------- Protected Methods
077:
078: protected void populate(ResourceAdapterForm p_Form)
079: throws Exception {
080: // Object name used
081: String cf = p_Form.getConnectionFactory();
082: ObjectName oObjectName = ObjectName.getInstance(cf);
083: // Populate
084: setIntegerAttribute(oObjectName, "jdbcConnCheckLevel", p_Form
085: .getJdbcConnCheckLevel());
086: setIntegerAttribute(oObjectName, "connMaxAge", p_Form
087: .getConnMaxAge());
088: setIntegerAttribute(oObjectName, "maxOpentime", p_Form
089: .getMaxOpentime());
090: setStringAttribute(oObjectName, "jdbcTestStatement", p_Form
091: .getJdbcTestStatement());
092: setIntegerAttribute(oObjectName, "maxSize", p_Form.getMaxSize());
093: setIntegerAttribute(oObjectName, "minSize", p_Form.getMinSize());
094: setIntegerAttribute(oObjectName, "maxWaitTime", p_Form
095: .getMaxWaitTime());
096: setIntegerAttribute(oObjectName, "maxWaiters", p_Form
097: .getMaxWaiters());
098: setIntegerAttribute(oObjectName, "samplingPeriod", p_Form
099: .getSamplingPeriod());
100: //setIntegerAttribute(oObjectName, "pstmtMax ", p_Form.getPstmtMax());
101: }
102:
103: protected void save(ResourceAdapterForm pForm, String domainName,
104: String serverName) throws Exception {
105: // Create a map containing the configuration parameters' values
106: HashMap configMap = new HashMap();
107: configMap.put("jdbcConnCheckLevel", pForm
108: .getJdbcConnCheckLevel());
109: configMap
110: .put("jdbcTestStatement", pForm.getJdbcTestStatement());
111: configMap.put("connMaxAge", pForm.getConnMaxAge());
112: configMap.put("maxOpentime", pForm.getMaxOpentime());
113: configMap.put("maxSize", pForm.getMaxSize());
114: configMap.put("minSize", pForm.getMinSize());
115: configMap.put("maxWaitTime", pForm.getMaxWaitTime());
116: configMap.put("maxWaiters", pForm.getMaxWaiters());
117: configMap.put("samplingPeriod", pForm.getSamplingPeriod());
118: configMap.put("pstmtMax", pForm.getPstmtMax());
119: // Get the RarConfigMbean
120: ObjectName on = JonasAdminJmx
121: .getRarConfigObjectName(serverName);
122: Object[] params = new Object[] { pForm.getPath(), configMap };
123: String[] sig = new String[] { "java.lang.String",
124: "java.util.Map" };
125: JonasManagementRepr.invoke(on, "updateXML", params, sig,
126: serverName);
127:
128: }
129: }
|