View Javadoc

1   //========================================================================
2   //$Id: Jetty6PluginWebAppContext.java 5511 2009-09-08 03:25:47Z 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 = new Jetty6MavenConfiguration();
41      private JettyWebXmlConfiguration jettyWebConfig = new JettyWebXmlConfiguration();
42      private TagLibConfiguration tagConfig = new TagLibConfiguration();
43      private Configuration[] configs = new Configuration[]{webInfConfig,envConfig, mvnConfig, jettyWebConfig, tagConfig};
44      private String contextPath = null;
45      
46      public Jetty6PluginWebAppContext ()
47      {
48          super();
49          setConfigurations(configs);
50      }
51      
52      public void setContextPath(String path)
53      {
54          this.contextPath = path;
55      }
56      
57      public String getContextPath()
58      {
59          return contextPath;
60      }
61      
62      public void setClassPathFiles(List classpathFiles)
63      {
64          this.classpathFiles = classpathFiles;
65      }
66  
67      public List getClassPathFiles()
68      {
69          return this.classpathFiles;
70      }
71      
72      public void setWebXmlFile(File webXmlFile)
73      {
74          this.webXmlFile = webXmlFile;
75      }
76      
77      public File getWebXmlFile()
78      {
79          return this.webXmlFile;
80      }
81      
82      public void setJettyEnvXmlFile (File jettyEnvXmlFile)
83      {
84          this.jettyEnvXmlFile = jettyEnvXmlFile;
85      }
86      
87      public File getJettyEnvXmlFile()
88      {
89          return this.jettyEnvXmlFile;
90      }
91      
92      public void configure ()
93      {        
94          if (this.contextPath != null)
95              super.setContextPath(this.contextPath);
96          
97          setConfigurations(configs);
98          mvnConfig.setClassPathConfiguration (classpathFiles);
99          mvnConfig.setWebXml (webXmlFile);  
100         try
101         {
102             if (this.jettyEnvXmlFile != null)
103                 envConfig.setJettyEnvXml(this.jettyEnvXmlFile.toURL());
104         }
105         catch (Exception e)
106         {
107             throw new RuntimeException(e);
108         }
109     }
110 
111 
112     public void doStart () throws Exception
113     {
114         setShutdown(false);
115         super.doStart();
116     }
117      
118     public void doStop () throws Exception
119     {
120         setShutdown(true);
121         //just wait a little while to ensure no requests are still being processed
122         Thread.currentThread().sleep(500L);
123         super.doStop();
124     }
125 }