/*
 * <copyright>
 *  Copyright (c) 2001 by Hyperwave AG
 * </copyright>
 *
 * <file>
 *  Name:        DebugCmd.js
 *  Created:     2001-01-14
 *  $Id: DebugCmd.js,v 1.3 2003/07/03 08:05:58 mmair Exp $
 * </file>
 */

initPackage ( "com.hyperwave.res" );
loadClass ( "com.hyperwave.res.ResourceException" );
loadClass ( "com.hyperwave.res.ScopedMap" );

//----------------------------------------------------------------------
/**
 * This "pseudo" command writes the content of a placeholder
 * by means of the placeholder's <code>toSource</code> method.
 * It can be used like the <i>iterate</i> command but it has
 * some addititional output.
 */
// <JSClass Name="com.hyperwave.res.DebugCmd">

  //--------------------------------------------------------------------
  /**
   * Construct the for command node.
   * @see com.hyperwave.res.AbstractCmd
   */
  com.hyperwave.res.DebugCmd = function ( aParam )
  {
    if ( aParam == "__proto__" )
      return;

    this.base$ = com.hyperwave.res.AbstractCmd;
    this.base$ ( aParam );
    delete this.base$;
  }
  class$ = doInherit ( com.hyperwave.res.DebugCmd, 
                       com.hyperwave.res.AbstractCmd );

  //--------------------------------------------------------------------
  /**
   * Parses the rest of the <code>for</code> command. This is done
   * by finding the next <code>endfor</code>.
   * @see com.hyperwave.res.AbstractCmd#doParse
   */
  class$.doParse = function ( theTemplateTail )
  {
  writeln ( "DDDDDEBUG: debug command" );
    var state = {};
    state.textTail_ = theTemplateTail;
    return state;
  }

  //--------------------------------------------------------------------
  /**
   * Executes the command in the given environment. This means 
   * that the data placeholder is evaluated and iterated in this
   * case.
   * @see com.hyperwave.res.AbstractCmd#execCmd
   */
  class$.execCmd = function ( theEnv )
  {
    var out_array = [];
    out_array [out_array.length] = "\n-------------------------------------";
    out_array [out_array.length] = "Debug:";
    out_array [out_array.length] = "  Placeholder Name: " + this.dataPHolder_;
    out_array [out_array.length] = "  Placeholder Value: >>>>";
    
    value = theEnv.get ( this.dataPHolder_ );
    if ( value == null )
      out_array [out_array.length] = value;
    else 
      out_array [out_array.length] = value.toSource ();
    out_array [out_array.length] = "<<<<\n";
    out_array [out_array.length] = "-------------------------------------\n";
    writelnError ( out_array.join ("\n") );
    return out_array.join ("\n");
  }

// </JSClass>
//----------------------------------------------------------------------

/* End of "com.hyperwave.res.DebugCmd.js" */
