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.picocontainer.jetty;
011
012 import org.mortbay.jetty.servlet.ServletHandler;
013 import org.mortbay.jetty.webapp.Configuration;
014 import org.mortbay.jetty.webapp.WebAppContext;
015 import org.mortbay.jetty.webapp.WebXmlConfiguration;
016 import org.picocontainer.PicoContainer;
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 boolean doSuperIsRunning = true;
027
028 protected void loadConfigurations() throws Exception {
029 super.loadConfigurations();
030 Configuration[] configurations = getConfigurations();
031 for (int i = 0; i < configurations.length; i++) {
032 if (configurations[i] instanceof WebXmlConfiguration) {
033 configurations[i] = new PicoWebXmlConfiguration(parentContainer);
034 }
035 }
036 doSuperIsRunning = false;
037 setConfigurations(configurations);
038 doSuperIsRunning = true;
039 }
040
041 @Override
042 public boolean isRunning() {
043 if (doSuperIsRunning) {
044 return super.isRunning();
045 } else {
046 return false;
047 }
048 }
049 /* ------------------------------------------------------------ */
050 public ServletHandler getServletHandler() {
051 return super.getServletHandler();
052 }
053 }