jwo.landserf.script
Class ScriptEngine

java.lang.Object
  extended by jwo.landserf.script.ScriptEngine
All Implemented Interfaces:
Runnable, JWInterruptionListener

public class ScriptEngine
extends Object
implements Runnable, JWInterruptionListener

Allows LandSerf functions to be called from the command line or script file.

Version:
2.3, 10th February, 2009.
Author:
Jo Wood

Field Summary
static String COPYRIGHT
          Copyright statement.
static String DATE
          Last modified date.
static float VERSION
          Current numeric version of LandScript.
static String VERSION_TEXT
          Text representing current version of LandScript.
 
Constructor Summary
ScriptEngine()
          Sets up the script engine with a default text-based gisFrame to hold spatial objects and report results.
ScriptEngine(GISFrame gisFrame)
          Sets up the script engine using the given gisFrame to hold spatial objects and report results.
 
Method Summary
 void addVariableListener(VariableListener varListener)
          Adds a variable listener to those that are informed when the number of variables stored by the script engine changes.
 void checkScript()
          Checks the script currently stored in this object.
 HashSet getCommands()
          Reports the list of commands available to the script engine.
 String getFormattedCommandText()
          Reports a formatted list of commands and their parameters.
 HashSet getFunctions()
          Reports the list of functions available to the script engine.
 String getReservedWords()
          Reports an alphabetical list of all reserved words (keywords and functions).
 void interruptionRequested()
          Responds to a request for an interruption of the script.
static void main(String[] args)
          Starts the LandScript interpreter with the given script file.
 void parseFile(String fileName)
          Parses the script stored in the given file.
 boolean removeVariableListener(VariableListener varListener)
          Removes the given variable listener from those that are informed when the number of variables stored by the script engine changes.
 void run()
          Parses the script currently stored in this object.
 void setEditor(ScriptEditor scriptEditor)
          Sets the script editor in which extra messages and progress can be reported.
 void setLogger(Logger otherLogger)
          Allows a logger to capture script engine input.
 void setScript(String script)
          Sets the script to be parsed.
 void showError()
          Displays an empty error message indicating the line that caused it.
 void showError(String message)
          Displays an error message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION_TEXT

public static final String VERSION_TEXT
Text representing current version of LandScript.

See Also:
Constant Field Values

VERSION

public static final float VERSION
Current numeric version of LandScript.

See Also:
Constant Field Values

DATE

public static final String DATE
Last modified date.

See Also:
Constant Field Values

COPYRIGHT

public static final String COPYRIGHT
Copyright statement.

See Also:
Constant Field Values
Constructor Detail

ScriptEngine

public ScriptEngine()
Sets up the script engine with a default text-based gisFrame to hold spatial objects and report results.


ScriptEngine

public ScriptEngine(GISFrame gisFrame)
Sets up the script engine using the given gisFrame to hold spatial objects and report results.

Parameters:
gisFrame - GISFrame that stores spatial objects and outputs messages.
Method Detail

main

public static void main(String[] args)
Starts the LandScript interpreter with the given script file. If the -gui option is included, this will start the graphical LandScript editor, if not, the given script will be run.

Parameters:
args - Command line argument containing name of LandScript file to read.

setLogger

public void setLogger(Logger otherLogger)
Allows a logger to capture script engine input. As each script command is interpreted it is sent to the given logger as Level.FINE. Note that output from the scripting is sent to the supplied GISFrame, stdout or stderr.

Parameters:
otherLogger - Logger to receive messages.

addVariableListener

public void addVariableListener(VariableListener varListener)
Adds a variable listener to those that are informed when the number of variables stored by the script engine changes. Note that the listeners are not informed if the contents of any variables have changed.

Parameters:
varListener - Variable listener to add.

removeVariableListener

public boolean removeVariableListener(VariableListener varListener)
Removes the given variable listener from those that are informed when the number of variables stored by the script engine changes.

Parameters:
varListener - Variable listener to remove.
Returns:
True if given listener was found and removed.

parseFile

public void parseFile(String fileName)
Parses the script stored in the given file. Any errors are reported to the gisFrame provided in the constructor.

Parameters:
fileName - Name of file containing script instructions.

getReservedWords

public String getReservedWords()
Reports an alphabetical list of all reserved words (keywords and functions).

Returns:
Alphabetical list of reserved words.

getFormattedCommandText

public String getFormattedCommandText()
Reports a formatted list of commands and their parameters. Excludes map algebra functions such as tan(), max() etc.

Returns:
Formatted command list.

getCommands

public HashSet getCommands()
Reports the list of commands available to the script engine. Excludes map algebra functions such as tan(), max() etc.

Returns:
Formatted command list.

getFunctions

public HashSet getFunctions()
Reports the list of functions available to the script engine. Excludes LandScript commands (e.g. open(), colouredit()) etc.

Returns:
Formatted function list.

setScript

public void setScript(String script)
Sets the script to be parsed. To parse a given script, call this method, then call the run() method. The script can also be parsed as a threaded process by passing this object to a Thread and calling its start() method.

Parameters:
script - Script that can be parsed.

setEditor

public void setEditor(ScriptEditor scriptEditor)
Sets the script editor in which extra messages and progress can be reported. This is not necessary, but can be used to separate messages that apply to the entire script from those produced by the commands within the script.

Parameters:
scriptEditor - GUI in which messages and progress can be reported.

run

public void run()
Parses the script currently stored in this object. The script can be set by either calling parseFile() or setScript(). Will report an error if the script cannot be parsed.

Specified by:
run in interface Runnable

checkScript

public void checkScript()
Checks the script currently stored in this object. Will also update the list of variables and user-defined functions used by the script. Should report an error if script cannot be parsed.


interruptionRequested

public void interruptionRequested()
Responds to a request for an interruption of the script.

Specified by:
interruptionRequested in interface JWInterruptionListener

showError

public void showError()
Displays an empty error message indicating the line that caused it.


showError

public void showError(String message)
Displays an error message.

Parameters:
message - Message to display.


Copyright Jo Wood, 1996-2009, last modified, 17th April, 2009