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    package org.nanocontainer.webcontainer;
010    
011    import org.mortbay.jetty.servlet.ServletHolder;
012    import org.picocontainer.PicoContainer;
013    import org.picocontainer.defaults.DefaultPicoContainer;
014    
015    import javax.servlet.Servlet;
016    
017    public class PicoServletHolder extends ServletHolder {
018    
019        private final PicoContainer parentContainer;
020    
021        public PicoServletHolder(PicoContainer parentContainer) {
022            this.parentContainer = parentContainer;
023        }
024    
025    
026        public PicoServletHolder(Class clazz, PicoContainer parentContainer) {
027            super(clazz);
028            this.parentContainer = parentContainer;
029        }
030    
031        public synchronized Object newInstance() throws InstantiationException, IllegalAccessException {
032            DefaultPicoContainer child = new DefaultPicoContainer(parentContainer);
033            child.registerComponentImplementation(Servlet.class, _class);
034            return child.getComponentInstance(Servlet.class);
035        }
036    
037    }