View Javadoc

1   //========================================================================
2   //$Id: Jetty6PluginWebAppContext.java 3605 2008-09-04 10:24:54Z 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 = 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      
45      public Jetty6PluginWebAppContext ()
46      {
47          super();
48          setConfigurations(configs);
49      }
50      
51      public void setClassPathFiles(List classpathFiles)
52      {
53          this.classpathFiles = classpathFiles;
54      }
55  
56      public List getClassPathFiles()
57      {
58          return this.classpathFiles;
59      }
60      
61      public void setWebXmlFile(File webXmlFile)
62      {
63          this.webXmlFile = webXmlFile;
64      }
65      
66      public File getWebXmlFile()
67      {
68          return this.webXmlFile;
69      }
70      
71      public void setJettyEnvXmlFile (File jettyEnvXmlFile)
72      {
73          this.jettyEnvXmlFile = jettyEnvXmlFile;
74      }
75      
76      public File getJettyEnvXmlFile()
77      {
78          return this.jettyEnvXmlFile;
79      }
80      
81      public void configure ()
82      {        
83          setConfigurations(configs);
84          mvnConfig.setClassPathConfiguration (classpathFiles);
85          mvnConfig.setWebXml (webXmlFile);  
86          try
87          {
88              if (this.jettyEnvXmlFile != null)
89                  envConfig.setJettyEnvXml(this.jettyEnvXmlFile.toURL());
90          }
91          catch (Exception e)
92          {
93              throw new RuntimeException(e);
94          }
95          /*
96          Configuration[] configurations = getConfigurations();
97          for (int i=0;i<configurations.length; i++)
98          {
99              if (configurations[i] instanceof Jetty6MavenConfiguration)
100             {
101                 ((Jetty6MavenConfiguration)configurations[i]).setClassPathConfiguration (classpathFiles);
102                 ((Jetty6MavenConfiguration)configurations[i]).setWebXml (webXmlFile);              
103             }
104             else if (configurations[i] instanceof EnvConfiguration)
105             {
106                 try
107                 {
108                     if (this.jettyEnvXmlFile != null)
109                         ((EnvConfiguration)configurations[i]).setJettyEnvXml(this.jettyEnvXmlFile.toURL());
110                 }
111                 catch (Exception e)
112                 {
113                     throw new RuntimeException(e);
114                 }
115             }
116         }
117         */
118     }
119 
120 
121     public void doStart () throws Exception
122     {
123         setShutdown(false);
124         super.doStart();
125     }
126      
127     public void doStop () throws Exception
128     {
129         setShutdown(true);
130         //just wait a little while to ensure no requests are still being processed
131         Thread.currentThread().sleep(500L);
132         super.doStop();
133     }
134 }