KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2003-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: ExecuteEjbAction.java,v 1.6 2004/10/27 13:46:48 danesa Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.webapp.jonasadmin.service.ejb;
27
28 import java.io.IOException JavaDoc;
29
30 import javax.management.ObjectName JavaDoc;
31 import javax.servlet.ServletException JavaDoc;
32 import javax.servlet.http.HttpServletRequest JavaDoc;
33 import javax.servlet.http.HttpServletResponse JavaDoc;
34
35 import org.apache.struts.action.ActionForm;
36 import org.apache.struts.action.ActionForward;
37 import org.apache.struts.action.ActionMapping;
38 import org.objectweb.jonas.jmx.JonasManagementRepr;
39 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
40
41 /**
42  * @author Michel-Ange ANTON
43  */

44
45 public class ExecuteEjbAction extends JonasBaseAction {
46
47 // --------------------------------------------------------- Protected variables
48

49     protected String JavaDoc mAction = null;
50     protected String JavaDoc mForward = null;
51
52 // --------------------------------------------------------- Public Methods
53

54     /**
55      * Execute a action.
56      *
57      * @param pMapping <code>ActionForward</code> instance
58      * @param pForm <code>ActionForm</code> instance
59      * @param pRequest <code>HttpServletRequest</code> instance
60      * @param pResponse <code>HttpServletResponse</code> instance
61      * @return <code>ActionForward</code> instance
62      * @throws IOException
63      * @throws ServletException
64      */

65     public ActionForward executeAction(ActionMapping pMapping, ActionForm pForm
66         , HttpServletRequest JavaDoc pRequest, HttpServletResponse JavaDoc pResponse)
67         throws IOException JavaDoc, ServletException JavaDoc {
68
69         // Get Http parameters
70
mAction = pRequest.getParameter("action");
71         // Form used
72
EjbForm oForm = (EjbForm) m_Session.getAttribute("ejbForm");
73         // Type Ejb used
74
//m_Type = getIntegerType(oForm);
75

76         try {
77             // Execute a method of Ejb
78
executeEjb(oForm);
79         } catch (Throwable JavaDoc t) {
80             addGlobalError(t);
81             saveErrors(pRequest, m_Errors);
82             return (pMapping.findForward("Global Error"));
83         }
84
85         // Forward to the jsp or the action
86
pRequest.setAttribute("select", oForm.getObjectName());
87         return (pMapping.findForward(mForward));
88     }
89
90 // --------------------------------------------------------- Protected Methods
91

92     /**
93      * Dispath executing on Ejb.
94      *
95      * @param pForm Current form
96      * @throws Exception Could not execute the requested action
97      */

98     protected void executeEjb(EjbForm pForm)
99         throws Exception JavaDoc {
100         // Object name used
101
String JavaDoc sObjectName = pForm.getObjectName();
102         ObjectName JavaDoc on = new ObjectName JavaDoc(sObjectName);
103         String JavaDoc mType = pForm.getType(); // j2eeType
104
if (mType.equals("EntityBean")) {
105             // set forward String
106
mForward = "ActionEditEjbEntity";
107             EjbEntityForm eForm = (EjbEntityForm) pForm;
108             String JavaDoc mPersistency = eForm.getPersistency();
109             if (mPersistency.startsWith("Cont")) {
110                 if ("synchronize".equals(mAction)) {
111                     JonasManagementRepr.invoke(on, "synchronize", null, null);
112                 } else if ("reduceCache".equals(mAction)) {
113                     JonasManagementRepr.invoke(on, "reduceCache", null, null);
114                 }
115             }
116         } else if (mType.equals("StatelessSessionBean")) {
117             mForward = "ActionEditEjbSbl";
118             if ("reducePool".equals(mAction)) {
119                 JonasManagementRepr.invoke(on, "reducePoolToMinSize", null, null);
120             }
121         }
122     }
123
124 }
125
Popular Tags