01: /*
02: * Copyright (C) 2004 TiongHiang Lee
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: * Email: thlee@onemindsoft.org
19: */
20:
21: package org.onemind.swingweb.servlet;
22:
23: import java.awt.Window;
24: import java.util.logging.Logger;
25: import javax.servlet.http.*;
26: import org.onemind.awtbridge.BridgeContextSession;
27: import org.onemind.commons.java.lang.reflect.ReflectUtils;
28: import org.onemind.swingweb.*;
29: import org.onemind.swingweb.component.shareapp.ShareAppApplicationInitializer;
30: import org.onemind.swingweb.session.SwingWebSession;
31:
32: /**
33: * A Servlet for initializing the swingweb application. There's only two parameter needed
34: * for the application: <br>
35: * <ul>
36: * <li>app-class - the application class </li>
37: * <li>swingweb-config - the swing web configuration </li>
38: * </ul>
39: *
40: * @author TiongHiang Lee (thlee@onemindsoft.org)
41: *
42: */
43: public class SwingWebShareAppServlet extends AbstractSwingWebServlet {
44:
45: /** the logger * */
46: private static final Logger _logger = Logger
47: .getLogger(SwingWebShareAppServlet.class.getName());
48:
49: /** the component manager **/
50: private SwingWebComponentManager _sharedComponentManager = new SwingWebComponentManager();
51:
52: /** whether the application has been started (used in shareApp mode only) **/
53: private boolean _appStarted = false;;
54:
55: /** the application window **/
56: private Window _app;
57:
58: /**
59: * {@inheritDoc}
60: */
61: protected SwingWebSession createSession(SwingWebContext context,
62: HttpSession httpSession) {
63: SwingWebSession session = new SwingWebSession(
64: _sharedComponentManager);
65: return session;
66: }
67:
68: /**
69: * {@inheritDoc}
70: */
71: protected void startApp(SwingWebSession swSession,
72: HttpServletRequest req, HttpServletResponse resp)
73: throws Exception {
74: if (!_appStarted) {
75: synchronized (getAppClass()) {
76: if (!_appStarted) {
77: _app = getManager().startApp(
78: ReflectUtils.getClass(getAppClass()), null);
79: _appStarted = true;
80: }
81: }
82: }
83: if (_app instanceof ShareAppApplicationInitializer) {
84: ((ShareAppApplicationInitializer) _app)
85: .sessionStartedForApplication(swSession);
86: }
87: }
88:
89: public void sessionEnded(BridgeContextSession session) {
90: super .sessionEnded(session);
91: if (_app instanceof ShareAppApplicationInitializer) {
92: ((ShareAppApplicationInitializer) _app)
93: .sessionEndedForApplication((SwingWebSession) session);
94: }
95: }
96: }
|