KickJava   Java API By Example, From Geeks To Geeks.

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


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: EditResourceAdapterAction.java,v 1.4 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.net.URL JavaDoc;
30 import java.util.ArrayList JavaDoc;
31 import java.util.Collections JavaDoc;
32 import java.util.Properties JavaDoc;
33
34 import javax.management.ObjectName JavaDoc;
35 import javax.servlet.ServletException JavaDoc;
36 import javax.servlet.http.HttpServletRequest JavaDoc;
37 import javax.servlet.http.HttpServletResponse JavaDoc;
38
39 import org.apache.struts.action.ActionForm;
40 import org.apache.struts.action.ActionForward;
41 import org.apache.struts.action.ActionMapping;
42 import org.objectweb.jonas.jmx.JonasManagementRepr;
43 import org.objectweb.jonas.jmx.JonasObjectName;
44 import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
45 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
46 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
47 import org.objectweb.jonas.webapp.jonasadmin.common.BeanComparator;
48 import org.objectweb.jonas.webapp.jonasadmin.common.ObjectNameItem;
49 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItem;
50 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItemByNameComparator;
51
52 /**
53  * @author Michel-Ange ANTON
54  */

55
56 public class EditResourceAdapterAction extends JonasBaseAction {
57
58 // --------------------------------------------------------- Public Methods
59

60     public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
61         , HttpServletRequest JavaDoc p_Request, HttpServletResponse JavaDoc p_Response)
62         throws IOException JavaDoc, ServletException JavaDoc {
63
64         // Selected resource adapter
65
String JavaDoc sObjectName = p_Request.getParameter("select");
66
67         ObjectName JavaDoc oObjectName = null;
68         String JavaDoc domainName = null;
69         String JavaDoc serverName = null;
70         String JavaDoc rarName = null;
71         String JavaDoc specVersion = null;
72
73         // Form used
74
ResourceAdapterForm oForm = null;
75         // Build a new form
76
if (sObjectName != null) {
77             String JavaDoc sPath = null;
78             try {
79                 // Recreate ObjectName
80
oObjectName = ObjectName.getInstance(sObjectName);
81                 domainName = oObjectName.getDomain();
82                 serverName = oObjectName.getKeyProperty("J2EEServer");
83                 rarName = oObjectName.getKeyProperty("name");
84                 // Build a new form
85
oForm = new ResourceAdapterForm();
86                 oForm.reset(p_Mapping, p_Request);
87                 oForm.setName(rarName);
88                 specVersion = getStringAttribute(oObjectName, "specVersion");
89                 oForm.setSpecVersion(specVersion);
90
91                 if (oObjectName != null) {
92                     // Object name used
93
oForm.setOName(oObjectName);
94                     oForm.setJndiName(getStringAttribute(oObjectName, "jndiName"));
95                     oForm.setPath(getStringAttribute(oObjectName, "fileName"));
96                     oForm.setFile(JonasAdminJmx.extractFilename(oForm.getPath()));
97                     oForm.setInEar(getBooleanAttribute(oObjectName, "inEarCase"));
98                     oForm.setEarPath((URL JavaDoc) JonasManagementRepr.getAttribute(oObjectName, "earURL"));
99                     oForm.setListProperties((Properties JavaDoc) JonasManagementRepr.getAttribute(oObjectName
100                             , "properties"));
101
102                     ObjectName JavaDoc oJCAResource = ObjectName.getInstance(getStringAttribute(oObjectName, "jcaResource"));
103
104                     String JavaDoc [] cfs = (String JavaDoc[]) JonasManagementRepr.getAttribute(oJCAResource, "connectionFactories");
105                     ArrayList JavaDoc cfAl = new ArrayList JavaDoc();
106                     String JavaDoc cfOn = null;
107                     for (int i = 0; i < cfs.length; i++) {
108                         cfOn = cfs[i];
109                         ObjectName JavaDoc onCf = ObjectName.getInstance(cfOn);
110                         cfAl.add(new ObjectNameItem(onCf));
111                     }
112                     Collections.sort(cfAl, new BeanComparator(new String JavaDoc[] {
113                             "name"}));
114                     oForm.setCF(cfAl);
115
116                     String JavaDoc [] ass = (String JavaDoc[]) JonasManagementRepr.getAttribute(oJCAResource, "activationSpecs");
117                     ArrayList JavaDoc asAl = new ArrayList JavaDoc();
118                     String JavaDoc asOn = null;
119                     for (int i = 0; i < ass.length; i++) {
120                         asOn = ass[i];
121                         ObjectName JavaDoc onAs = ObjectName.getInstance(asOn);
122                         asAl.add(new ObjectNameItem(onAs));
123                     }
124                     Collections.sort(asAl, new BeanComparator(new String JavaDoc[] {
125                             "name"}));
126                     oForm.setAS(asAl);
127
128                     String JavaDoc [] aos = (String JavaDoc[]) JonasManagementRepr.getAttribute(oJCAResource, "adminObjects");
129                     ArrayList JavaDoc aoAl = new ArrayList JavaDoc();
130                     String JavaDoc aoOn = null;
131                     for (int i = 0; i < aos.length; i++) {
132                         aoOn = aos[i];
133                         ObjectName JavaDoc onAo = ObjectName.getInstance(aoOn);
134                         aoAl.add(new ObjectNameItem(onAo));
135                     }
136                     Collections.sort(aoAl, new BeanComparator(new String JavaDoc[] {
137                             "name"}));
138                     oForm.setAO(aoAl);
139
140                     if (specVersion == null || specVersion.equals("1.0")) {
141                         populate(oForm, cfs[0]);
142                     }
143                 }
144
145                 m_Session.setAttribute("resourceAdapterForm", oForm);
146             } catch (Throwable JavaDoc t) {
147                 addGlobalError(t);
148                 saveErrors(p_Request, m_Errors);
149                 return (p_Mapping.findForward("Global Error"));
150             }
151         } else {
152             // Used last form in session
153
oForm = (ResourceAdapterForm) m_Session.getAttribute("resourceAdapterForm");
154             specVersion = oForm.getSpecVersion();
155         }
156
157         // Force the node selected in tree
158
m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER) + WhereAreYou.NODE_SEPARATOR
159             + "services" + WhereAreYou.NODE_SEPARATOR + "resourceAdapter"
160             + WhereAreYou.NODE_SEPARATOR + oForm.getFile(), true);
161
162         // Forward to the jsp.
163
if (specVersion != null && specVersion.equals("1.5")) {
164             return (p_Mapping.findForward("Resource Adapter1.5"));
165         }
166         return (p_Mapping.findForward("Resource Adapter1.0"));
167     }
168
169 // --------------------------------------------------------- Protected Methods
170

171     protected void populate(ResourceAdapterForm p_Form, String JavaDoc cf)
172         throws Exception JavaDoc {
173
174         // ObjectName used for CF
175
ObjectName JavaDoc oObjectName = ObjectName.getInstance(cf);
176         p_Form.setConnectionFactory (cf);
177
178         p_Form.setJdbcConnCheckLevel(toStringIntegerAttribute(oObjectName, "jdbcConnCheckLevel"));
179         p_Form.setConnMaxAge(toStringIntegerAttribute(oObjectName, "connMaxAge"));
180         p_Form.setMaxOpentime(toStringIntegerAttribute(oObjectName, "maxOpentime"));
181         p_Form.setJdbcTestStatement(getStringAttribute(oObjectName, "jdbcTestStatement"));
182         p_Form.setMaxSize(toStringIntegerAttribute(oObjectName, "maxSize"));
183         p_Form.setMinSize(toStringIntegerAttribute(oObjectName, "minSize"));
184         p_Form.setMaxWaitTime(toStringIntegerAttribute(oObjectName, "maxWaitTime"));
185         p_Form.setMaxWaiters(toStringIntegerAttribute(oObjectName, "maxWaiters"));
186         p_Form.setSamplingPeriod(toStringIntegerAttribute(oObjectName, "samplingPeriod"));
187
188         // Build list of Ejb which used this jndiName
189
ArrayList JavaDoc al = new ArrayList JavaDoc();
190         String JavaDoc[] asParam = new String JavaDoc[1];
191         String JavaDoc[] asSignature = new String JavaDoc[1];
192         asSignature[0] = "java.lang.String";
193         asParam[0] = p_Form.getJndiName();
194         if (JonasManagementRepr.isRegistered(JonasObjectName.ejbService())) {
195             java.util.Iterator JavaDoc it = ((java.util.Set JavaDoc) JonasManagementRepr.invoke(JonasObjectName.
196                 ejbService(), "getDataSourceDependence", asParam, asSignature)).iterator();
197             while (it.hasNext()) {
198                 al.add(new EjbItem((ObjectName JavaDoc) it.next()));
199             }
200         }
201         // Sort by name
202
Collections.sort(al, new EjbItemByNameComparator());
203         // Set list in form
204
p_Form.setListUsedByEjb(al);
205     }
206 }
207
Popular Tags