org.omegahat.Environment.Interpreter
Class InteractiveEvaluator

java.lang.Object
  |
  +--org.omegahat.Environment.Interpreter.BasicEvaluator
        |
        +--org.omegahat.Environment.Interpreter.UtilityEvaluator
              |
              +--org.omegahat.Environment.Interpreter.UserClassEvaluator
                    |
                    +--org.omegahat.Environment.Interpreter.InteractiveEvaluator
All Implemented Interfaces:
DatabaseCustomer, Evaluator, InputConsumer, ManagedEvaluatorInt, PromptSource, java.lang.Runnable, java.io.Serializable
Direct Known Subclasses:
CorbaAugmentedEvaluator, GUIHelpEvaluator, TracingEvaluator

public class InteractiveEvaluator
extends UserClassEvaluator
implements InputConsumer, PromptSource

This is the default evaluator used for an interactive Omegahat session, providing functionality for serializing objects, returning prompt strings, and handling input as an InputConsumer. This object is registered with an InputSupplier and is notified when new input is available.

See Also:
Serialized Form

Field Summary
protected  boolean continuation
          Flag indicating whether we are in continued input mode.
protected  java.lang.String continuationPrompt
          The prompt to be used when in continuation mode.
 boolean interrupt
           
protected  boolean notify_listeners
          Flag indicating whether we want to notify listeners of different evaluation events, specifically not when we are evaluating the prompt expressions.
protected  java.lang.StringBuffer pendingInput
          Contents of the current pending input that is cached across input events in the case of incomplete input.
protected  Evaluable promptExpression
          The normal prompt as an expression which is evaluated each time allowing it to increment the task number, etc.
 
Fields inherited from class org.omegahat.Environment.Interpreter.UserClassEvaluator
classManager
 
Fields inherited from class org.omegahat.Environment.Interpreter.BasicEvaluator
allowUnrestrictedAccess, class_lists, currentExpression, data, databases, debugger, DefaultAttachIndex, defaultDatabase, dynamicClassLoader, errorHandler, evaluationEvent, evaluationListeners, initialized, internalFunctionTables, internalPrimitiveClassNames, internalPrimitiveClassTable, lexer, localClasses, manager, options, output, parser, primitive_classes, primitiveClasses, PrimitiveClassNames, primitiveTypeNames, primitiveTypes, reversePrimitiveTypes, ShowMultipleClasses, sourceStack, stderr, stdout, SubEvaluationListeners, taskHistory, toplevelExpression, warningMessages
 
Fields inherited from interface org.omegahat.Environment.Interpreter.Evaluator
ThisVariableName
 
Constructor Summary
InteractiveEvaluator()
           
InteractiveEvaluator(Evaluator parent)
           
InteractiveEvaluator(EvaluatorManager manager)
           
InteractiveEvaluator(Options opts)
           
 
Method Summary
 ExpressionInt currentExpression(ExpressionInt e)
          Sets the currently active sub-expression being evaluated at this moment.
 java.lang.Object deserialize(java.io.File file)
           
 java.lang.Object deserialize(java.io.File file, boolean zip)
           
 java.lang.Object deserialize(java.io.InputStream stream)
           
 java.lang.Object deserialize(java.io.ObjectInputStream stream)
           
 java.lang.Object deserialize(java.lang.String file)
           
 java.lang.Object deserialize(java.lang.String file, boolean zip)
           
 java.lang.Object evaluate(java.lang.Object expr, java.lang.String input)
          Added so that the interrupt is automatically reset at this point.
 boolean inputReady(InputSupplier src)
          The alternative method used to signal input available from an InputSupplier.
 boolean inputReady(java.lang.String text)
          This is the method from InputConsumer which is called when the InputConsumer has new input for it to process.
 boolean interrupt()
          Allow others to interrupt the current computation, asynchronously.
 boolean notify_listeners()
          Queries the status of whether we are notifying evaluation listeners of events.
 boolean notify_listeners(boolean val)
          Set the flag controlling whether evaluation listeners are to be notified of events.
 int notifyListeners(ExpressionInt e, boolean task)
          Control the notification of listeners by intercepting notification when we are evaluating the prompt.
 void parserError(java.lang.Exception ex)
          Handle parser errors by determining whether it is an incomplete expression or an actual syntax error.
 java.lang.String prompt()
          Return an appropriate value for the prompt, based on whether there is unfinished input or not and potentially evaluating the prompt string as an evaluable expression.
 Evaluable promptExpression()
          Return the current normal prompt expression.
 Evaluable promptExpression(Evaluable expr)
          Set the normal prompt expression that is evaluated each time a new non-continuation prompt is needed.
 Evaluable promptExpression(java.lang.String str)
          Specify the normal prompt expression in textual form, rather than as a pre-parsed expression.
 java.io.ObjectOutputStream serialize(java.lang.Object obj, java.io.File file)
          Serialize the given object to the specified file.
 java.io.ObjectOutputStream serialize(java.lang.Object obj, java.io.ObjectOutputStream stream)
          Version of the serialization that actually writes the serialized data from the object to the stream.
 java.io.ObjectOutputStream serialize(java.lang.Object obj, java.io.OutputStream stream)
          Write a serialized version of the given object on the output stream.
 java.io.ObjectOutputStream serialize(java.lang.Object obj, java.lang.String file)
          Write a serialized version of the specified object to the given file.
 
Methods inherited from class org.omegahat.Environment.Interpreter.UserClassEvaluator
addMethod, classManager, classManager, createInstance, createInstance, createInstance, defineClass, defineClass, defineClass, defineClass, defineClass, defineClass, DefineUserClass, DefineUserClass, DefineUserClass, findUserClass, findUserClass, parseClass, parser
 
Methods inherited from class org.omegahat.Environment.Interpreter.UtilityEvaluator
evaluator, exec, exec, findFile, getEvaluator, setProperty, setProperty
 
Methods inherited from class org.omegahat.Environment.Interpreter.BasicEvaluator
addEvaluationListener, addFunctionTable, addFunctionTable, addSourceInput, addToHistory, allowUnrestrictedAccess, allowUnrestrictedAccess, asObject, asObject, asObject, asObjectName, asPrimitiveClass, assign, assign, assign, asWriter, attach, attach, attach, attach, attach, attach, attach, classInit, classLists, classLists, classPath, classPath, commandLine, convertPrimitive, copy, copy, copyByConstructor, copyBySerialization, createClassLists, currentExpression, data, data, database, database, database, Debug, Debug, Debug, Debug, Debug, debugger, debugger, defaultDatabase, defaultDatabase, defaultDatabase, defaultErrorHandler, detach, detach, displayTask, displayTask, displayWarnings, displayWarnings, dynamicClassLoader, dynamicClassLoader, endSource, endSource, endSource, endTaskEvaluation, error, error, errorHandler, errorHandler, evaluate, evaluate, evaluate, evaluationError, evaluationListeners, evaluationListeners, evaluationListeners, exists, exit, exit, expandClassName, expandedClassPathElement, find, findAsField, findClass, findClass, findClass, findClass, findFunction, findFunctionOrMethod, functionTableList, get, get, get, get, get, get, get, get, get, getBaseURL, getEvaluationEvent, getEvaluationListeners, getField, getSubEvaluationListeners, help, Import, Import, Import, init, initialize, initTaskEvaluation, internalFunctionTables, isPrimitive, isPrimitive, javaVersion, lexer, lexer, lexer, localClasses, localClasses, manager, manager, newDatabase, newDatabase, notifyListeners, objects, objects, objects, options, options, output, output, output, parse, parse, parse, parse, primitiveClass, q, q, remove, remove, remove, removeFunctionTable, run, same, searchForClass, searchPath, searchPath, searchPath, searchPath, setEvaluationEvent, setEvaluationListeners, setSubEvaluationListeners, show, show, show, source, source, source, source, source, source, source, source, source, sourceStack, stderr, stderr, stdout, stdout, taskHistory, taskHistory, toplevelExpression, toplevelExpression, useLazyEvaluation, warning, warning, warning, warnings, warnings, where, which, which
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

notify_listeners

protected boolean notify_listeners
Flag indicating whether we want to notify listeners of different evaluation events, specifically not when we are evaluating the prompt expressions.

continuation

protected boolean continuation
Flag indicating whether we are in continued input mode.

continuationPrompt

protected java.lang.String continuationPrompt
The prompt to be used when in continuation mode.

pendingInput

protected java.lang.StringBuffer pendingInput
Contents of the current pending input that is cached across input events in the case of incomplete input.

promptExpression

protected Evaluable promptExpression
The normal prompt as an expression which is evaluated each time allowing it to increment the task number, etc.

interrupt

public boolean interrupt
Constructor Detail

InteractiveEvaluator

public InteractiveEvaluator()

InteractiveEvaluator

public InteractiveEvaluator(Options opts)

InteractiveEvaluator

public InteractiveEvaluator(Evaluator parent)

InteractiveEvaluator

public InteractiveEvaluator(EvaluatorManager manager)
Method Detail

inputReady

public boolean inputReady(java.lang.String text)
This is the method from InputConsumer which is called when the InputConsumer has new input for it to process. This attempts to parse and evaluate the expression provided in the text, having it appended it to any outstanding input caused by incomplete expressions in previous notifications.
Specified by:
inputReady in interface InputConsumer

inputReady

public boolean inputReady(InputSupplier src)
The alternative method used to signal input available from an InputSupplier. This extracts the input from the supplier and passes it to the inputReady() method.
Specified by:
inputReady in interface InputConsumer

prompt

public java.lang.String prompt()
Return an appropriate value for the prompt, based on whether there is unfinished input or not and potentially evaluating the prompt string as an evaluable expression. The actual values are read from the Options object associated with this evaluator.
Specified by:
prompt in interface PromptSource

notify_listeners

public boolean notify_listeners()
Queries the status of whether we are notifying evaluation listeners of events.

notify_listeners

public boolean notify_listeners(boolean val)
Set the flag controlling whether evaluation listeners are to be notified of events.

notifyListeners

public int notifyListeners(ExpressionInt e,
                           boolean task)
Control the notification of listeners by intercepting notification when we are evaluating the prompt.
Overrides:
notifyListeners in class BasicEvaluator
Following copied from class: org.omegahat.Environment.Interpreter.BasicEvaluator
Parameters:
task - indicates whether this is a top-level expression or a sub-expression within a top-level task.

promptExpression

public Evaluable promptExpression()
Return the current normal prompt expression.

promptExpression

public Evaluable promptExpression(Evaluable expr)
Set the normal prompt expression that is evaluated each time a new non-continuation prompt is needed.

promptExpression

public Evaluable promptExpression(java.lang.String str)
Specify the normal prompt expression in textual form, rather than as a pre-parsed expression.

parserError

public void parserError(java.lang.Exception ex)
Handle parser errors by determining whether it is an incomplete expression or an actual syntax error. In the former case, we can continue, emitting a continuation prompt.

serialize

public java.io.ObjectOutputStream serialize(java.lang.Object obj,
                                            java.lang.String file)
                                     throws java.io.IOException
Write a serialized version of the specified object to the given file.
Parameters:
obj - object to be serialized.
file - name of file to which the output should be serialized.

serialize

public java.io.ObjectOutputStream serialize(java.lang.Object obj,
                                            java.io.File file)
                                     throws java.io.IOException
Serialize the given object to the specified file.

currentExpression

public ExpressionInt currentExpression(ExpressionInt e)
Description copied from class: BasicEvaluator
Sets the currently active sub-expression being evaluated at this moment. Each of the expression objects registers themselves at the beginning of their own eval() method
Overrides:
currentExpression in class BasicEvaluator

evaluate

public java.lang.Object evaluate(java.lang.Object expr,
                                 java.lang.String input)
                          throws java.lang.Throwable
Added so that the interrupt is automatically reset at this point.
Overrides:
evaluate in class BasicEvaluator

serialize

public java.io.ObjectOutputStream serialize(java.lang.Object obj,
                                            java.io.OutputStream stream)
                                     throws java.io.IOException
Write a serialized version of the given object on the output stream.

serialize

public java.io.ObjectOutputStream serialize(java.lang.Object obj,
                                            java.io.ObjectOutputStream stream)
                                     throws java.io.IOException
Version of the serialization that actually writes the serialized data from the object to the stream.

interrupt

public boolean interrupt()
Allow others to interrupt the current computation, asynchronously.

deserialize

public java.lang.Object deserialize(java.lang.String file)
                             throws java.lang.ClassNotFoundException,
                                    java.io.StreamCorruptedException,
                                    java.io.IOException,
                                    java.io.OptionalDataException

deserialize

public java.lang.Object deserialize(java.lang.String file,
                                    boolean zip)
                             throws java.lang.ClassNotFoundException,
                                    java.io.StreamCorruptedException,
                                    java.io.IOException,
                                    java.io.OptionalDataException

deserialize

public java.lang.Object deserialize(java.io.File file)
                             throws java.lang.ClassNotFoundException,
                                    java.io.StreamCorruptedException,
                                    java.io.IOException,
                                    java.io.OptionalDataException

deserialize

public java.lang.Object deserialize(java.io.File file,
                                    boolean zip)
                             throws java.lang.ClassNotFoundException,
                                    java.io.StreamCorruptedException,
                                    java.io.IOException,
                                    java.io.OptionalDataException

deserialize

public java.lang.Object deserialize(java.io.InputStream stream)
                             throws java.lang.ClassNotFoundException,
                                    java.io.StreamCorruptedException,
                                    java.io.IOException,
                                    java.io.OptionalDataException

deserialize

public java.lang.Object deserialize(java.io.ObjectInputStream stream)
                             throws java.lang.ClassNotFoundException,
                                    java.io.IOException,
                                    java.io.OptionalDataException