com.sun.slamd.scripting.engine
Class ScriptParser

java.lang.Object
  extended bycom.sun.slamd.scripting.engine.ScriptParser

public class ScriptParser
extends java.lang.Object

This class implements a mechanism for parsing and executing script files that specify instructions for performing operations in a SLAMD job. The set of reserved words understood by this parser is hard-coded, but the set of data types that may be used is flexible and may be extended by the end user.


Field Summary
static java.lang.String[] AUTO_INCLUDED_VARIABLE_TYPES
          The set of variable types that will be automatically included and available to scripts without the need for an explicit "use" definition.
static java.lang.String RESERVED_WORD_BEGIN
          The reserved word that is used to indicate the beginning of an instruction block.
static java.lang.String RESERVED_WORD_BREAK
          The reserved word that is used to indicate that execution of the current loop should stop immediately and that execution should resume with the next instruction immediately after the loop.
static java.lang.String RESERVED_WORD_CONTINUE
          The reserved word that is used to indicate that the execution of the current loop iteration should stop immediately and that the next iteration should begin if appropriate.
static java.lang.String RESERVED_WORD_ELSE
          The reserved word that is used to execute an instruction if the boolean value associated with the immediately preceding if statement is false.
static java.lang.String RESERVED_WORD_END
          The reserved word that is used to indicate the end of an instruction block.
static java.lang.String RESERVED_WORD_IF
          The reserved word that is used to execute an instruction if the associated boolean value is true.
static java.lang.String RESERVED_WORD_IF_NOT
          The reserved word that is used to execute an instruction if the associated boolean value is false.
static java.lang.String RESERVED_WORD_LOOP
          The reserved word that is used to execute an instruction a specified number of times.
static java.lang.String RESERVED_WORD_USE
          The reserved word that is used to define a new variable type for use in the SLAMD script.
static java.lang.String RESERVED_WORD_VARIABLE
          The reserved word that is used to define a new variable instance for use in the SLAMD script.
static java.lang.String RESERVED_WORD_WHILE
          The reserved word that is used to execute an instruction until a specified condition becomes false.
static java.lang.String RESERVED_WORD_WHILE_NOT
          The reserved word that is used to execute an instruction until a specified condition becomes true.
static java.lang.String VARIABLE_TYPE_SUPERCLASS_NAME
          The Java class name that is the superclass of all variable types that may be used in SLAMD scripts.
 
Constructor Summary
ScriptParser()
          Creates a new script parser that can be used to parse and execute a SLAMD script.
 
Method Summary
 void debugExecute(JobClass jobThread)
          Executes the script in debug mode, sending debug information to the client's message writer.
 void execute(JobClass jobThread)
          Executes the script.
 java.lang.String getScriptArgument(java.lang.String argumentName)
          Retrieves the value of the specified script argument.
 StatTracker[] getStatTrackers()
          Retrieves the set of statistics gathered while running this script.
static boolean isReservedWord(java.lang.String token)
          Indicates whether the specified token is one of the reserved words in the SLAMD scripting environment.
 void parse()
          Parses the script information and tokenizes the instructions so that they may be more easily and efficiently executed.
 java.lang.String peekAtNextToken()
          Retrieves the next token from the script but preserves the internal markers used to keep track of the position in the script.
 void read(java.io.InputStream inputStream)
          Reads the script file data from the specified input stream into memory.
 void read(java.lang.String filename)
          Reads the specified script file into memory.
 void registerVariableType(java.lang.String className)
          Registers a variable type definition for use in the SLAMD script.
 void setScriptArguments(java.util.Hashtable scriptArgumentHash)
          Specifies the script arguments to use with this script.
 void setScriptLines(java.lang.String[] lines)
          Specifies the lines to use for the script.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AUTO_INCLUDED_VARIABLE_TYPES

public static final java.lang.String[] AUTO_INCLUDED_VARIABLE_TYPES
The set of variable types that will be automatically included and available to scripts without the need for an explicit "use" definition.


VARIABLE_TYPE_SUPERCLASS_NAME

public static final java.lang.String VARIABLE_TYPE_SUPERCLASS_NAME
The Java class name that is the superclass of all variable types that may be used in SLAMD scripts.

See Also:
Constant Field Values

RESERVED_WORD_USE

public static final java.lang.String RESERVED_WORD_USE
The reserved word that is used to define a new variable type for use in the SLAMD script.

See Also:
Constant Field Values

RESERVED_WORD_VARIABLE

public static final java.lang.String RESERVED_WORD_VARIABLE
The reserved word that is used to define a new variable instance for use in the SLAMD script.

See Also:
Constant Field Values

RESERVED_WORD_BEGIN

public static final java.lang.String RESERVED_WORD_BEGIN
The reserved word that is used to indicate the beginning of an instruction block.

See Also:
Constant Field Values

RESERVED_WORD_END

public static final java.lang.String RESERVED_WORD_END
The reserved word that is used to indicate the end of an instruction block.

See Also:
Constant Field Values

RESERVED_WORD_IF

public static final java.lang.String RESERVED_WORD_IF
The reserved word that is used to execute an instruction if the associated boolean value is true.

See Also:
Constant Field Values

RESERVED_WORD_IF_NOT

public static final java.lang.String RESERVED_WORD_IF_NOT
The reserved word that is used to execute an instruction if the associated boolean value is false.

See Also:
Constant Field Values

RESERVED_WORD_ELSE

public static final java.lang.String RESERVED_WORD_ELSE
The reserved word that is used to execute an instruction if the boolean value associated with the immediately preceding if statement is false.

See Also:
Constant Field Values

RESERVED_WORD_LOOP

public static final java.lang.String RESERVED_WORD_LOOP
The reserved word that is used to execute an instruction a specified number of times.

See Also:
Constant Field Values

RESERVED_WORD_WHILE

public static final java.lang.String RESERVED_WORD_WHILE
The reserved word that is used to execute an instruction until a specified condition becomes false.

See Also:
Constant Field Values

RESERVED_WORD_WHILE_NOT

public static final java.lang.String RESERVED_WORD_WHILE_NOT
The reserved word that is used to execute an instruction until a specified condition becomes true.

See Also:
Constant Field Values

RESERVED_WORD_BREAK

public static final java.lang.String RESERVED_WORD_BREAK
The reserved word that is used to indicate that execution of the current loop should stop immediately and that execution should resume with the next instruction immediately after the loop.

See Also:
Constant Field Values

RESERVED_WORD_CONTINUE

public static final java.lang.String RESERVED_WORD_CONTINUE
The reserved word that is used to indicate that the execution of the current loop iteration should stop immediately and that the next iteration should begin if appropriate.

See Also:
Constant Field Values
Constructor Detail

ScriptParser

public ScriptParser()
             throws ScriptException
Creates a new script parser that can be used to parse and execute a SLAMD script.

Throws:
ScriptException - If there is a problem initializing the script parser or loading the automatically included variable types.
Method Detail

registerVariableType

public void registerVariableType(java.lang.String className)
                          throws ScriptException
Registers a variable type definition for use in the SLAMD script.

Parameters:
className - The name of the Java class that provides the variable type definition.
Throws:
ScriptException - If the specified class cannot be found, cannot be instantiated, does not define a variable type, or defines a variable type that is already in use.

read

public void read(java.lang.String filename)
          throws java.io.IOException
Reads the specified script file into memory.

Parameters:
filename - The path and name of the script file to be read.
Throws:
java.io.IOException - If there is a problem reading from the script file.

read

public void read(java.io.InputStream inputStream)
          throws java.io.IOException
Reads the script file data from the specified input stream into memory.

Parameters:
inputStream - The input stream from which the script file data will be read.
Throws:
java.io.IOException - If there is a problem reading the script file data.

setScriptLines

public void setScriptLines(java.lang.String[] lines)
Specifies the lines to use for the script.

Parameters:
lines - The lines to use for the script.

setScriptArguments

public void setScriptArguments(java.util.Hashtable scriptArgumentHash)
Specifies the script arguments to use with this script.

Parameters:
scriptArgumentHash - The set of arguments to use in conjunction with this script.

getScriptArgument

public java.lang.String getScriptArgument(java.lang.String argumentName)
Retrieves the value of the specified script argument.

Parameters:
argumentName - The name of the script argument to retrieve.
Returns:
The value of the requested script argument, or null if it was not defined.

parse

public void parse()
           throws ScriptException
Parses the script information and tokenizes the instructions so that they may be more easily and efficiently executed.

Throws:
ScriptException - If the script cannot be parsed as a valid SLAMD script (i.e., if the script contains one or more syntax errors).

peekAtNextToken

public java.lang.String peekAtNextToken()
                                 throws ScriptException
Retrieves the next token from the script but preserves the internal markers used to keep track of the position in the script. That is, it retrieves the next token that will be returned by the call to nextToken().

Returns:
The next token that will be returned by nextToken().
Throws:
ScriptException - If there is a problem while parsing the next token.

isReservedWord

public static boolean isReservedWord(java.lang.String token)
Indicates whether the specified token is one of the reserved words in the SLAMD scripting environment. It is expected that the token will be in all lowercase characters.

Parameters:
token - The token for which to make the determination.
Returns:
true if the specified token is one of the reserved words, or false if not.

execute

public void execute(JobClass jobThread)
             throws ScriptException
Executes the script. The script must have already been read in and parsed into tokens.

Parameters:
jobThread - The job thread that will be executing the script.
Throws:
ScriptException - If a problem occurs while executing the script.

debugExecute

public void debugExecute(JobClass jobThread)
                  throws ScriptException
Executes the script in debug mode, sending debug information to the client's message writer. The script must have already been read in and parsed into tokens.

Parameters:
jobThread - The job thread that will be executing the script.
Throws:
ScriptException - If a problem occurs while executing the script.

getStatTrackers

public StatTracker[] getStatTrackers()
Retrieves the set of statistics gathered while running this script.

Returns:
The set of statistics gathered while running this script.