/*
* Copyright (C) 2004 TiongHiang Lee
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Email: thlee@onemindsoft.org
*/
package org.onemind.swingweb.servlet;
import java.awt.Window;
import java.util.logging.Logger;
import javax.servlet.http.*;
import org.onemind.awtbridge.BridgeContextSession;
import org.onemind.commons.java.lang.reflect.ReflectUtils;
import org.onemind.swingweb.*;
import org.onemind.swingweb.component.shareapp.ShareAppApplicationInitializer;
import org.onemind.swingweb.session.SwingWebSession;
/**
* A Servlet for initializing the swingweb application. There's only two parameter needed
* for the application: <br>
* <ul>
* <li>app-class - the application class </li>
* <li>swingweb-config - the swing web configuration </li>
* </ul>
*
* @author TiongHiang Lee (thlee@onemindsoft.org)
*
*/
public class SwingWebShareAppServlet extends AbstractSwingWebServlet
{
/** the logger * */
private static final Logger _logger = Logger.getLogger(SwingWebShareAppServlet.class.getName());
/** the component manager **/
private SwingWebComponentManager _sharedComponentManager = new SwingWebComponentManager();
/** whether the application has been started (used in shareApp mode only) **/
private boolean _appStarted = false;;
/** the application window **/
private Window _app;
/**
* {@inheritDoc}
*/
protected SwingWebSession createSession(SwingWebContext context, HttpSession httpSession)
{
SwingWebSession session = new SwingWebSession(_sharedComponentManager);
return session;
}
/**
* {@inheritDoc}
*/
protected void startApp(SwingWebSession swSession, HttpServletRequest req, HttpServletResponse resp) throws Exception
{
if (!_appStarted)
{
synchronized (getAppClass())
{
if (!_appStarted)
{
_app = getManager().startApp(ReflectUtils.getClass(getAppClass()), null);
_appStarted = true;
}
}
}
if (_app instanceof ShareAppApplicationInitializer)
{
((ShareAppApplicationInitializer) _app).sessionStartedForApplication(swSession);
}
}
public void sessionEnded(BridgeContextSession session)
{
super.sessionEnded(session);
if (_app instanceof ShareAppApplicationInitializer)
{
((ShareAppApplicationInitializer) _app).sessionEndedForApplication((SwingWebSession) session);
}
}
}