001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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    }