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: EditDatasourceAction.java 9680 2006-10-06 12:08:33Z danesa $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.webapp.jonasadmin.service.db;
025:
026: import java.io.IOException;
027: import java.util.ArrayList;
028: import java.util.Collections;
029:
030: import javax.management.ObjectName;
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.J2eeObjectName;
039: import org.objectweb.jonas.jmx.JonasManagementRepr;
040: import org.objectweb.jonas.jmx.JonasObjectName;
041: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
042: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
043: import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItem;
044: import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItemByNameComparator;
045:
046: /**
047: * @author Michel-Ange ANTON
048: */
049:
050: public class EditDatasourceAction extends JonasBaseAction {
051:
052: // --------------------------------------------------------- Public Methods
053:
054: public ActionForward executeAction(ActionMapping p_Mapping,
055: ActionForm p_Form, HttpServletRequest p_Request,
056: HttpServletResponse p_Response) throws IOException,
057: ServletException {
058:
059: // Datasource to edit
060: String sName = p_Request.getParameter("name");
061:
062: // Form used
063: DatasourceForm oForm = null;
064: if (sName != null) {
065: // Editing a new
066: oForm = new DatasourceForm();
067: oForm.reset(p_Mapping, p_Request);
068: m_Session.setAttribute("datasourceForm", oForm);
069: oForm.setDatasourceName(sName);
070: } else {
071: // Editing that which is in session
072: oForm = (DatasourceForm) m_Session
073: .getAttribute("datasourceForm");
074: }
075:
076: // Force the node selected in tree
077: m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER)
078: + WhereAreYou.NODE_SEPARATOR + "services"
079: + WhereAreYou.NODE_SEPARATOR + "database"
080: + WhereAreYou.NODE_SEPARATOR
081: + oForm.getDatasourceName(), true);
082:
083: // Populate
084: try {
085: if (sName != null) {
086: populate(oForm, m_WhereAreYou.getCurrentDomainName(),
087: m_WhereAreYou.getCurrentJonasServerName());
088: }
089: } catch (Throwable t) {
090: addGlobalError(t);
091: saveErrors(p_Request, m_Errors);
092: return (p_Mapping.findForward("Global Error"));
093: }
094: // Forward to the jsp.
095: return (p_Mapping.findForward("Datasource"));
096: }
097:
098: // --------------------------------------------------------- Protected Methods
099:
100: protected void populate(DatasourceForm p_Form, String domainName,
101: String serverName) throws Exception {
102:
103: // ObjectName used for JDBCDataSource
104: ObjectName oObjectName = J2eeObjectName.getJDBCDataSource(
105: domainName, serverName, p_Form.getDatasourceName());
106: // JDBCDriver ObjectName
107: String jdbcDriverON = getStringAttribute(oObjectName,
108: "jdbcDriver");
109: ObjectName onJdbcDriver = ObjectName.getInstance(jdbcDriverON);
110: // Driver class name moved to JDBCDriver
111: p_Form.setClassName(getStringAttribute(onJdbcDriver,
112: "driverClassName"));
113: p_Form.setDatasourceDescription(getStringAttribute(oObjectName,
114: "description"));
115: p_Form
116: .setDatasourceName(getStringAttribute(oObjectName,
117: "name"));
118: p_Form.setDatasourceMapper(getStringAttribute(oObjectName,
119: "mapperName"));
120: p_Form.setDsName(getStringAttribute(oObjectName, "jndiName"));
121: p_Form.setJdbcConnCheckLevel(toStringIntegerAttribute(
122: oObjectName, "jdbcConnCheckLevel"));
123: p_Form.setJdbcConnMaxAge(toStringIntegerAttribute(oObjectName,
124: "jdbcConnMaxAge"));
125: p_Form.setJdbcMaxOpenTime(toStringIntegerAttribute(oObjectName,
126: "jdbcMaxOpenTime"));
127: p_Form.setJdbcTestStatement(getStringAttribute(oObjectName,
128: "jdbcTestStatement"));
129: p_Form.setPassword(getStringAttribute(oObjectName,
130: "userPassword"));
131: p_Form.setUrl(getStringAttribute(oObjectName, "url"));
132: p_Form.setUserName(getStringAttribute(oObjectName, "userName"));
133: p_Form.setJdbcMaxConnPool(toStringIntegerAttribute(oObjectName,
134: "jdbcMaxConnPool"));
135: p_Form.setJdbcMinConnPool(toStringIntegerAttribute(oObjectName,
136: "jdbcMinConnPool"));
137: p_Form.setJdbcMaxWaitTime(toStringIntegerAttribute(oObjectName,
138: "jdbcMaxWaitTime"));
139: p_Form.setJdbcMaxWaiters(toStringIntegerAttribute(oObjectName,
140: "jdbcMaxWaiters"));
141: p_Form.setJdbcSamplingPeriod(toStringIntegerAttribute(
142: oObjectName, "jdbcSamplingPeriod"));
143: p_Form.setJdbcPstmtMax(toStringIntegerAttribute(oObjectName,
144: "jdbcPstmtMax"));
145:
146: // Build list of Ejb which used this datasource
147: ArrayList al = new ArrayList();
148: String[] asParam = new String[1];
149: String[] asSignature = new String[1];
150: asSignature[0] = "java.lang.String";
151: asParam[0] = p_Form.getDsName();
152: if (JonasManagementRepr.isRegistered(JonasObjectName
153: .ejbService(), serverName)) {
154: java.util.Iterator it = ((java.util.Set) JonasManagementRepr
155: .invoke(JonasObjectName.ejbService(),
156: "getDataSourceDependence", asParam,
157: asSignature, serverName)).iterator();
158: while (it.hasNext()) {
159: al.add(new EjbItem((ObjectName) it.next(), serverName));
160: }
161: }
162: // Sort by name
163: Collections.sort(al, new EjbItemByNameComparator());
164: // Set list in form
165: p_Form.setListUsedByEjb(al);
166: }
167: }
|