001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.servlet;
016    
017    import com.liferay.portal.kernel.deploy.hot.HotDeployEvent;
018    import com.liferay.portal.kernel.deploy.hot.HotDeployUtil;
019    import com.liferay.portal.kernel.util.BasePortalLifecycle;
020    
021    import javax.servlet.ServletContext;
022    import javax.servlet.ServletContextEvent;
023    import javax.servlet.ServletContextListener;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public class WebContextListener
029            extends BasePortalLifecycle implements ServletContextListener {
030    
031            public void contextDestroyed(ServletContextEvent servletContextEvent) {
032                    portalDestroy();
033            }
034    
035            public void contextInitialized(ServletContextEvent servletContextEvent) {
036                    _servletContext = servletContextEvent.getServletContext();
037    
038                    Thread currentThread = Thread.currentThread();
039    
040                    _webClassLoader = currentThread.getContextClassLoader();
041    
042                    registerPortalLifecycle();
043            }
044    
045            @Override
046            protected void doPortalDestroy() {
047                    HotDeployUtil.fireUndeployEvent(
048                            new HotDeployEvent(_servletContext, _webClassLoader));
049            }
050    
051            @Override
052            protected void doPortalInit() {
053                    HotDeployUtil.fireDeployEvent(
054                            new HotDeployEvent(_servletContext, _webClassLoader));
055            }
056    
057            private ServletContext _servletContext;
058            private ClassLoader _webClassLoader;
059    
060    }