//----------------------------BEGIN LICENSE----------------------------
/* 
 * Willow : the Open Source WorkFlow Project
 * Distributable under GNU LGPL license by gun.org
 *
 * Copyright (C) 2004-2010  huihoo.org 
 * Copyright (C) 2004-2010  ZosaTapo <dertyang@hotmail.com> 
 * 
 * ====================================================================
 * Project Homepage : http://www.huihoo.org/willow
 * Source Forge     : http://sourceforge.net/projects/huihoo
 * Mailing list     : willow@lists.sourceforge.net 
 */
//----------------------------END  LICENSE-----------------------------
package org.huihoo.willow;

import java.io.IOException;
import java.net.URL;

public interface Deployer extends Container
{

	// ----------------------------------------------------- Manifest TypeConstants

	/**
	 * The ContainerEvent event type sent when a new application is
	 * being installed by <code>install()</code>, before it has been
	 * started.
	 */
	public static final String PRE_INSTALL_EVENT = "pre-install";

	/**
	 * The ContainerEvent event type sent when a new application is
	 * installed by <code>install()</code>, after it has been started.
	 */
	public static final String INSTALL_EVENT = "install";

	/**
	 * The ContainerEvent event type sent when an existing application is
	 * removed by <code>remove()</code>.
	 */
	public static final String REMOVE_EVENT = "remove";

	// --------------------------------------------------------- Public Methods

	/**
	 * Return the name of the Container with which this EngineDeployer is associated.
	 */
	public String getName();


	/**
	 * Install a new workflow application, whose workflow application archive is at the
	 * specified URL, into this container with the specified context path.
	 * A context path of "" (the empty string) should be used for the root
	 * application for this container.  Otherwise, the context path must
	 * start with a slash.
	 *
	 * @param appName The context path to which this application should
	 *  be installed (must be unique)
	 * @param war A URL of type "jar:" that points to a WAR file, or type
	 *  "file:" that points to an unpacked directory structure containing
	 *  the workflow application to be installed
	 *
	 * @exception IllegalArgumentException if the specified context path
	 *  is malformed (it must be "" or start with a slash)
	 * @exception IllegalStateException if the specified context path
	 *  is already attached to an existing workflow application
	 * @exception IOException if an input/output error was encountered
	 *  during installation
	 */
	public void install(String appName, URL war) throws IOException;

	/**
	 * Return the Context for the deployed application that is associated
	 * with the specified context path (if any); otherwise return
	 * <code>null</code>.
	 *
	 * @param appName The context path of the requested web application
	 */
	public Context findDeployedApp(String appName);

	/**
	 * Return the context paths of all deployed web applications in this
	 * Container.  If there are no deployed applications, a zero-length
	 * array is returned.
	 */
	public String[] findDeployedApps();

	/**
	 * Remove an existing workflow application, attached to the specified context
	 * path.  
	 *
	 * @param appName The context path of the application to be removed
	 *
	 * @exception IllegalArgumentException if the specified context path
	 *  is malformed (it must be "" or start with a slash)
	 * @exception IllegalArgumentException if the specified context path does
	 *  not identify a currently installed workflow application
	 * @exception IOException if an input/output error occurs during
	 *  removal
	 */
	public void remove(String appName) throws IOException;

	/**
	 * Remove an existing workflow application, attached to the specified context
	 * path.   Deletes the workflow application war file and/or directory
	 * if they exist in the Host's appBase.
	 *
	 * @param appName The context path of the application to be removed
	 * @param undeploy boolean flag to remove workflow application from server
	 *
	 * @exception IllegalArgumentException if the specified context path
	 *  is malformed (it must be "" or start with a slash)
	 * @exception IllegalArgumentException if the specified context path does
	 *  not identify a currently installed web application
	 * @exception IOException if an input/output error occurs during
	 *  removal
	 */
	public void remove(String appName, boolean undeploy) throws IOException;

	/**
	 * Start an existing workflow application, attached to the specified context
	 * path.  Only starts a workflow application if it is not running.
	 *
	 * @param appName The context path of the application to be started
	 *
	 * @exception IllegalArgumentException if the specified context path
	 *  is malformed (it must be "" or start with a slash)
	 * @exception IllegalArgumentException if the specified context path does
	 *  not identify a currently installed workflow application
	 * @exception IOException if an input/output error occurs during
	 *  startup
	 */
	public void start(String appName) throws IOException;

	/**
	 * Stop an existing workflow application, attached to the specified context
	 * path.  Only stops a workflow application if it is running.
	 *
	 * @param appName The context path of the application to be stopped
	 *
	 * @exception IllegalArgumentException if the specified context path
	 *  is malformed (it must be "" or start with a slash)
	 * @exception IllegalArgumentException if the specified context path does
	 *  not identify a currently installed web application
	 * @exception IOException if an input/output error occurs while stopping
	 *  the web application
	 */
	public void stop(String appName) throws IOException;

}