KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > jonasadmin > service > ejb > EditEjbAction


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: EditEjbAction.java,v 1.17 2005/06/27 09:21:10 danesa Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.webapp.jonasadmin.service.ejb;
27
28 import java.util.ArrayList JavaDoc;
29 import java.util.Collection JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import java.util.Map JavaDoc;
32
33 import javax.management.MalformedObjectNameException JavaDoc;
34 import javax.management.ObjectName 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.jmx.JoramObjectName;
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.service.container.ContainerForm;
48
49 /**
50  * @author Michel-Ange ANTON
51  */

52
53 public abstract class EditEjbAction extends JonasBaseAction {
54
55     /**
56      * The EJB's OBJECT_NAME (the stringified ObjetName)
57      */

58     private String JavaDoc ejbObjectName = null;
59
60     // --------------------------------------------------------- Public Methods
61
/**
62      * Execute a action.
63      *
64      * @param pMapping <code>ActionForward</code> instance
65      * @param pForm <code>ActionForm</code> instance
66      * @param pRequest <code>HttpServletRequest</code> instance
67      * @param pResponse <code>HttpServletResponse</code> instance
68      * @return <code>ActionForward</code> instance
69      */

70     public ActionForward executeAction(ActionMapping pMapping,
71             ActionForm pForm,
72             HttpServletRequest JavaDoc pRequest,
73             HttpServletResponse JavaDoc pResponse) {
74         // setForm is used specifically when this action is invoked as a result of invalid input in editEjbSession*.jsp.
75
EjbForm setForm = (EjbForm) m_Session.getAttribute("ejbForm");
76         // Determine the EJB's ObjectName
77
String JavaDoc sObjectName = pRequest.getParameter("select");
78         if (sObjectName == null) {
79             // Accept request attribute forced by a EditEjbAction
80
sObjectName = (String JavaDoc) pRequest.getAttribute("select");
81         }
82
83         if (sObjectName == null) {
84             // Use the objectname specified in the cached input form before invalid data was submitted by user.
85
sObjectName = (setForm != null && setForm.getObjectName() != null) ? setForm.getObjectName() : null;
86         }
87
88         ObjectName JavaDoc oObjectName = null;
89         if (sObjectName != null) {
90             try {
91                 oObjectName = ObjectName.getInstance(sObjectName);
92             } catch (Throwable JavaDoc t) {
93                 addGlobalError(t);
94                 saveErrors(pRequest, m_Errors);
95                 return (pMapping.findForward("Global Error"));
96             }
97         }
98
99         // Form used
100
EjbForm oForm = getEjbForm();
101         ejbObjectName = sObjectName;
102         String JavaDoc msParamType = oObjectName.getKeyProperty("j2eeType");
103         String JavaDoc msParamName = oObjectName.getKeyProperty("name");
104         String JavaDoc msParamFile = getStringAttribute(oObjectName, "fileName");
105
106         // Put global properties
107
oForm.setType(msParamType);
108         oForm.setName(msParamName);
109         oForm.setObjectName(ejbObjectName);
110         oForm.setFile(msParamFile);
111         if (msParamType != null) {
112             String JavaDoc sFullType = m_Resources.getMessage("ejb.fulltype." + msParamType);
113             oForm.setFullType(sFullType);
114         }
115
116         // Force the node selected in tree
117
//m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER)
118
// DEPTH_SERVER is not good in case the currently selected node do no belongs to the Server JOnAS node
119
// this situation can be found when the selected node is a JMS destination managed by Joram and
120
// when trying to navigate through the EJBs used by a JMS destination
121
String JavaDoc serverNodeName = "domain" + WhereAreYou.NODE_SEPARATOR
122             + m_WhereAreYou.getCurrentJonasServerName();
123
124         m_WhereAreYou.selectNameNode(serverNodeName
125                 + WhereAreYou.NODE_SEPARATOR + "services"
126                 + WhereAreYou.NODE_SEPARATOR + "ejbContainers"
127                 + WhereAreYou.NODE_SEPARATOR + JonasAdminJmx.extractFilename(oForm.getFile())
128                 + WhereAreYou.NODE_SEPARATOR + oForm.getName(), true);
129
130         try {
131             // Fill Ejb infos
132
fillEjbInfo(oForm, oObjectName);
133             // Fill Ejb dependencies (Datasource, JMS, ...)
134
fillEjbDependencies(oForm, oObjectName);
135         } catch (Throwable JavaDoc t) {
136             addGlobalError(t);
137             saveErrors(pRequest, m_Errors);
138             return (pMapping.findForward("Global Error"));
139         }
140
141         if (setForm != null && oForm.getObjectName() == null) {
142             sObjectName = setForm.getObjectName();
143             oForm = setForm;
144         }
145         pRequest.setAttribute("select", sObjectName);
146
147         m_Session.setAttribute("ejbForm", oForm);
148
149
150         // Ejb Forward
151
String JavaDoc sForward = getEjbForward();
152
153
154
155         // Control if the Container in session is the parent of the current Ejb
156
ContainerForm oContForm = (ContainerForm) m_Session.getAttribute("containerForm");
157         boolean bChangeForward = false;
158         if (oContForm == null) {
159             bChangeForward = true;
160         } else {
161             if (!oContForm.getPath().equals(oForm.getFile())) {
162                 bChangeForward = true;
163             }
164         }
165         // Change enabled
166
if (bChangeForward) {
167             // Next forward in EditContainerAction
168
pRequest.setAttribute("NextForward", sForward);
169             //p_Request.setAttribute("selectedEjb", sObjectName);
170
// Change the forward to Edit the container
171
sForward = "ActionEditContainer";
172         }
173
174         // Forward to the jsp or the action
175
return (pMapping.findForward(sForward));
176     }
177
178 // --------------------------------------------------------- Protected Methods
179

180     /**
181      * The global forward to go.
182      *
183      * @return Forward
184      */

185     protected abstract String JavaDoc getEjbForward();
186
187     /**
188      * Return a <code>EjbForm</code> instance associate to the EJB.
189      *
190      * @return A form instance
191      */

192     protected abstract EjbForm getEjbForm();
193
194     /**
195      * Fill all infos of EJB in the <code>EjbForm</code> instance.
196      *
197      * @param pForm Instance to fill
198      * @param pObjectName Instance to get infos
199      * @throws Exception Could not fill info
200      */

201     protected abstract void fillEjbInfo(EjbForm pForm, ObjectName JavaDoc pObjectName)
202         throws Exception JavaDoc;
203
204     /**
205      * Get a <code>ObjectName</code> instance for the Ejb given with the parameters of the HTPP request.
206      *
207      * @return The ObjectName instance
208      * @throws Exception Could not construct ObjectName
209      */

210     protected ObjectName JavaDoc getEjbObjectName()
211         throws Exception JavaDoc {
212         return ObjectName.getInstance(ejbObjectName);
213     }
214
215     /**
216      * Fill all global infos of EJB in the <code>EjbForm</code> instance.
217      *
218      * @param pForm Instance to fill
219      * @param pObjectName Instance to get infos
220      */

221     protected void fillEjbGlobalInfo(EjbForm pForm, ObjectName JavaDoc pObjectName) {
222         pForm.setCurrentInstancePoolSize(getIntegerAttribute(pObjectName
223             , "currentInstancePoolSize"));
224         pForm.setDisplayName(getStringAttribute(pObjectName, "displayName"));
225         pForm.setEjbClass(getStringAttribute(pObjectName, "ejbClass"));
226         pForm.setEjbFileName(getStringAttribute(pObjectName, "fileName"));
227         pForm.setEjbName(pObjectName.getKeyProperty("name"));
228         pForm.setHomeClass(getStringAttribute(pObjectName, "homeClass"));
229         pForm.setJndiName(getStringAttribute(pObjectName, "jndiName"));
230         pForm.setLocalClass(getStringAttribute(pObjectName, "localClass"));
231         pForm.setLocalHomeClass(getStringAttribute(pObjectName, "localHomeClass"));
232         pForm.setRemoteClass(getStringAttribute(pObjectName, "remoteClass"));
233     }
234
235     /**
236      * Fill all dependencies of EJB in the <code>EjbForm</code> instance.
237      *
238      * @param pForm Instance to fill
239      * @param pObjectName Instance to get infos
240      */

241     protected void fillEjbDependencies(EjbForm pForm, ObjectName JavaDoc pObjectName) {
242         // Dependency with Datasource service
243
pForm.setDatabaseServiceActivated(JonasManagementRepr.isRegistered(JonasObjectName.
244             databaseService()));
245         HashMap JavaDoc hDataSources = new HashMap JavaDoc((Map JavaDoc) JonasManagementRepr.getAttribute(pObjectName
246             , "allDataSourceName"));
247         if (hDataSources.size() > 0) {
248             pForm.setDataSource(true);
249             pForm.setDataSources(hDataSources);
250         }
251         // Dependency with JMS service or Joram resource
252
pForm.setJmsServiceActivated(JonasManagementRepr.isRegistered(JonasObjectName.jmsService()));
253         ObjectName JavaDoc jormamPlatformObjectName = null;
254         try {
255             jormamPlatformObjectName = JoramObjectName.joramPlatform();
256             pForm.setJoramResourceLoaded(JonasManagementRepr.isRegistered(jormamPlatformObjectName));
257         } catch (MalformedObjectNameException JavaDoc e) {
258             pForm.setJoramResourceLoaded(false);
259         }
260         ArrayList JavaDoc alJmsConnections = new ArrayList JavaDoc((Collection JavaDoc) JonasManagementRepr.getAttribute(
261             pObjectName, "allJMSConnectionFactoryName"));
262         if (alJmsConnections.size() > 0) {
263             pForm.setJmsConnection(true);
264             pForm.setJmsConnections(alJmsConnections);
265         }
266         ArrayList JavaDoc alJmsDestinations = new ArrayList JavaDoc((Collection JavaDoc) JonasManagementRepr.getAttribute(
267             pObjectName, "allJMSDestinationName"));
268         if (alJmsDestinations.size() > 0) {
269             pForm.setJmsDestination(true);
270             pForm.setJmsDestinations(alJmsDestinations);
271         }
272         // Dependency with Mail service
273
pForm.setMailServiceActivated(JonasManagementRepr.isRegistered(JonasObjectName.mailService()));
274         HashMap JavaDoc hMailSessions = new HashMap JavaDoc((Map JavaDoc) JonasManagementRepr.getAttribute(pObjectName
275             , "allMailFactorySName"));
276         if (hMailSessions.size() > 0) {
277             pForm.setMailSession(true);
278             pForm.setMailSessions(hMailSessions);
279         }
280         HashMap JavaDoc hMailMimes = new HashMap JavaDoc((Map JavaDoc) JonasManagementRepr.getAttribute(pObjectName
281             , "allMailFactoryMName"));
282         if (hMailMimes.size() > 0) {
283             pForm.setMailMime(true);
284             pForm.setMailMimes(hMailMimes);
285         }
286         // Detect one dependency
287
pForm.setDependency(pForm.isDataSource() || pForm.isJmsConnection()
288             || pForm.isJmsDestination() || pForm.isMailSession() || pForm.isMailMime());
289     }
290 }
291
Popular Tags