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: EditResourceAdapterAction.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.net.URL;
030: import java.util.ArrayList;
031: import java.util.Collections;
032: import java.util.Properties;
033:
034: import javax.management.ObjectName;
035: import javax.servlet.ServletException;
036: import javax.servlet.http.HttpServletRequest;
037: import javax.servlet.http.HttpServletResponse;
038:
039: import org.apache.struts.action.ActionForm;
040: import org.apache.struts.action.ActionForward;
041: import org.apache.struts.action.ActionMapping;
042: import org.objectweb.jonas.jmx.JonasManagementRepr;
043: import org.objectweb.jonas.jmx.JonasObjectName;
044: import org.objectweb.jonas.jmx.JoramObjectName;
045: import org.objectweb.jonas.jmx.J2eeObjectName;
046: import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
047: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
048: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
049: import org.objectweb.jonas.webapp.jonasadmin.common.BeanComparator;
050: import org.objectweb.jonas.webapp.jonasadmin.common.ObjectNameItem;
051: import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItem;
052: import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItemByNameComparator;
053:
054: /**
055: * @author Michel-Ange ANTON
056: */
057:
058: public class EditResourceAdapterAction extends JonasBaseAction {
059:
060: public final static String JORAM_RAR_NAME = "joram_for_jonas_ra";
061:
062: // --------------------------------------------------------- Public Methods
063:
064: public ActionForward executeAction(ActionMapping p_Mapping,
065: ActionForm p_Form, HttpServletRequest p_Request,
066: HttpServletResponse p_Response) throws IOException,
067: ServletException {
068:
069: // Selected resource adapter
070: String raON = p_Request.getParameter("select");
071:
072: ObjectName raObjectName = null;
073: ObjectName rarObjectName = null;
074: String domainName = null;
075: String serverName = null;
076: String rarName = null;
077: String fileName = null;
078: String specVersion = null;
079: String appName = null;
080:
081: // Form used
082: ResourceAdapterForm oForm = null;
083: // Build a new form
084: if (raON != null) {
085: String sPath = null;
086: try {
087: // Recreate ResourceAdapter ObjectName
088: raObjectName = ObjectName.getInstance(raON);
089: domainName = raObjectName.getDomain();
090: serverName = raObjectName.getKeyProperty("J2EEServer");
091: rarName = raObjectName.getKeyProperty("name");
092: appName = raObjectName
093: .getKeyProperty("J2EEApplication");
094: // Create the ResourceAdapterModule ObjectName
095: rarObjectName = J2eeObjectName
096: .getResourceAdapterModule(domainName,
097: serverName, appName, rarName);
098: // Build a new form
099: oForm = new ResourceAdapterForm();
100: oForm.reset(p_Mapping, p_Request);
101: oForm.setName(rarName);
102: specVersion = getStringAttribute(raObjectName,
103: "specVersion");
104: oForm.setSpecVersion(specVersion);
105:
106: if (raObjectName != null) {
107: // Object name used
108: oForm.setOName(raObjectName);
109: oForm.setJndiName(getStringAttribute(raObjectName,
110: "jndiName"));
111: fileName = getStringAttribute(raObjectName,
112: "fileName");
113: oForm.setPath(fileName);
114: if (fileName.lastIndexOf(JORAM_RAR_NAME) > 0) {
115: // this is possibly the Joram RAR
116: ObjectName joramAdapterOn = (ObjectName) JonasManagementRepr
117: .queryNames(
118: JoramObjectName.joramAdapter(),
119: serverName).iterator().next();
120: if (JonasAdminJmx.hasMBeanName(joramAdapterOn,
121: serverName)) {
122: oForm.setJoramAdapter(true);
123: Short localServerId = (Short) JonasManagementRepr
124: .getAttribute(joramAdapterOn,
125: "ServerId", serverName);
126: oForm.setJoramServerId(localServerId
127: .toString());
128: oForm
129: .setJoramServerName((String) JonasManagementRepr
130: .getAttribute(
131: joramAdapterOn,
132: "ServerName",
133: serverName));
134: }
135: }
136: oForm.setFile(JonasAdminJmx.extractFilename(oForm
137: .getPath()));
138: // Use the ResourceAdapterModule MBean for EAR related info
139: oForm.setInEar(getBooleanAttribute(rarObjectName,
140: "inEarCase"));
141: oForm.setEarPath((URL) JonasManagementRepr
142: .getAttribute(rarObjectName, "earURL",
143: serverName));
144: oForm.setEarON((String) JonasManagementRepr
145: .getAttribute(rarObjectName, "earON",
146: serverName));
147: oForm
148: .setListProperties((Properties) JonasManagementRepr
149: .getAttribute(raObjectName,
150: "properties", serverName));
151:
152: ObjectName oJCAResource = ObjectName
153: .getInstance(getStringAttribute(
154: raObjectName, "jcaResource"));
155:
156: String[] cfs = (String[]) JonasManagementRepr
157: .getAttribute(oJCAResource,
158: "connectionFactories", serverName);
159: ArrayList cfAl = new ArrayList();
160: String cfOn = null;
161: for (int i = 0; i < cfs.length; i++) {
162: cfOn = cfs[i];
163: ObjectName onCf = ObjectName.getInstance(cfOn);
164: cfAl.add(new ObjectNameItem(onCf));
165: }
166: Collections.sort(cfAl, new BeanComparator(
167: new String[] { "name" }));
168: oForm.setCF(cfAl);
169:
170: String[] ass = (String[]) JonasManagementRepr
171: .getAttribute(oJCAResource,
172: "activationSpecs", serverName);
173: ArrayList asAl = new ArrayList();
174: String asOn = null;
175: for (int i = 0; i < ass.length; i++) {
176: asOn = ass[i];
177: ObjectName onAs = ObjectName.getInstance(asOn);
178: asAl.add(new ObjectNameItem(onAs));
179: }
180: Collections.sort(asAl, new BeanComparator(
181: new String[] { "name" }));
182: oForm.setAS(asAl);
183:
184: String[] aos = (String[]) JonasManagementRepr
185: .getAttribute(oJCAResource, "adminObjects",
186: serverName);
187: ArrayList aoAl = new ArrayList();
188: String aoOn = null;
189: for (int i = 0; i < aos.length; i++) {
190: aoOn = aos[i];
191: ObjectName onAo = ObjectName.getInstance(aoOn);
192: aoAl.add(new ObjectNameItem(onAo));
193: }
194: Collections.sort(aoAl, new BeanComparator(
195: new String[] { "name" }));
196: oForm.setAO(aoAl);
197:
198: if (specVersion == null
199: || specVersion.equals("1.0")) {
200: populate(oForm, cfs[0], serverName);
201: }
202: }
203:
204: m_Session.setAttribute("resourceAdapterForm", oForm);
205: } catch (Throwable t) {
206: addGlobalError(t);
207: saveErrors(p_Request, m_Errors);
208: return (p_Mapping.findForward("Global Error"));
209: }
210: } else {
211: // Used last form in session
212: oForm = (ResourceAdapterForm) m_Session
213: .getAttribute("resourceAdapterForm");
214: specVersion = oForm.getSpecVersion();
215: }
216:
217: // Force the node selected in tree
218: m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER)
219: + WhereAreYou.NODE_SEPARATOR + "services"
220: + WhereAreYou.NODE_SEPARATOR + "resourceAdapter"
221: + WhereAreYou.NODE_SEPARATOR + oForm.getFile(), true);
222:
223: // Forward to the jsp.
224: if (specVersion != null && specVersion.equals("1.5")) {
225: return (p_Mapping.findForward("Resource Adapter1.5"));
226: }
227: return (p_Mapping.findForward("Resource Adapter1.0"));
228: }
229:
230: // --------------------------------------------------------- Protected Methods
231:
232: protected void populate(ResourceAdapterForm p_Form, String cf,
233: String serverName) throws Exception {
234:
235: // ObjectName used for CF
236: ObjectName oObjectName = ObjectName.getInstance(cf);
237: p_Form.setConnectionFactory(cf);
238:
239: p_Form.setJdbcConnCheckLevel(toStringIntegerAttribute(
240: oObjectName, "jdbcConnCheckLevel"));
241: p_Form.setConnMaxAge(toStringIntegerAttribute(oObjectName,
242: "connMaxAge"));
243: p_Form.setMaxOpentime(toStringIntegerAttribute(oObjectName,
244: "maxOpentime"));
245: p_Form.setJdbcTestStatement(getStringAttribute(oObjectName,
246: "jdbcTestStatement"));
247: p_Form.setMaxSize(toStringIntegerAttribute(oObjectName,
248: "maxSize"));
249: p_Form.setMinSize(toStringIntegerAttribute(oObjectName,
250: "minSize"));
251: p_Form.setInitSize(toStringIntegerAttribute(oObjectName,
252: "initSize"));
253: p_Form.setMaxWaitTime(toStringIntegerAttribute(oObjectName,
254: "maxWaitTime"));
255: p_Form.setMaxWaiters(toStringIntegerAttribute(oObjectName,
256: "maxWaiters"));
257: p_Form.setSamplingPeriod(toStringIntegerAttribute(oObjectName,
258: "samplingPeriod"));
259: p_Form.setPstmtMax(toStringIntegerAttribute(oObjectName,
260: "pstmtMax"));
261:
262: // Build list of Ejb which used this jndiName
263: ArrayList al = new ArrayList();
264: String[] asParam = new String[1];
265: String[] asSignature = new String[1];
266: asSignature[0] = "java.lang.String";
267: asParam[0] = p_Form.getJndiName();
268: if (JonasManagementRepr.isRegistered(JonasObjectName
269: .ejbService(), serverName)) {
270: java.util.Iterator it = ((java.util.Set) JonasManagementRepr
271: .invoke(JonasObjectName.ejbService(),
272: "getDataSourceDependence", asParam,
273: asSignature, serverName)).iterator();
274: while (it.hasNext()) {
275: al.add(new EjbItem((ObjectName) it.next(), serverName));
276: }
277: }
278: // Sort by name
279: Collections.sort(al, new EjbItemByNameComparator());
280: // Set list in form
281: p_Form.setListUsedByEjb(al);
282: }
283: }
|