KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > jonasadmin > service > resource > EditResourceAdapterCFAction


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: EditResourceAdapterCFAction.java,v 1.3 2005/06/15 08:51:26 kemlerp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.webapp.jonasadmin.service.resource;
27
28 import java.io.IOException JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.Collections JavaDoc;
31 import java.util.Properties JavaDoc;
32
33 import javax.management.ObjectName JavaDoc;
34 import javax.servlet.ServletException JavaDoc;
35 import javax.servlet.http.HttpServletRequest JavaDoc;
36 import javax.servlet.http.HttpServletResponse JavaDoc;
37
38 import org.apache.struts.action.ActionForm;
39 import org.apache.struts.action.ActionForward;
40 import org.apache.struts.action.ActionMapping;
41 import org.objectweb.jonas.jmx.JonasManagementRepr;
42 import org.objectweb.jonas.jmx.JonasObjectName;
43 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
44 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
45 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItem;
46 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItemByNameComparator;
47
48 /**
49  * @author Michel-Ange ANTON
50  */

51
52 public class EditResourceAdapterCFAction extends JonasBaseAction {
53
54 // --------------------------------------------------------- Public Methods
55

56     public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
57         , HttpServletRequest JavaDoc p_Request, HttpServletResponse JavaDoc p_Response)
58         throws IOException JavaDoc, ServletException JavaDoc {
59
60         // Selected resource adapter
61
String JavaDoc sObjectName = p_Request.getParameter("select");
62
63         ObjectName JavaDoc oObjectName = null;
64         String JavaDoc domainName = null;
65         String JavaDoc serverName = null;
66
67         // Form used
68
ResourceAdapterCFForm oForm = null;
69         // Build a new form
70
if (sObjectName != null) {
71             String JavaDoc sPath = null;
72             try {
73                 // Recreate ObjectName
74
oObjectName = ObjectName.getInstance(sObjectName);
75                 domainName = oObjectName.getDomain();
76                 serverName = oObjectName.getKeyProperty("J2EEServer");
77                 // Build a new form
78
oForm = new ResourceAdapterCFForm();
79                 oForm.reset(p_Mapping, p_Request);
80                 if (oObjectName != null) {
81                     // Object name used
82
oForm.setOName(oObjectName);
83                     oForm.setName(getStringAttribute(oObjectName, "jndiName"));
84                     oForm.setDescription(getStringAttribute(oObjectName, "description"));
85                     oForm.setListProperties((Properties JavaDoc) JonasManagementRepr.getAttribute(oObjectName
86                             , "properties"));
87                     populate(oForm, oObjectName);
88                 }
89                 m_Session.setAttribute("resourceAdapterCFForm", oForm);
90             } catch (Throwable JavaDoc t) {
91                 addGlobalError(t);
92                 saveErrors(p_Request, m_Errors);
93                 return (p_Mapping.findForward("Global Error"));
94             }
95         } else {
96             // Used last form in session
97
oForm = (ResourceAdapterCFForm) m_Session.getAttribute("resourceAdapterCFForm");
98         }
99
100         ResourceAdapterForm raForm = (ResourceAdapterForm) m_Session.getAttribute("resourceAdapterForm");
101
102         // Force the node selected in tree
103
m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER) + WhereAreYou.NODE_SEPARATOR
104             + "services" + WhereAreYou.NODE_SEPARATOR + "resourceAdapter"
105             + WhereAreYou.NODE_SEPARATOR + raForm.getFile(), true);
106
107         // Forward to the jsp.
108
return (p_Mapping.findForward("Resource AdapterCF"));
109     }
110
111     protected void populate(ResourceAdapterCFForm p_Form, ObjectName JavaDoc oObjectName)
112         throws Exception JavaDoc {
113
114         p_Form.setJdbcConnCheckLevel(toStringIntegerAttribute(oObjectName, "jdbcConnCheckLevel"));
115         p_Form.setConnMaxAge(toStringIntegerAttribute(oObjectName, "connMaxAge"));
116         p_Form.setMaxOpentime(toStringIntegerAttribute(oObjectName, "maxOpentime"));
117         p_Form.setJdbcTestStatement(getStringAttribute(oObjectName, "jdbcTestStatement"));
118         p_Form.setMaxSize(toStringIntegerAttribute(oObjectName, "maxSize"));
119         p_Form.setMinSize(toStringIntegerAttribute(oObjectName, "minSize"));
120         p_Form.setMaxWaitTime(toStringIntegerAttribute(oObjectName, "maxWaitTime"));
121         p_Form.setMaxWaiters(toStringIntegerAttribute(oObjectName, "maxWaiters"));
122         p_Form.setSamplingPeriod(toStringIntegerAttribute(oObjectName, "samplingPeriod"));
123
124         // Build list of Ejb which used this jndiName
125
ArrayList JavaDoc al = new ArrayList JavaDoc();
126         String JavaDoc[] asParam = new String JavaDoc[1];
127         String JavaDoc[] asSignature = new String JavaDoc[1];
128         asSignature[0] = "java.lang.String";
129         asParam[0] = p_Form.getName();
130         if (JonasManagementRepr.isRegistered(JonasObjectName.ejbService())) {
131             java.util.Iterator JavaDoc it = ((java.util.Set JavaDoc) JonasManagementRepr.invoke(JonasObjectName.
132                 ejbService(), "getDataSourceDependence", asParam, asSignature)).iterator();
133             while (it.hasNext()) {
134                 al.add(new EjbItem((ObjectName JavaDoc) it.next()));
135             }
136         }
137         // Sort by name
138
Collections.sort(al, new EjbItemByNameComparator());
139         // Set list in form
140
p_Form.setListUsedByEjb(al);
141     }
142
143 }
144
Popular Tags