001: /*
002: * ========================================================================
003: *
004: * Copyright 2003-2004 The Apache Software Foundation.
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * ========================================================================
019: */
020: package org.apache.cactus.integration.ant.container.tomcat;
021:
022: import java.io.File;
023: import java.io.IOException;
024:
025: import org.apache.tools.ant.BuildException;
026: import org.apache.tools.ant.util.FileUtils;
027:
028: /**
029: * Special container support for the Apache Tomcat 4.x servlet container.
030: *
031: * @version $Id: Tomcat4xContainer.java 238811 2004-02-29 10:10:42Z vmassol $
032: */
033: public class Tomcat4xContainer extends AbstractCatalinaContainer {
034: // Instance Variables ------------------------------------------------------
035:
036: /**
037: * A user-specific context xml configuration file.
038: */
039: private File contextXml;
040:
041: // Public Methods ----------------------------------------------------------
042:
043: /**
044: * @return The context xml file, if set or null otherwise
045: */
046: public final File getContextXml() {
047: return this .contextXml;
048: }
049:
050: /**
051: * Sets a user-custom context xml configuration file to use for the test
052: * installation of Tomcat.
053: *
054: * @param theContextXml the custom context xml file to use
055: */
056: public final void setContextXml(File theContextXml) {
057: this .contextXml = theContextXml;
058: }
059:
060: // Container Implementation ------------------------------------------------
061:
062: /**
063: * @see org.apache.cactus.integration.ant.container.Container#init
064: */
065: public final void init() {
066: super .init();
067:
068: if (!getVersion().startsWith("4")) {
069: throw new BuildException(
070: "This element doesn't support version "
071: + getVersion() + " of Tomcat");
072: }
073: }
074:
075: /**
076: * @see org.apache.cactus.integration.ant.container.Container#startUp
077: */
078: public final void startUp() {
079: try {
080: prepare("tomcat4x", "cactus/tomcat4x");
081: invokeBootstrap("start");
082: } catch (IOException ioe) {
083: getLog().error("Failed to startup the container", ioe);
084: throw new BuildException(ioe);
085: }
086: }
087:
088: /**
089: * @see org.apache.cactus.integration.ant.container.Container#shutDown
090: */
091: public final void shutDown() {
092: invokeBootstrap("stop");
093: }
094:
095: /**
096: * Tomcat 4.x-specific setup of a temporary installation of the container.
097: *
098: * @param theResourcePrefix The prefix to use when looking up container
099: * resource in the JAR
100: * @param theDirName The name of the temporary container installation
101: * directory
102: * @throws IOException If an I/O error occurs
103: * @see AbstractCatalinaContainer#prepare(String, String)
104: */
105: protected void prepare(String theResourcePrefix, String theDirName)
106: throws IOException {
107: super .prepare(theResourcePrefix, theDirName);
108:
109: FileUtils fileUtils = FileUtils.newFileUtils();
110:
111: // Copy user-provided context xml file into the temporary webapp/
112: // container directory
113: File webappsDir = new File(getTmpDir(), "webapps");
114: if (getContextXml() != null) {
115: fileUtils.copyFile(getContextXml(), new File(webappsDir,
116: getContextXml().getName()));
117: }
118:
119: }
120:
121: }
|