FileDocCategorySizeDatePackage
AbstractTomcatTask.javaAPI DocExample2742Sat Mar 15 19:39:56 GMT 2003com.oreilly.javaxp.tomcat.tasks

AbstractTomcatTask.java

package com.oreilly.javaxp.tomcat.tasks;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;

/**
 * @author Brian M. Coyner
 * @version $Id: AbstractTomcatTask.java,v 1.4 2003/02/27 00:29:33 jepc Exp $
 */
public abstract class AbstractTomcatTask extends Task {

    private TomcatSupport tomcatSupport;

    /**
     * Overrides the base class implementation to instantiate the
     * <code>TomcatSupport</code> class.
     */
    public void init() {
        this.tomcatSupport =
                new TomcatSupport(this, getScriptToExecute(), isStarting());
    }

    /**
     * @return the name of the script to execute. For Tomcat 4.0 and
     * higher a valid filename might be 'startup'. The name of the script
     * should <strong>not</strong> include the extension.
     */
    public abstract String getScriptToExecute();

    /**
     * @return true if Tomcat is being started; false if Tomcat is being
     * stopped.
     */
    public abstract boolean isStarting();

    /**
     * Called by Ant to start the execution of the target.
     */
    public void execute() throws BuildException {
        this.tomcatSupport.execute();
    }

    /**
     * Called by Ant to set the attribute 'testURL'. This attribute is
     * referenced in the buildfile.
     *
     * @param testURL a URL that is used to connect to Tomcat. This URL
     * is used to validate that Tomcat is running.
     */
    public void setTestURL(String testURL) {
        this.tomcatSupport.setTestURL(testURL);
    }

    /**
     * Called by Ant to set the attribute 'catalinaHome'. This attribute is
     * referenced in the buildfile.
     *
     * @param catalinaHome the full path to where Tomcat is installed.
     */
    public void setCatalinaHome(String catalinaHome) {
        this.tomcatSupport.setCatalinaHome(catalinaHome);
    }

    /**
     * @param timeout a number representing the timeout in
     * milliseconds. The timeout must be greater than 10 seconds
     * (10000 ms) and less than 60 seconds (60000 ms).
     */
    public void setTimeout(String timeout) {
        try {
            long temp = Long.parseLong(timeout);
            if (temp >= 10000 && temp <= 60000) {
                this.tomcatSupport.setTimeout(temp);
            } else {
                throw new BuildException("Invalid 'timeout' value: "
                                         + timeout + ". The timeout must be between " +
                                         "10000 and 60000.");
            }
        } catch (NumberFormatException nfe) {
            throw new BuildException("Invalid 'timeout' value: " + timeout);
        }
    }
}