001 /**
002 *
003 * $Revision: 13776 $ $Date: 2008-07-29 16:31:02 +0200 (Di, 29 Jul 2008) $
004 *
005 * This file is part of ** M y C o R e **
006 * Visit our homepage at http://www.mycore.de/ for details.
007 *
008 * This program is free software; you can use it, redistribute it
009 * and / or modify it under the terms of the GNU General Public License
010 * (GPL) as published by the Free Software Foundation; either version 2
011 * of the License or (at your option) any later version.
012 *
013 * This program is distributed in the hope that it will be useful, but
014 * WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program, normally in the file license.txt.
020 * If not, write to the Free Software Foundation Inc.,
021 * 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
022 *
023 **/
024 package org.mycore.common.events;
025
026 import javax.servlet.ServletContextEvent;
027 import javax.servlet.ServletContextListener;
028
029 import org.apache.log4j.Logger;
030
031 import org.mycore.common.MCRConfiguration;
032
033 /**
034 * is a shutdown hook for the current <code>ServletContext</code>.
035 *
036 * For this class to register itself as a shutdown hook to the current ServletContext please add the following code to your web.xml (allready done in MyCoRe-shipped version):
037 * <pre>
038 <listener>
039 <listener-class>org.mycore.common.events.MCRServletContextListener</listener-class>
040 </listener>
041 * </pre>
042 *
043 * @author Thomas Scheffler (yagee)
044 * @see org.mycore.common.events.MCRShutdownHandler
045 * @since 1.3
046 */
047 public class MCRServletContextListener implements ServletContextListener {
048
049 private static final Logger LOGGER = Logger.getLogger(MCRServletContextListener.class);
050
051 public void contextInitialized(ServletContextEvent sce) {
052 //Make sure logging is configured
053 MCRConfiguration.instance();
054 // register to MCRShutdownHandler
055 LOGGER.info("Register ServletContextListener to MCRShutdownHandler");
056 MCRShutdownHandler.getInstance().isWebAppRunning = true;
057 }
058
059 public void contextDestroyed(ServletContextEvent sce) {
060 // shutdown event
061 MCRShutdownHandler.getInstance().shutDown();
062 }
063 }