001: //========================================================================
002: //$Id: Jetty6PluginWebApplication.java 1246 2006-11-18 10:40:27Z janb $
003: //Copyright 2000-2004 Mort Bay Consulting Pty. Ltd.
004: //------------------------------------------------------------------------
005: //Licensed under the Apache License, Version 2.0 (the "License");
006: //you may not use this file except in compliance with the License.
007: //You may obtain a copy of the License at
008: //http://www.apache.org/licenses/LICENSE-2.0
009: //Unless required by applicable law or agreed to in writing, software
010: //distributed under the License is distributed on an "AS IS" BASIS,
011: //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: //See the License for the specific language governing permissions and
013: //limitations under the License.
014: //========================================================================
015:
016: package org.mortbay.jetty.plugin;
017:
018: import java.io.File;
019: import java.util.List;
020:
021: import org.mortbay.jetty.plugin.util.JettyPluginWebApplication;
022: import org.mortbay.jetty.plus.webapp.EnvConfiguration;
023: import org.mortbay.jetty.webapp.Configuration;
024: import org.mortbay.jetty.webapp.JettyWebXmlConfiguration;
025: import org.mortbay.jetty.webapp.WebAppContext;
026: import org.mortbay.jetty.webapp.WebInfConfiguration;
027:
028: /**
029: * Jetty6PluginWebApplication
030: *
031: * Wrapper for jetty6 WebAppContext
032: *
033: */
034:
035: class Jetty6PluginWebApplication implements JettyPluginWebApplication {
036: private WebAppContext context;
037: private File webAppDir;
038: private File webXmlFile;
039: private File overrideWebXmlFile;
040: private File jettyEnvXmlFile;
041: private List classpathFiles;
042: private Configuration[] configurations = {
043: new WebInfConfiguration(), new EnvConfiguration(),
044: new Jetty6MavenConfiguration(),
045: new JettyWebXmlConfiguration(),
046: new Jetty6MavenTagLibConfiguration() };
047:
048: protected Jetty6PluginWebApplication() {
049: context = new WebAppContext();
050: }
051:
052: public void setContextPath(String path) {
053: context.setContextPath(path);
054: }
055:
056: public String getContextPath() {
057: return this .context.getContextPath();
058: }
059:
060: public void setWebAppSrcDir(File webAppDir) throws Exception {
061: this .webAppDir = webAppDir;
062: context.setWar(webAppDir.getCanonicalPath());
063: }
064:
065: public void setTempDirectory(File tmpDir) {
066: context.setTempDirectory(tmpDir);
067: tmpDir.deleteOnExit();
068: }
069:
070: /**
071: * Set the location of the defaults descriptor to use.
072: * NOTE: if the user hasn't supplied one, then don't set
073: * a null value as we want jetty to use its own default.
074: *
075: * @see org.mortbay.jetty.plugin.util.JettyPluginWebApplication#setWebDefaultXmlFile(java.io.File)
076: */
077: public void setWebDefaultXmlFile(File webDefaultXml)
078: throws Exception {
079: if (webDefaultXml != null)
080: context.setDefaultsDescriptor(webDefaultXml
081: .getCanonicalPath());
082: }
083:
084: public void setOverrideWebXmlFile(File overrideWebXml)
085: throws Exception {
086: this .overrideWebXmlFile = overrideWebXml;
087: if (overrideWebXml != null)
088: context.setOverrideDescriptor(overrideWebXml
089: .getCanonicalPath());
090: }
091:
092: public void configure() {
093:
094: for (int i = 0; i < configurations.length; i++) {
095: if (configurations[i] instanceof Jetty6MavenConfiguration) {
096: ((Jetty6MavenConfiguration) configurations[i])
097: .setClassPathConfiguration(webAppDir,
098: classpathFiles);
099: ((Jetty6MavenConfiguration) configurations[i])
100: .setWebXml(webXmlFile);
101: } else if (configurations[i] instanceof EnvConfiguration) {
102: try {
103: if (this .jettyEnvXmlFile != null)
104: ((EnvConfiguration) configurations[i])
105: .setJettyEnvXml(this .jettyEnvXmlFile
106: .toURL());
107: } catch (Exception e) {
108: throw new RuntimeException(e);
109: }
110: } else if (configurations[i] instanceof Jetty6MavenTagLibConfiguration) {
111: ((Jetty6MavenTagLibConfiguration) configurations[i])
112: .setClassPathFiles(classpathFiles);
113: }
114: }
115:
116: this .context.setConfigurations(configurations);
117: }
118:
119: public void setClassPathFiles(List classpathFiles) {
120: this .classpathFiles = classpathFiles;
121: }
122:
123: public void setWebXmlFile(File webXmlFile) {
124: this .webXmlFile = webXmlFile;
125: }
126:
127: public void setJettyEnvXmlFile(File jettyEnvXmlFile) {
128: this .jettyEnvXmlFile = jettyEnvXmlFile;
129: }
130:
131: public void start() throws Exception {
132: this .context.setShutdown(false);
133: this .context.start();
134: }
135:
136: public void stop() throws Exception {
137: this .context.setShutdown(true);
138: //just wait a little while to ensure no requests are still being processed
139: Thread.currentThread().sleep(500L);
140: this .context.stop();
141: }
142:
143: /**
144: * @see org.mortbay.jetty.plugin.util.JettyPluginWebApplication#getProxiedObject()
145: */
146: public Object getProxiedObject() {
147: return this.context;
148: }
149:
150: }
|