edu.rice.cs.drjava.model.repl
Class DefaultInteractionsModel

java.lang.Object
  extended by edu.rice.cs.drjava.model.repl.InteractionsModel
      extended by edu.rice.cs.drjava.model.repl.RMIInteractionsModel
          extended by edu.rice.cs.drjava.model.repl.DefaultInteractionsModel
All Implemented Interfaces:
InteractionsModelCallback

public class DefaultInteractionsModel
extends RMIInteractionsModel

Interactions model which can notify GlobalModelListeners on events. TODO: remove invokeLater wrappers here and enforce the policy that all of the listener methods must use them

Version:
$Id: DefaultInteractionsModel.java 5237 2010-04-27 07:52:59Z mgricken $

Field Summary
protected  DefaultGlobalModel _model
          Model that contains the interpreter to use.
 
Fields inherited from class edu.rice.cs.drjava.model.repl.RMIInteractionsModel
_jvm
 
Fields inherited from class edu.rice.cs.drjava.model.repl.InteractionsModel
_autoImportSet, _cDoc, _document, _inputListener, _lastError, _notifier, _pane, _secondToLastError, _waitingForFirstInterpreter, _workingDirectory, _writerLock, BANNER_PREFIX, WRITE_DELAY
 
Constructor Summary
DefaultInteractionsModel(DefaultGlobalModel model, MainJVM jvm, ConsoleDocumentInterface cDoc, File wd)
          Creates a new InteractionsModel.
 
Method Summary
protected  void _interpreterResetFailed(Throwable t)
          Any extra action to perform (beyond notifying listeners) when the interpreter fails to reset.
protected  void _interpreterWontStart(Exception e)
          Action to perform when the interpreter won't start.
protected  void _notifyInteractionEnded()
          In the event thread, notifies listeners that an interaction has ended.
protected  void _notifyInteractionIncomplete()
          In the event thread, notifies the view that the current interaction is incomplete.
 void _notifyInteractionStarted()
          In the event thread, notifies listeners that an interaction has started.
protected  void _notifyInterpreterChanged(boolean inProgress)
          In the event thread, notifies listeners that the interpreter has changed.
protected  void _notifyInterpreterExited(int status)
          In the event thread, notifies listeners that the interpreter has exited unexpectedly.
 void _notifyInterpreterReady(File wd)
          In the event thread, notifies listeners that the interpreter is ready.
protected  void _notifyInterpreterResetFailed(Throwable t)
          In the event thread, notifies listeners that the interpreter reset failed.
protected  void _notifyInterpreterResetting()
          In the event thread, notifies listeners that the interpreter is resetting.
protected  void _notifySyntaxErrorOccurred(int offset, int length)
          In the event thread, notifies listeners that an error was present in the interaction.
 List<File> getCompilerBootClassPath()
          A compiler can instruct DrJava to include additional elements for the boot class path of the Interactions JVM.
 ConsoleDocument getConsoleDocument()
          Gets the console tab document for this interactions model
 String getConsoleInput()
          Returns a line of text entered by the user at the equivalent of System.in.
 void interpreterReady(File wd)
          Called when the Java interpreter is ready to use.
 StackTraceElement[] replaceLLException(StackTraceElement[] stackTrace)
          overides method in InteractionModel.java and changes stackTrace for a throwable if LL files are present
 void replSystemErrPrint(String s)
          Called when the repl prints to System.err.
 void replSystemOutPrint(String s)
          Called when the repl prints to System.out.
 String transformCommands(String interactionsString)
          Transform the command line to be interpreted into something the Interactions JVM can use.
 
Methods inherited from class edu.rice.cs.drjava.model.repl.RMIInteractionsModel
_interpret, _resetInterpreter, addBuildDirectoryClassPath, addExternalFilesClassPath, addExtraClassPath, addInterpreter, addProjectClassPath, addProjectFilesClassPath, getClassPath, getVariableToString, removeInterpreter, setActiveInterpreter, setEnforceAllAccess, setEnforcePrivateAccess, setRequireSemicolon, setRequireVariableType, setToDefaultInterpreter
 
Methods inherited from class edu.rice.cs.drjava.model.repl.InteractionsModel
_addNewline, _createNewDebugPort, _getHistoryText, _interactionIsOver, _removeSeparators, _writerDelay, addListener, append, autoImport, changeInputListener, getBanner, getBanner, getDebugPort, getDocument, getLastError, getSecondToLastError, getStartUpBanner, getWorkingDirectory, interactionContinues, interpret, interpretCurrentInteraction, interpreterResetFailed, interpreterResetting, interpreterWontStart, loadHistory, loadHistoryAsScript, performDefaultImports, removeAllInteractionListeners, removeLastFromHistory, removeListener, replCalledSystemExit, replReturnedResult, replReturnedSyntaxError, replReturnedVoid, replThrewException, replThrewException, resetInterpreter, resetLastErrors, scrollToCaret, setDebugPort, setInputListener, setUpPane, setWaitingForFirstInterpreter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_model

protected final DefaultGlobalModel _model
Model that contains the interpreter to use.

Constructor Detail

DefaultInteractionsModel

public DefaultInteractionsModel(DefaultGlobalModel model,
                                MainJVM jvm,
                                ConsoleDocumentInterface cDoc,
                                File wd)
Creates a new InteractionsModel.

Parameters:
model - DefaultGlobalModel to do the interpretation
jvm - the RMI interface used by the Main JVM to access the Interpreter JVM
cDoc - document
wd - the working directory for interactions i/o
Method Detail

replSystemOutPrint

public void replSystemOutPrint(String s)
Called when the repl prints to System.out. This method can safely be called from outside the event thread.

Specified by:
replSystemOutPrint in interface InteractionsModelCallback
Overrides:
replSystemOutPrint in class InteractionsModel
Parameters:
s - String to print

replSystemErrPrint

public void replSystemErrPrint(String s)
Called when the repl prints to System.err. This method can safely be called from outside the event thread.

Specified by:
replSystemErrPrint in interface InteractionsModelCallback
Overrides:
replSystemErrPrint in class InteractionsModel
Parameters:
s - String to print

getConsoleInput

public String getConsoleInput()
Returns a line of text entered by the user at the equivalent of System.in. This method may be safely called from outside the event thread.

Specified by:
getConsoleInput in interface InteractionsModelCallback
Overrides:
getConsoleInput in class InteractionsModel
Returns:
the input given to System.in

_interpreterResetFailed

protected void _interpreterResetFailed(Throwable t)
Any extra action to perform (beyond notifying listeners) when the interpreter fails to reset.

Specified by:
_interpreterResetFailed in class InteractionsModel
Parameters:
t - The Throwable thrown by System.exit

_interpreterWontStart

protected void _interpreterWontStart(Exception e)
Description copied from class: InteractionsModel
Action to perform when the interpreter won't start.

Specified by:
_interpreterWontStart in class InteractionsModel

interpreterReady

public void interpreterReady(File wd)
Called when the Java interpreter is ready to use. This method body adds actions that involve the global model. This method may run outside the event thread.

Specified by:
interpreterReady in interface InteractionsModelCallback
Overrides:
interpreterReady in class InteractionsModel

_notifyInteractionStarted

public void _notifyInteractionStarted()
In the event thread, notifies listeners that an interaction has started.

Specified by:
_notifyInteractionStarted in class InteractionsModel

_notifyInteractionEnded

protected void _notifyInteractionEnded()
In the event thread, notifies listeners that an interaction has ended.

Specified by:
_notifyInteractionEnded in class InteractionsModel

_notifySyntaxErrorOccurred

protected void _notifySyntaxErrorOccurred(int offset,
                                          int length)
In the event thread, notifies listeners that an error was present in the interaction.

Specified by:
_notifySyntaxErrorOccurred in class InteractionsModel
Parameters:
offset - the first character of the error in the InteractionsDocument
length - the length of the error.

_notifyInterpreterChanged

protected void _notifyInterpreterChanged(boolean inProgress)
In the event thread, notifies listeners that the interpreter has changed.

Specified by:
_notifyInterpreterChanged in class RMIInteractionsModel
Parameters:
inProgress - Whether the new interpreter is currently in progress.

_notifyInterpreterResetting

protected void _notifyInterpreterResetting()
In the event thread, notifies listeners that the interpreter is resetting.

Specified by:
_notifyInterpreterResetting in class InteractionsModel

_notifyInterpreterReady

public void _notifyInterpreterReady(File wd)
In the event thread, notifies listeners that the interpreter is ready. Sometimes called from outside the event thread.

Specified by:
_notifyInterpreterReady in class InteractionsModel

_notifyInterpreterExited

protected void _notifyInterpreterExited(int status)
In the event thread, notifies listeners that the interpreter has exited unexpectedly.

Specified by:
_notifyInterpreterExited in class InteractionsModel
Parameters:
status - Status code of the dead process

_notifyInterpreterResetFailed

protected void _notifyInterpreterResetFailed(Throwable t)
In the event thread, notifies listeners that the interpreter reset failed.

Specified by:
_notifyInterpreterResetFailed in class InteractionsModel
Parameters:
t - Throwable causing the failure

_notifyInteractionIncomplete

protected void _notifyInteractionIncomplete()
In the event thread, notifies the view that the current interaction is incomplete.

Specified by:
_notifyInteractionIncomplete in class InteractionsModel

getConsoleDocument

public ConsoleDocument getConsoleDocument()
Description copied from class: InteractionsModel
Gets the console tab document for this interactions model

Specified by:
getConsoleDocument in class InteractionsModel

replaceLLException

public StackTraceElement[] replaceLLException(StackTraceElement[] stackTrace)
overides method in InteractionModel.java and changes stackTrace for a throwable if LL files are present

Overrides:
replaceLLException in class InteractionsModel
Parameters:
stackTrace - the stack trace to change files name and line number in
Returns:
stack trace with replaced file name and line number (if throwable occured in a .dj* file)

getCompilerBootClassPath

public List<File> getCompilerBootClassPath()
A compiler can instruct DrJava to include additional elements for the boot class path of the Interactions JVM.


transformCommands

public String transformCommands(String interactionsString)
Transform the command line to be interpreted into something the Interactions JVM can use. This replaces "java MyClass a b c" with Java code to call MyClass.main(new String[]{"a","b","c"}). "import MyClass" is not handled here.

Parameters:
interactionsString - unprocessed command line
Returns:
command line with commands transformed