/*
 * <copyright>
 *  Copyright (c) 2001 by Hyperwave AG
 * </copyright>
 *
 * <file>
 *  Name:        AbstractCmd.js
 *  Created:     2001-01-14
 *  $Id: AbstractCmd.js,v 1.4 2003/07/03 08:05:57 mmair Exp $
 * </file>
 */

initPackage ( "com.hyperwave.res" );
loadClass ( "com.hyperwave.res.ForCmd" );
loadClass ( "com.hyperwave.res.IfCmd" );
loadClass ( "com.hyperwave.res.IterateCmd" );
loadClass ( "com.hyperwave.res.WithCmd" );
loadClass ( "com.hyperwave.res.DebugCmd" );

//----------------------------------------------------------------------
/**
 * This abstract class combines a general constructor for 
 * and language constructs and a factory that creates commands
 * by means of a command name.
 */
// <JSClass Name="com.hyperwave.res.AbstractCmd">

  //--------------------------------------------------------------------
  /**
   * Sets the <i>data placeholder</i> of commands. This constructor
   * assumes that the parameter object has the right properties because
   * commands should not be constructed outside this class.
   * @param aParam: Object: 
   * @param aParam.expression_: String: The name of the data
   *   placeholder for this command.
   */
  com.hyperwave.res.AbstractCmd = function ( aParam )
  {
    if ( aParam == "__proto__" )
      return;

    this.expression_ = aParam.expression_;
  }
  class$ = doInherit ( com.hyperwave.res.AbstractCmd );

  //--------------------------------------------------------------------
  /**
   * Parse the command's body into the command structure. This 
   * function will be called by the enclosing template's parser
   * to <i>continue</i> parsing. Note that a command must always
   * end with an end command. The parsing function returns a
   * parser state like defined in the template class.
   * @param theTemplateTail: String: the template string which
   *   follows the begin of the current command.
   * @return Object: the state object.
   * @see com.hyperwave.res.Template
   */
  class$.doParse = function ( theTemplateTail )
  {
    // abstract!
  }

  //--------------------------------------------------------------------
  /**
   * Executes the command in the given environment. This means 
   * that the data placeholder is evaluated and iterated in this
   * case.
   * @param theEnv: com.hyperwave.res.ScopedMap: the current environment.
   * @return String: the final string after evaluation
   */
  class$.execCmd = function ( theEnv )
  {
    // abstract!
  }

  //--------------------------------------------------------------------
  /**
   * This factory is used to get a command classs by means of a command
   * string. Currently this factory is "wired" but it can use an
   * abstract class loading too.
   * @param aParam: Object: with the following properties
   * @param aParam.command_: String: the command string like 
   *   <code>for</code>
   * @param aParam.dataPHolder_: String: the name of the command's
   *   data placeholder. This placeholder will be used to evaluate
   *   the command.
   * @return com.hyperwave.res.AbstractCmd: a command object.
   */
  class$.static_.getCommand = function ( aParam )
  {
    if ( aParam == null ||
         aParam.command_ == null )
      return null;

    var cmd;
    switch ( aParam.command_ )
    {
    case "if":
      cmd = new com.hyperwave.res.IfCmd ( aParam );
      break;
    case "for":
      cmd = new com.hyperwave.res.ForCmd ( aParam );
      break;
    case "iterate":
      cmd = new com.hyperwave.res.IterateCmd ( aParam );
      break;
    case "with":
      cmd = new com.hyperwave.res.WithCmd ( aParam );
      break;
    case "debug":
      cmd = new com.hyperwave.res.DebugCmd ( aParam );
      break;
    }
    return cmd;
  }

// </JSClass>
//----------------------------------------------------------------------

/* End of "com.hyperwave.res.AbstractCmd.js" */

