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: ApplyResourceAdapterCFAction.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.objectweb.jonas.jmx.J2eeObjectName;
038: import org.objectweb.jonas.jmx.JonasManagementRepr;
039: import org.objectweb.jonas.jmx.JonasObjectName;
040: import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
041: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
042:
043: /**
044: * @author Eric Hardesty
045: */
046:
047: public class ApplyResourceAdapterCFAction extends JonasBaseAction {
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: // Form used
057: ResourceAdapterCFForm oForm = (ResourceAdapterCFForm) p_Form;
058: try {
059: String domainName = m_WhereAreYou.getCurrentDomainName();
060: String serverName = m_WhereAreYou
061: .getCurrentJonasServerName();
062: populate(oForm);
063: if (oForm.getAction().equals("save") == true) {
064: save(oForm, domainName, serverName);
065: }
066: } catch (Throwable t) {
067: addGlobalError(t);
068: saveErrors(p_Request, m_Errors);
069: return (p_Mapping.findForward("Global Error"));
070: }
071: // Forward to the jsp and add the parameter 'name' with the good value.
072: return new ActionForward(p_Mapping
073: .findForward("Resource AdapterCF"));
074: }
075:
076: // --------------------------------------------------------- Protected Methods
077:
078: protected void populate(ResourceAdapterCFForm p_Form)
079: throws Exception {
080: // Object name used
081: ObjectName oObjectName = p_Form.getOName();
082: // Populate
083: setIntegerAttribute(oObjectName, "jdbcConnCheckLevel", p_Form
084: .getJdbcConnCheckLevel());
085: setIntegerAttribute(oObjectName, "connMaxAge", p_Form
086: .getConnMaxAge());
087: setIntegerAttribute(oObjectName, "maxOpentime", p_Form
088: .getMaxOpentime());
089: setStringAttribute(oObjectName, "jdbcTestStatement", p_Form
090: .getJdbcTestStatement());
091: setIntegerAttribute(oObjectName, "maxSize", p_Form.getMaxSize());
092: setIntegerAttribute(oObjectName, "minSize", p_Form.getMinSize());
093: setIntegerAttribute(oObjectName, "maxWaitTime", p_Form
094: .getMaxWaitTime());
095: setIntegerAttribute(oObjectName, "maxWaiters", p_Form
096: .getMaxWaiters());
097: setIntegerAttribute(oObjectName, "samplingPeriod", p_Form
098: .getSamplingPeriod());
099: //setIntegerAttribute(oObjectName, "pstmtMax ", p_Form.getPstmtMax());
100: }
101:
102: protected void save(ResourceAdapterCFForm pForm, String domainName,
103: String serverName) {
104: // Create a map containing the configuration parameters' values
105: HashMap configMap = new HashMap();
106: configMap.put("jdbcConnCheckLevel", pForm
107: .getJdbcConnCheckLevel());
108: configMap
109: .put("jdbcTestStatement", pForm.getJdbcTestStatement());
110: configMap.put("connMaxAge", pForm.getConnMaxAge());
111: configMap.put("maxOpentime", pForm.getMaxOpentime());
112: configMap.put("maxSize", pForm.getMaxSize());
113: configMap.put("minSize", pForm.getMinSize());
114: configMap.put("maxWaitTime", pForm.getMaxWaitTime());
115: configMap.put("maxWaiters", pForm.getMaxWaiters());
116: configMap.put("samplingPeriod", pForm.getSamplingPeriod());
117: configMap.put("pstmtMax", pForm.getPstmtMax());
118: // Get the RarConfigMbean
119: ObjectName on = JonasAdminJmx
120: .getRarConfigObjectName(serverName);
121: Object[] params = new Object[] { pForm.getPath(), configMap };
122: String[] sig = new String[] { "java.lang.String",
123: "java.util.Map" };
124: JonasManagementRepr.invoke(on, "updateXML", params, sig,
125: serverName);
126: }
127: }
|