001/*
002 * ModeShape (http://www.modeshape.org)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *       http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.modeshape.web.jcr;
017
018import javax.servlet.ServletContextEvent;
019import javax.servlet.ServletContextListener;
020
021/**
022 * Servlet context listener that is responsible for {@link RepositoryManager#initialize(javax.servlet.ServletContext)
023 * initializing} the {@link RepositoryManager repository factory}.
024 * <p>
025 * This class is not thread safe, but in practice this does not matter as the servlet container must ensure that only a single
026 * instance of this exists per web context and that it is only called in a single-threaded manner.
027 * </p>
028 * <p>
029 * This class is not thread-safe.
030 * </p>
031 * 
032 * @see RepositoryManager
033 */
034public class ModeShapeJcrDeployer implements ServletContextListener {
035
036    /**
037     * Alerts the repository factory that the web application is shutting down
038     * 
039     * @param event the servlet context event
040     * @see RepositoryManager#shutdown()
041     */
042    @Override
043    public void contextDestroyed( ServletContextEvent event ) {
044        RepositoryManager.shutdown();
045    }
046
047    /**
048     * Initializes the repository factory
049     * 
050     * @param event the servlet context event
051     * @see RepositoryManager#initialize(javax.servlet.ServletContext)
052     */
053    @Override
054    public void contextInitialized( ServletContextEvent event ) {
055        RepositoryManager.initialize(event.getServletContext());
056    }
057}