1 package fr.ifremer.coser.web; 2 3 /* 4 * #%L 5 * Coser :: Web 6 * %% 7 * Copyright (C) 2010 - 2014 Ifremer, Codelutin, Chemit Tony 8 * %% 9 * This program is free software: you can redistribute it and/or modify 10 * it under the terms of the GNU Affero General Public License as published by 11 * the Free Software Foundation, either version 3 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU Affero General Public License 20 * along with this program. If not, see <http://www.gnu.org/licenses/>. 21 * #L% 22 */ 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 27 import javax.servlet.ServletContextEvent; 28 import javax.servlet.ServletContextListener; 29 import java.util.Date; 30 31 /** 32 * To listen start and end of the application. 33 * <p/> 34 * On start we will init the application context ({@link CoserWebApplicationContext#init()}). 35 * <p/> 36 * On stop, just release close the application context ({@link CoserWebApplicationContext#close()}). 37 * 38 * @author tchemit <chemit@codelutin.com> 39 * @since 1.5 40 */ 41 public class CoserApplicationListener implements ServletContextListener { 42 43 /** Logger. */ 44 protected static final Log log = 45 LogFactory.getLog(CoserApplicationListener.class); 46 47 @Override 48 public void contextInitialized(ServletContextEvent sce) { 49 50 if (log.isInfoEnabled()) { 51 log.info("Application starting at " + new Date() + "..."); 52 } 53 CoserWebApplicationContext.init(); 54 } 55 56 @Override 57 public void contextDestroyed(ServletContextEvent sce) { 58 if (log.isInfoEnabled()) { 59 log.info("Application is ending at " + new Date() + "..."); 60 } 61 CoserWebApplicationContext.close(); 62 } 63 }