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.WebXmlConfiguration; 013 import org.mortbay.jetty.servlet.ServletHolder; 014 import org.mortbay.jetty.servlet.FilterHolder; 015 import org.picocontainer.PicoContainer; 016 import org.picocontainer.defaults.DefaultPicoContainer; 017 018 019 public class PicoWebXmlConfiguration extends WebXmlConfiguration { 020 021 private PicoContainer parentContainer; 022 023 public PicoWebXmlConfiguration(PicoContainer parentContainer) { 024 this.parentContainer = parentContainer; 025 } 026 027 protected ServletHolder newServletHolder() { 028 return new PicoServletHolder(parentContainer); 029 } 030 031 protected FilterHolder newFilterHolder() { 032 return new PicoFilterHolder(parentContainer); 033 } 034 035 protected Object newListenerInstance(Class clazz) throws InstantiationException, IllegalAccessException { 036 DefaultPicoContainer child = new DefaultPicoContainer(parentContainer); 037 child.registerComponentImplementation("listener", clazz); 038 return child.getComponentInstance("listener"); 039 } 040 041 }