001    /*****************************************************************************
002     * Copyright (C) NanoContainer Organization. All rights reserved.            *
003     * ------------------------------------------------------------------------- *
004     * The software in this package is published under the terms of the BSD      *
005     * style license a copy of which has been included with this distribution in *
006     * the LICENSE.txt file.                                                     *
007     *                                                                           *
008     *****************************************************************************/
009    
010    package org.nanocontainer.webcontainer;
011    
012    import org.mortbay.jetty.webapp.WebAppContext;
013    import org.mortbay.jetty.webapp.WebXmlConfiguration;
014    import org.mortbay.jetty.webapp.Configuration;
015    import org.picocontainer.PicoContainer;
016    import org.nanocontainer.webcontainer.PicoServletHandler;
017    
018    public class PicoWebAppContext extends WebAppContext {
019        private final PicoContainer parentContainer;
020    
021        public PicoWebAppContext(PicoContainer parentContainer) {
022                 super(null,null,new PicoServletHandler(parentContainer),null);
023            this.parentContainer = parentContainer;
024        }
025    
026        protected void loadConfigurations() throws Exception {
027            super.loadConfigurations();
028            Configuration[]  configurations = getConfigurations();
029            for (int i = 0; i < configurations.length; i++) {
030                if (configurations[i] instanceof WebXmlConfiguration) {
031                    configurations[i] = new PicoWebXmlConfiguration(parentContainer);
032                }
033            }
034            setConfigurations(configurations);
035        }
036    
037    
038    }