/**
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 2006-2011 Bull S.A.S.
 * Contact: jonas-team@ow2.org
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * --------------------------------------------------------------------------
 * $Id$
 * --------------------------------------------------------------------------
 */
package org.ow2.jonas.antmodular.jonasbase.web.tomcat6;

import org.ow2.jonas.antmodular.jonasbase.web.tomcat.TomcatSessionManager;
import org.ow2.jonas.antmodular.web.base.Cluster;
import org.ow2.jonas.antmodular.jonasbase.web.tomcat.Tomcat;
import org.ow2.jonas.antmodular.web.base.SessionReplication;

/**
 * Support Tomcat Connector Configuration.
 * Prefered order : http, director, ajp, https, cluster.
 *
 * @author Jeremy Cazaux
 */
public class Tomcat6 extends Tomcat {

    /**
     * Name of the tomcat server file
    */
    public static final String TOMCAT_SERVER_CONF_FILE = "tomcat6-server.xml";

    /**
     * Name of the implementation class for Tomcat.
     */
    private static final String TOMCAT_SERVICE = "org.ow2.jonas.web.tomcat6.Tomcat6Service";

    /**
     * Name of the tomcat context file
     */
    public static final String TOMCAT_CONTEXT_CONF_FILE = "tomcat6-context.xml";

    /**
     * Default Constructor.
     */
    public Tomcat6() {
        super();
    }

    /**
     * Set the port number for the WebContainer
     * @param portNumber the port number
     */
    @Override
    public void setPort(final String portNumber) {
        super.setPort(portNumber, TOMCAT_SERVER_CONF_FILE, "tomcat");
    }

    /**
     * Configure Tomcat6's connectors
     * @param tomcat6Connectors
     */
    public void addConfiguredConnectors(final Tomcat6Connectors tomcat6Connectors) {
        this.tasks.add(tomcat6Connectors);
    }

    /**
     * Configure a Cluster HTTP Session.
     * @param cluster Cluster HTTP Session.
     */
    @Deprecated
    public void addConfiguredCluster(final Cluster cluster) {
        addConfiguredSessionReplication(cluster);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void addConfiguredSessionReplication(final SessionReplication sessionReplication) {
        super.addConfiguredSessionReplication(sessionReplication, TOMCAT_SERVER_CONF_FILE);
    }

    /**
     * Configure a jvmRoute.
     * @param jvmRoute jvm route name
     */
    public void setJvmRoute(final String jvmRoute) {
        super.setJvmRoute(jvmRoute, TOMCAT_SERVER_CONF_FILE);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void addConfiguredSessionManager(final TomcatSessionManager tomcatSessionManager) {
        super.addConfiguredSessionManager(tomcatSessionManager, TOMCAT_CONTEXT_CONF_FILE);
    }

    /**
     * Execute all tasks
     */
    @Override
    public void execute() {
        super.execute();
        super.createServiceNameReplace(this.TOMCAT_SERVICE, this.INFO, destDir.getAbsolutePath() + this.CONF_DIR);
    }
}
