1   //========================================================================
2   //$Id: Jetty6PluginWebAppContext.java 3606 2008-09-04 11:20:12Z dyu $
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      public List getClassPathFiles()
63      {
64          return this.classpathFiles;
65      }
66      
67      public void setWebXmlFile(File webXmlFile)
68      {
69          this.webXmlFile = webXmlFile;
70      }
71      
72      public File getWebXmlFile()
73      {
74          return this.webXmlFile;
75      }
76      
77      public void setJettyEnvXmlFile (File jettyEnvXmlFile)
78      {
79          this.jettyEnvXmlFile = jettyEnvXmlFile;
80      }
81      
82      public File getJettyEnvXmlFile()
83      {
84          return this.jettyEnvXmlFile;
85      }
86      
87      public void configure ()
88      {        
89          setConfigurations(configs);
90          mvnConfig.setClassPathConfiguration (classpathFiles);
91          mvnConfig.setWebXml (webXmlFile);  
92          try
93          {
94              if (this.jettyEnvXmlFile != null)
95                  envConfig.setJettyEnvXml(this.jettyEnvXmlFile.toURL());
96          }
97          catch (Exception e)
98          {
99              throw new RuntimeException(e);
100         }
101     }
102 
103 
104     public void doStart () throws Exception
105     {
106         setShutdown(false);
107         super.doStart();
108     }
109      
110     public void doStop () throws Exception
111     {
112         setShutdown(true);
113         //just wait a little while to ensure no requests are still being processed
114         Thread.currentThread().sleep(500L);
115         super.doStop();
116     }
117 }