/*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * (the "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
 * 
 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
 * language governing rights and limitations under the License.
 * 
 * The Original Code is the Venice Web Communities System.
 * 
 * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
 * for Silverwrist Design Studios.  Portions created by Eric J. Bowersox are
 * Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.
 * 
 * Contributor(s): 
 */
package com.silverwrist.dynamo.iface;

import java.io.InputStream;
import com.silverwrist.dynamo.except.ScriptingException;

/**
 * The runtime service through which scripts are executed.  Scripts may be loaded from the system
 * {@link com.silverwrist.dynamo.iface.ResourceProvider ResourceProvider}, or through some other means.
 * They are always executed in the context of a {@link com.silverwrist.dynamo.iface.Request Request}.<P>
 * Scripts return values by calling the <CODE>dynamo.scriptReturn()</CODE> or <CODE>dynamo.scriptOutput()</CODE>
 * functions (or their equivalents in whatever scripting language).  These values are returned by the various
 * methods of this interface.
 *
 * @author Eric J. Bowersox &lt;erbo@silcom.com&gt;
 * @version X
 */
public interface ScriptExecute
{
  /**
   * Execute a script contained in a string.
   *
   * @param request The request context this script is executed under.
   * @param language The scripting language the script is written in.
   * @param source_name The name of the script source.
   * @param code The script code.
   * @return The return value from the script.
   * @exception com.silverwrist.dynamo.except.ScriptingException If there was an error parsing or executing the script.
   */
  public Object executeScript(Request request, String language, String source_name, String code)
      throws ScriptingException;

  /**
   * Execute a script loaded from an external source.
   *
   * @param request The request context this script is executed under.
   * @param language The scripting language the script is written in.
   * @param source_name The name of the script source.
   * @param code A stream from which the script code is loaded.
   * @return The return value from the script.
   * @exception com.silverwrist.dynamo.except.ScriptingException If there was an error parsing or executing the script.
   */
  public Object executeScript(Request request, String language, String source_name, InputStream code)
      throws ScriptingException;

  /**
   * Execute a script loaded from the resources.
   *
   * @param request The request context this script is executed under.
   * @param language The scripting language the script is written in.
   * @param resource_name The name of the resource to load and execute.
   * @return The return value from the script.
   * @exception com.silverwrist.dynamo.except.ScriptingException If there was an error parsing or executing the script.
   */
  public Object executeScript(Request request, String language, String resource_name)
      throws ScriptingException;

  /**
   * Execute a script loaded from the resources.  The language of the script is inferred from the resource name.
   *
   * @param request The request context this script is executed under.
   * @param resource_name The name of the resource to load and execute.
   * @return The return value from the script.
   * @exception com.silverwrist.dynamo.except.ScriptingException If there was an error parsing or executing the script.
   */
  public Object executeScript(Request request, String resource_name) throws ScriptingException;

} // end interface ScriptExecute
