KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > jonasadmin > service > container > ApplyWebAppJettyAction


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: ApplyWebAppJettyAction.java,v 1.3 2005/04/21 08:59:54 kemlerp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.webapp.jonasadmin.service.container;
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.ActionMessage;
36 import org.apache.struts.action.ActionForm;
37 import org.apache.struts.action.ActionForward;
38 import org.apache.struts.action.ActionMapping;
39 import org.objectweb.jonas.jmx.JonasManagementRepr;
40 import org.objectweb.jonas.webapp.jonasadmin.JonasAdminException;
41
42 /**
43  * @author Michel-Ange ANTON
44  */

45 public class ApplyWebAppJettyAction extends BaseWebAppAction {
46
47     private static String JavaDoc sDefaultForward = "ActionEditWebAppJetty";
48
49 // --------------------------------------------------------- Protected Variables
50

51 // --------------------------------------------------------- Public Methods
52

53     public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
54         , HttpServletRequest JavaDoc p_Request, HttpServletResponse JavaDoc p_Response)
55         throws IOException JavaDoc, ServletException JavaDoc {
56
57         // Default forward
58
ActionForward oForward = null;
59
60         // Identify the requested action
61
WebAppJettyForm oForm = (WebAppJettyForm) p_Form;
62
63         // Populate
64
try {
65             // Stop the web app
66
if ("stop".equals(oForm.getAction())) {
67                 oForward = stopWebApplication(oForm, p_Mapping);
68             }
69             // Start the web app
70
else if ("start".equals(oForm.getAction())) {
71                 oForward = startWebApplication(oForm, p_Mapping);
72             }
73         } catch (JonasAdminException e) {
74             // Build error
75
m_Errors.add("webapp", new ActionMessage(e.getId()));
76             saveErrors(p_Request, m_Errors);
77             // Return to the current page
78
oForward = new ActionForward(p_Mapping.getInput());
79         } catch (Throwable JavaDoc t) {
80             addGlobalError(t);
81             saveErrors(p_Request, m_Errors);
82             oForward = p_Mapping.findForward("Global Error");
83         }
84
85         // Next Forward
86
return oForward;
87     }
88
89
90 // --------------------------------------------------------- Protected Methods
91

92     /**
93      * Start the current web application.
94      * @param p_Form The current form
95      * @param p_Mapping The current mapping
96      * @return The forward to go to the next page
97      * @throws Exception
98      */

99     protected ActionForward startWebApplication(WebAppJettyForm p_Form, ActionMapping p_Mapping)
100         throws Exception JavaDoc {
101         try {
102             ObjectName JavaDoc onContext = new ObjectName JavaDoc(p_Form.getObjectName());
103             JonasManagementRepr.invoke(onContext, "start", null, null);
104         } catch (Throwable JavaDoc t) {
105             throw new JonasAdminException("error.webapp.start");
106         }
107         return p_Mapping.findForward(sDefaultForward);
108     }
109
110     /**
111      * Stop the current web application.
112      * @param p_Form The current form
113      * @param p_Mapping The current mapping
114      * @return The forward to go to the next page
115      * @throws Exception
116      */

117     protected ActionForward stopWebApplication(WebAppJettyForm p_Form, ActionMapping p_Mapping)
118         throws Exception JavaDoc {
119         try {
120             ObjectName JavaDoc onContext = new ObjectName JavaDoc(p_Form.getObjectName());
121             JonasManagementRepr.invoke(onContext, "stop", null, null);
122         } catch (Throwable JavaDoc t) {
123             throw new JonasAdminException("error.webapp.stop");
124         }
125         return p_Mapping.findForward(sDefaultForward);
126     }
127 }
128
Popular Tags