KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > jonasadmin > service > db > EditDatasourceAction


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 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: EditDatasourceAction.java,v 1.20 2005/05/03 12:28:01 danesa Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.webapp.jonasadmin.service.db;
27
28 import java.io.IOException JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.Collections JavaDoc;
31
32 import javax.management.ObjectName JavaDoc;
33 import javax.servlet.ServletException JavaDoc;
34 import javax.servlet.http.HttpServletRequest JavaDoc;
35 import javax.servlet.http.HttpServletResponse JavaDoc;
36
37 import org.apache.struts.action.ActionForm;
38 import org.apache.struts.action.ActionForward;
39 import org.apache.struts.action.ActionMapping;
40 import org.objectweb.jonas.jmx.J2eeObjectName;
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 EditDatasourceAction 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         // Datasource to edit
61
String JavaDoc sName = p_Request.getParameter("name");
62
63         // Form used
64
DatasourceForm oForm = null;
65         if (sName != null) {
66             // Editing a new
67
oForm = new DatasourceForm();
68             oForm.reset(p_Mapping, p_Request);
69             m_Session.setAttribute("datasourceForm", oForm);
70             oForm.setDatasourceName(sName);
71         } else {
72             // Editing that which is in session
73
oForm = (DatasourceForm) m_Session.getAttribute("datasourceForm");
74         }
75
76         // Force the node selected in tree
77
m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER) + WhereAreYou.NODE_SEPARATOR
78             + "services" + WhereAreYou.NODE_SEPARATOR + "database" + WhereAreYou.NODE_SEPARATOR
79             + oForm.getDatasourceName(), true);
80
81         // Populate
82
try {
83             if (sName != null) {
84                 populate(oForm, m_WhereAreYou.getCurrentDomainName(), m_WhereAreYou.getCurrentJonasServerName());
85             }
86         } catch (Throwable JavaDoc t) {
87             addGlobalError(t);
88             saveErrors(p_Request, m_Errors);
89             return (p_Mapping.findForward("Global Error"));
90         }
91         // Forward to the jsp.
92
return (p_Mapping.findForward("Datasource"));
93     }
94
95 // --------------------------------------------------------- Protected Methods
96

97     protected void populate(DatasourceForm p_Form, String JavaDoc domainName, String JavaDoc serverName)
98         throws Exception JavaDoc {
99
100         // ObjectName used for JDBCDataSource
101
ObjectName JavaDoc oObjectName = J2eeObjectName.getJDBCDataSource(domainName, serverName, p_Form.getDatasourceName());
102         // JDBCDriver ObjectName
103
String JavaDoc jdbcDriverON = getStringAttribute(oObjectName, "jdbcDriver");
104         ObjectName JavaDoc onJdbcDriver = ObjectName.getInstance(jdbcDriverON);
105         // Driver class name moved to JDBCDriver
106
p_Form.setClassName(getStringAttribute(onJdbcDriver, "driverClassName"));
107         p_Form.setDatasourceDescription(getStringAttribute(oObjectName, "description"));
108         p_Form.setDatasourceName(getStringAttribute(oObjectName, "name"));
109         p_Form.setDatasourceMapper(getStringAttribute(oObjectName, "mapperName"));
110         p_Form.setDsName(getStringAttribute(oObjectName, "jndiName"));
111         p_Form.setJdbcConnCheckLevel(toStringIntegerAttribute(oObjectName, "jdbcConnCheckLevel"));
112         p_Form.setJdbcConnMaxAge(toStringIntegerAttribute(oObjectName, "jdbcConnMaxAge"));
113         p_Form.setJdbcMaxOpenTime(toStringIntegerAttribute(oObjectName, "jdbcMaxOpenTime"));
114         p_Form.setJdbcTestStatement(getStringAttribute(oObjectName, "jdbcTestStatement"));
115         p_Form.setPassword(getStringAttribute(oObjectName, "userPassword"));
116         p_Form.setUrl(getStringAttribute(oObjectName, "url"));
117         p_Form.setUserName(getStringAttribute(oObjectName, "userName"));
118         p_Form.setJdbcMaxConnPool(toStringIntegerAttribute(oObjectName, "jdbcMaxConnPool"));
119         p_Form.setJdbcMinConnPool(toStringIntegerAttribute(oObjectName, "jdbcMinConnPool"));
120         p_Form.setJdbcMaxWaitTime(toStringIntegerAttribute(oObjectName, "jdbcMaxWaitTime"));
121         p_Form.setJdbcMaxWaiters(toStringIntegerAttribute(oObjectName, "jdbcMaxWaiters"));
122         p_Form.setJdbcSamplingPeriod(toStringIntegerAttribute(oObjectName, "jdbcSamplingPeriod"));
123
124         // Build list of Ejb which used this datasource
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.getDsName();
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
Popular Tags