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: EditResourceAdapterCFAction.java 9680 2006-10-06 12:08:33Z danesa $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.webapp.jonasadmin.service.resource;
027:
028: import java.io.IOException;
029: import java.util.ArrayList;
030: import java.util.Collections;
031: import java.util.Properties;
032:
033: import javax.management.ObjectName;
034: import javax.servlet.ServletException;
035: import javax.servlet.http.HttpServletRequest;
036: import javax.servlet.http.HttpServletResponse;
037:
038: import org.apache.struts.action.ActionForm;
039: import org.apache.struts.action.ActionForward;
040: import org.apache.struts.action.ActionMapping;
041: import org.objectweb.jonas.jmx.JonasManagementRepr;
042: import org.objectweb.jonas.jmx.JonasObjectName;
043: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
044: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
045: import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItem;
046: import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItemByNameComparator;
047:
048: /**
049: * @author Michel-Ange ANTON
050: */
051:
052: public class EditResourceAdapterCFAction extends JonasBaseAction {
053:
054: // --------------------------------------------------------- Public Methods
055:
056: public ActionForward executeAction(ActionMapping p_Mapping,
057: ActionForm p_Form, HttpServletRequest p_Request,
058: HttpServletResponse p_Response) throws IOException,
059: ServletException {
060:
061: // Selected resource adapter
062: String sObjectName = p_Request.getParameter("select");
063:
064: ObjectName oObjectName = null;
065: String domainName = null;
066: String serverName = null;
067:
068: // Form used
069: ResourceAdapterCFForm oForm = null;
070: // Build a new form
071: if (sObjectName != null) {
072: String sPath = null;
073: try {
074: // Recreate ObjectName
075: oObjectName = ObjectName.getInstance(sObjectName);
076: domainName = oObjectName.getDomain();
077: serverName = oObjectName.getKeyProperty("J2EEServer");
078: // Build a new form
079: oForm = new ResourceAdapterCFForm();
080: oForm.reset(p_Mapping, p_Request);
081: if (oObjectName != null) {
082: // Object name used
083: oForm.setOName(oObjectName);
084: oForm.setName(getStringAttribute(oObjectName,
085: "jndiName"));
086: oForm.setPath(getStringAttribute(oObjectName,
087: "fileName"));
088: oForm.setDescription(getStringAttribute(
089: oObjectName, "description"));
090: oForm
091: .setListProperties((Properties) JonasManagementRepr
092: .getAttribute(oObjectName,
093: "properties", serverName));
094: populate(oForm, oObjectName, serverName);
095: }
096: m_Session.setAttribute("resourceAdapterCFForm", oForm);
097: } catch (Throwable t) {
098: addGlobalError(t);
099: saveErrors(p_Request, m_Errors);
100: return (p_Mapping.findForward("Global Error"));
101: }
102: } else {
103: // Used last form in session
104: oForm = (ResourceAdapterCFForm) m_Session
105: .getAttribute("resourceAdapterCFForm");
106: }
107:
108: ResourceAdapterForm raForm = (ResourceAdapterForm) m_Session
109: .getAttribute("resourceAdapterForm");
110:
111: // Force the node selected in tree
112: m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER)
113: + WhereAreYou.NODE_SEPARATOR + "services"
114: + WhereAreYou.NODE_SEPARATOR + "resourceAdapter"
115: + WhereAreYou.NODE_SEPARATOR + raForm.getFile(), true);
116:
117: // Forward to the jsp.
118: return (p_Mapping.findForward("Resource AdapterCF"));
119: }
120:
121: protected void populate(ResourceAdapterCFForm p_Form,
122: ObjectName oObjectName, String serverName) throws Exception {
123:
124: p_Form.setJdbcConnCheckLevel(toStringIntegerAttribute(
125: oObjectName, "jdbcConnCheckLevel"));
126: p_Form.setConnMaxAge(toStringIntegerAttribute(oObjectName,
127: "connMaxAge"));
128: p_Form.setMaxOpentime(toStringIntegerAttribute(oObjectName,
129: "maxOpentime"));
130: p_Form.setJdbcTestStatement(getStringAttribute(oObjectName,
131: "jdbcTestStatement"));
132: p_Form.setMaxSize(toStringIntegerAttribute(oObjectName,
133: "maxSize"));
134: p_Form.setMinSize(toStringIntegerAttribute(oObjectName,
135: "minSize"));
136: p_Form.setInitSize(toStringIntegerAttribute(oObjectName,
137: "initSize"));
138: p_Form.setMaxWaitTime(toStringIntegerAttribute(oObjectName,
139: "maxWaitTime"));
140: p_Form.setMaxWaiters(toStringIntegerAttribute(oObjectName,
141: "maxWaiters"));
142: p_Form.setSamplingPeriod(toStringIntegerAttribute(oObjectName,
143: "samplingPeriod"));
144: p_Form.setPstmtMax(toStringIntegerAttribute(oObjectName,
145: "pstmtMax"));
146:
147: // Build list of Ejb which used this jndiName
148: ArrayList al = new ArrayList();
149: String[] asParam = new String[1];
150: String[] asSignature = new String[1];
151: asSignature[0] = "java.lang.String";
152: asParam[0] = p_Form.getName();
153: if (JonasManagementRepr.isRegistered(JonasObjectName
154: .ejbService(), serverName)) {
155: java.util.Iterator it = ((java.util.Set) JonasManagementRepr
156: .invoke(JonasObjectName.ejbService(),
157: "getDataSourceDependence", asParam,
158: asSignature, serverName)).iterator();
159: while (it.hasNext()) {
160: al.add(new EjbItem((ObjectName) it.next(), serverName));
161: }
162: }
163: // Sort by name
164: Collections.sort(al, new EjbItemByNameComparator());
165: // Set list in form
166: p_Form.setListUsedByEjb(al);
167: }
168:
169: }
|