KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > j2eedo > web > ApplicationServlet


1 /**
2  * Speedo: an implementation of JDO compliant personality on top of JORM generic
3  * I/O sub-system.
4  * Copyright (C) 2001-2004 France Telecom R&D
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 of the License, or (at your option) 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 USA
19  *
20  * Release: 1.0
21  *
22  * Created on 2004-02-18
23  * @author fmillevi@yahoo.com
24  *
25  */

26 package org.objectweb.speedo.j2eedo.web;
27
28 import java.io.IOException JavaDoc;
29 import java.rmi.RemoteException JavaDoc;
30
31 import javax.jdo.JDOException;
32 import javax.servlet.ServletOutputStream JavaDoc;
33 import javax.servlet.http.HttpServletRequest JavaDoc;
34 import javax.servlet.http.HttpServletResponse JavaDoc;
35
36 import org.objectweb.speedo.j2eedo.common.PMHolder;
37 import org.objectweb.speedo.j2eedo.bo.DatabaseImpl;
38 import org.objectweb.speedo.j2eedo.ejb.StoreServicesLocal;
39 import org.objectweb.speedo.j2eedo.ejb.StoreServicesRemote;
40
41 /**
42  * is an extended of the former servlet MainServlet. This class implements the
43  * two methods used to execute the resquest through a Session Bean or directly
44  * from the {@link org.objectweb.speedo.j2eedo.bo.DatabaseImpl DataBaseImpl} class.</li>
45  * </ul>
46  *
47  * @author fmillevi@yahoo.com
48  *
49  */

50 public class ApplicationServlet extends MainServlet {
51     /**
52      * The constant <code>PARAMETER_ACTION</code> defines the HTTP
53      * requests paramater <b>"action"</b> use to know
54      * {@link org.objectweb.speedo.j2eedo.bo.DatabaseImpl#actionArray which action} to do.
55      */

56     final public static String JavaDoc PARAMETER_ACTION = "action";
57
58     private DatabaseImpl departmentImpl = null;
59
60     /**
61      * @see org.objectweb.speedo.j2eedo.web.MainServlet#executeSessionBean(javax.servlet.http.HttpServletRequest,
62      * javax.servlet.http.HttpServletResponse,
63      * org.objectweb.speedo.j2eedo.ejb.StoreServicesRemote,
64      * org.objectweb.speedo.j2eedo.common.PMHolder)
65      */

66     protected void executeSessionBean(HttpServletRequest JavaDoc req,
67             HttpServletResponse JavaDoc resp,
68             StoreServicesLocal storeServices,
69             PMHolder persistenceManagerHolder) throws JDOException,
70             RemoteException JavaDoc, Exception JavaDoc, IOException JavaDoc {
71         ServletOutputStream JavaDoc out = resp.getOutputStream();
72         out.println(storeServices.doAction(
73                 persistenceManagerHolder, req.getParameter(PARAMETER_ACTION)));
74     }
75
76     protected void executeSessionBean(HttpServletRequest JavaDoc req,
77             HttpServletResponse JavaDoc resp,
78             StoreServicesRemote storeServices)
79             throws JDOException, RemoteException JavaDoc, Exception JavaDoc, IOException JavaDoc {
80         ServletOutputStream JavaDoc out = resp.getOutputStream();
81         out.println(storeServices.doAction(req.getParameter(PARAMETER_ACTION)));
82     }
83
84     /**
85      * @see org.objectweb.speedo.j2eedo.web.MainServlet#executeDirectCall(javax.servlet.http.HttpServletRequest,
86      * javax.servlet.http.HttpServletResponse,
87      * org.objectweb.speedo.j2eedo.common.PMHolder)
88      * javax.servlet.ServletOutputStream)
89      */

90     protected void executeDirectCall(
91         HttpServletRequest JavaDoc req,
92         HttpServletResponse JavaDoc resp,
93         PMHolder persistenceManagerHolder)
94         throws JDOException, IOException JavaDoc, Exception JavaDoc {
95         ServletOutputStream JavaDoc out = resp.getOutputStream();
96         if (departmentImpl == null) {
97             departmentImpl = new DatabaseImpl(persistenceManagerHolder);
98         }
99         out.println(
100             departmentImpl.doAction(
101                 req.getParameter(ApplicationServlet.PARAMETER_ACTION)));
102     }
103 }
Popular Tags