sleep.runtime
Class ScriptEnvironment

java.lang.Object
  extended bysleep.runtime.ScriptEnvironment
All Implemented Interfaces:
Serializable

public class ScriptEnvironment
extends Object
implements Serializable

This class contains methods for accessing the data stack, return value of a function, and the environment hashtable for a script. In sleep each ScriptInstance has a ScriptEnvironment object associated with it. Most of the functions in this class are used internally by sleep.

For the developers purposes, this class is your gateway into the runtime environment of a script.

If you use the evaluate methods to evaluate a snippet of code, they will be evaluated as if they were part of the script file that this ScriptEnvironment represents.

The Hashtable environment contains references for all of the loaded bridges this script has access to. Every function, predicate, and operator is specified in the environment hashtable. To force scripts to share this information use setEnvironment(Hashtable) and pass the same instance of Hashtable that other scripts are using.

This class is instantiated by sleep.runtime.ScriptInstance.

See Also:
ScriptLoader, ScriptInstance, Serialized Form

Field Summary
protected  Hashtable environment
          the environment hashtable that contains all of the functions, predicates, operators, and "environment keywords" this script has access to.
protected  Stack environmentStack
          the runtime data stack for this environment
protected  String errorMessage
          stored error message...
protected  int findex
           
protected  ArrayList frames
           
protected  boolean isBreak
          value that determines if we are breaking out of the current loop or not
protected  ScriptInstance self
          the script instance that this is the environment for
 
Constructor Summary
ScriptEnvironment()
          Not recommended that you instantiate a script environment in this way
ScriptEnvironment(Hashtable env, ScriptInstance myscript)
          Instantiate a new script environment with the specified environment (can be shared), and the specified ScriptInstance
 
Method Summary
 String checkError()
          once an error is checked using this function, it is cleared, the orignal error message is returned as well
 void clearCache()
          clears the cache of parsed and evaluated strings used by the "evaluate*" methods
 void clearReturn()
           
 void CreateFrame()
           
 Scalar evaluateExpression(String code)
          evaluates an expression
 Scalar evaluateParsedLiteral(String code)
          evaluates the passed in code as if it was a sleep parsed literal
 boolean evaluatePredicate(String code)
          evaluates a predicate condition
 Scalar evaluateStatement(String code)
          evaluate a full blown statement...
 void flagBreak(boolean flag)
          determine wether or not we want to break out of the current loop
 void flagError(String message)
          A utility for bridge writers to flag an error.
 void flagReturn(Scalar value)
           
 Stack getCurrentFrame()
           
 Hashtable getEnvironment()
          Returns the environment for this script.
 Stack getEnvironmentStack()
          returns the environment stack used for temporary calculations and such.
 FilterEnvironment getFilterEnvironment(String env)
           
 Function getFunction(String func)
           
 Environment getFunctionEnvironment(String env)
           
 Operator getOperator(String oper)
           
 Predicate getPredicate(String name)
           
 PredicateEnvironment getPredicateEnvironment(String env)
           
 Scalar getReturnValue()
           
 Scalar getScalar(String key)
          returns a scalar from this scripts environment
 ScriptInstance getScriptInstance()
          returns a reference to the script associated with this environment
 ScriptVariables getScriptVariables()
          returns the variable manager for this script
 boolean isBreak()
          checks wether or not we want to break out of the current loop
 boolean isReturn()
           
 void KillFrame()
           
 void putScalar(String key, Scalar value)
          puts a scalar into this scripts environment
 void setEnvironment(Hashtable h)
          Sets the environment Hashtable this script is to use.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

self

protected ScriptInstance self
the script instance that this is the environment for


environmentStack

protected Stack environmentStack
the runtime data stack for this environment


environment

protected Hashtable environment
the environment hashtable that contains all of the functions, predicates, operators, and "environment keywords" this script has access to.


errorMessage

protected String errorMessage
stored error message...


frames

protected ArrayList frames

findex

protected int findex

isBreak

protected boolean isBreak
value that determines if we are breaking out of the current loop or not

Constructor Detail

ScriptEnvironment

public ScriptEnvironment()
Not recommended that you instantiate a script environment in this way


ScriptEnvironment

public ScriptEnvironment(Hashtable env,
                         ScriptInstance myscript)
Instantiate a new script environment with the specified environment (can be shared), and the specified ScriptInstance

Method Detail

getScriptInstance

public ScriptInstance getScriptInstance()
returns a reference to the script associated with this environment


flagError

public void flagError(String message)
A utility for bridge writers to flag an error. flags an error that script writers can then check for with checkError(). Currently used by the IO bridge openf, exec, and connect functions. Major errors should bubble up as exceptions. Small stuff like being unable to open a certain file should be flagged this way.


checkError

public String checkError()
once an error is checked using this function, it is cleared, the orignal error message is returned as well


getScriptVariables

public ScriptVariables getScriptVariables()
returns the variable manager for this script


getScalar

public Scalar getScalar(String key)
returns a scalar from this scripts environment


putScalar

public void putScalar(String key,
                      Scalar value)
puts a scalar into this scripts environment


getFunction

public Function getFunction(String func)

getFunctionEnvironment

public Environment getFunctionEnvironment(String env)

getPredicateEnvironment

public PredicateEnvironment getPredicateEnvironment(String env)

getFilterEnvironment

public FilterEnvironment getFilterEnvironment(String env)

getPredicate

public Predicate getPredicate(String name)

getOperator

public Operator getOperator(String oper)

getEnvironment

public Hashtable getEnvironment()
Returns the environment for this script. The environment has the following formats for keys: &[keyname] - a sleep function -[keyname] - assumed to be a unary predicate [keyname] - assumed to be an environment binding, predicate, or operator


setEnvironment

public void setEnvironment(Hashtable h)
Sets the environment Hashtable this script is to use. Sharing an instance of this Hashtable allows scripts to share common environment data like functions, subroutines, etc. Also useful for bridge writers as their information can be stored in this hashtable as well


getEnvironmentStack

public Stack getEnvironmentStack()
returns the environment stack used for temporary calculations and such.


toString

public String toString()

getReturnValue

public Scalar getReturnValue()

isReturn

public boolean isReturn()

flagReturn

public void flagReturn(Scalar value)

clearReturn

public void clearReturn()

getCurrentFrame

public Stack getCurrentFrame()

KillFrame

public void KillFrame()

CreateFrame

public void CreateFrame()

flagBreak

public void flagBreak(boolean flag)
determine wether or not we want to break out of the current loop


isBreak

public boolean isBreak()
checks wether or not we want to break out of the current loop


clearCache

public void clearCache()
clears the cache of parsed and evaluated strings used by the "evaluate*" methods


evaluateStatement

public Scalar evaluateStatement(String code)
                         throws YourCodeSucksException
evaluate a full blown statement... probably best to just load a script at this point

Throws:
YourCodeSucksException

evaluatePredicate

public boolean evaluatePredicate(String code)
                          throws YourCodeSucksException
evaluates a predicate condition

Throws:
YourCodeSucksException

evaluateExpression

public Scalar evaluateExpression(String code)
                          throws YourCodeSucksException
evaluates an expression

Throws:
YourCodeSucksException

evaluateParsedLiteral

public Scalar evaluateParsedLiteral(String code)
                             throws YourCodeSucksException
evaluates the passed in code as if it was a sleep parsed literal

Throws:
YourCodeSucksException