1   //========================================================================
2   //$Id: Jetty6PluginWebAppContext.java 2419 2008-03-07 01:06:43Z janb $
3   //Copyright 2006 Mort Bay Consulting Pty. Ltd.
4   //------------------------------------------------------------------------
5   //Licensed under the Apache License, Version 2.0 (the "License");
6   //you may not use this file except in compliance with the License.
7   //You may obtain a copy of the License at 
8   //http://www.apache.org/licenses/LICENSE-2.0
9   //Unless required by applicable law or agreed to in writing, software
10  //distributed under the License is distributed on an "AS IS" BASIS,
11  //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  //See the License for the specific language governing permissions and
13  //limitations under the License.
14  //========================================================================
15  
16  package org.mortbay.jetty.plugin;
17  
18  import java.io.File;
19  import java.util.List;
20  
21  import org.mortbay.jetty.plus.webapp.EnvConfiguration;
22  import org.mortbay.jetty.webapp.Configuration;
23  import org.mortbay.jetty.webapp.JettyWebXmlConfiguration;
24  import org.mortbay.jetty.webapp.TagLibConfiguration;
25  import org.mortbay.jetty.webapp.WebAppContext;
26  import org.mortbay.jetty.webapp.WebInfConfiguration;
27  
28  /**
29   * Jetty6PluginWebAppContext
30   *
31   *
32   */
33  public class Jetty6PluginWebAppContext extends WebAppContext
34  {
35      private List classpathFiles;
36      private File jettyEnvXmlFile;
37      private File webXmlFile;
38      private WebInfConfiguration webInfConfig = new WebInfConfiguration();
39      private EnvConfiguration envConfig =  new EnvConfiguration();
40      private Jetty6MavenConfiguration mvnConfig;
41      private JettyWebXmlConfiguration jettyWebConfig;
42      private TagLibConfiguration tagConfig;
43      private Configuration[] configs;
44      
45      public Jetty6PluginWebAppContext ()
46      throws Exception
47      {
48          super();
49         
50          mvnConfig = new Jetty6MavenConfiguration();
51          jettyWebConfig = new JettyWebXmlConfiguration();
52          tagConfig =  new TagLibConfiguration();
53          configs = new Configuration[]{webInfConfig,envConfig, mvnConfig, jettyWebConfig, tagConfig};
54          setConfigurations(configs);
55      }
56      
57      public void setClassPathFiles(List classpathFiles)
58      {
59          this.classpathFiles = classpathFiles;
60      }
61  
62      
63      public void setWebXmlFile(File webXmlFile)
64      {
65          this.webXmlFile = webXmlFile;
66      }
67      
68      public void setJettyEnvXmlFile (File jettyEnvXmlFile)
69      {
70          this.jettyEnvXmlFile = jettyEnvXmlFile;
71      }
72      
73      public void configure ()
74      {        
75          setConfigurations(configs);
76          mvnConfig.setClassPathConfiguration (classpathFiles);
77          mvnConfig.setWebXml (webXmlFile);  
78          try
79          {
80              if (this.jettyEnvXmlFile != null)
81                  envConfig.setJettyEnvXml(this.jettyEnvXmlFile.toURL());
82          }
83          catch (Exception e)
84          {
85              throw new RuntimeException(e);
86          }
87      }
88  
89  
90      public void doStart () throws Exception
91      {
92          setShutdown(false);
93          super.doStart();
94      }
95       
96      public void doStop () throws Exception
97      {
98          setShutdown(true);
99          //just wait a little while to ensure no requests are still being processed
100         Thread.currentThread().sleep(500L);
101         super.doStop();
102     }
103 }