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

java.lang.Object
  extended by edu.rice.cs.drjava.model.repl.InteractionsModel
      extended by edu.rice.cs.drjava.model.repl.RMIInteractionsModel
All Implemented Interfaces:
InteractionsModelCallback
Direct Known Subclasses:
DefaultInteractionsModel, InteractionsModelTest.IncompleteInputInteractionsModel

public abstract class RMIInteractionsModel
extends InteractionsModel

A Swing specific InteractionsModel which can serve as the glue between a local InteractionsDocument and a remote JavaInterpreter in another JVM.

Version:
$Id: RMIInteractionsModel.java 5181 2010-02-24 16:53:27Z mgricken $

Field Summary
protected  MainJVM _jvm
          RMI interface to the remote Java interpreter.
 
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
RMIInteractionsModel(MainJVM jvm, ConsoleDocumentInterface cDoc, File wd, int historySize, int writeDelay)
          Constructs an InteractionsModel which can communicate with another JVM.
 
Method Summary
protected  void _interpret(String toEval)
          Interprets the given command.
protected abstract  void _notifyInterpreterChanged(boolean inProgress)
          Notifies listeners that the interpreter has changed.
protected  void _resetInterpreter(File wd, boolean force)
          Resets the Java interpreter.
private  void _updateDocument(String prompt, boolean inProgress)
          Updates the prompt and status of the document after an interpreter change.
 void addBuildDirectoryClassPath(File f)
          These add the given path to the build directory class paths used in the interpreter.
 void addExternalFilesClassPath(File f)
          These add the given path to the external files class paths used in the interpreter.
 void addExtraClassPath(File f)
          These add the given path to the extra class paths used in the interpreter.
 void addInterpreter(String name)
          Adds a named interpreter to the list.
 void addProjectClassPath(File f)
          Adds the given path to the interpreter's class path.
 void addProjectFilesClassPath(File f)
          These add the given path to the project files class paths used in the interpreter.
 Iterable<File> getClassPath()
          Gets the interpreter class path from the interpreter jvm.
 Pair<String,String> getVariableToString(String var)
          Gets the string representation of the value of a variable in the current interpreter.
 void removeInterpreter(String name)
          Removes the interpreter with the given name, if it exists.
 void setActiveInterpreter(String name, String prompt)
          Sets the active interpreter.
 void setEnforceAllAccess(boolean enforce)
          Sets whether or not the interpreter should enforce access to all members.
 void setEnforcePrivateAccess(boolean enforce)
          Sets whether or not the interpreter should enforce access to private members.
 void setRequireSemicolon(boolean require)
          Require a semicolon at the end of statements.
 void setRequireVariableType(boolean require)
          Require variable declarations to include an explicit type.
 void setToDefaultInterpreter()
          Sets the default interpreter to be the current one.
 
Methods inherited from class edu.rice.cs.drjava.model.repl.InteractionsModel
_addNewline, _createNewDebugPort, _getHistoryText, _interactionIsOver, _interpreterResetFailed, _interpreterWontStart, _notifyInteractionEnded, _notifyInteractionIncomplete, _notifyInteractionStarted, _notifyInterpreterExited, _notifyInterpreterReady, _notifyInterpreterResetFailed, _notifyInterpreterResetting, _notifySyntaxErrorOccurred, _removeSeparators, _writerDelay, addListener, append, autoImport, changeInputListener, getBanner, getBanner, getConsoleDocument, getConsoleInput, getDebugPort, getDocument, getLastError, getSecondToLastError, getStartUpBanner, getWorkingDirectory, interactionContinues, interpret, interpretCurrentInteraction, interpreterReady, interpreterResetFailed, interpreterResetting, interpreterWontStart, loadHistory, loadHistoryAsScript, performDefaultImports, removeAllInteractionListeners, removeLastFromHistory, removeListener, replaceLLException, replCalledSystemExit, replReturnedResult, replReturnedSyntaxError, replReturnedVoid, replSystemErrPrint, replSystemOutPrint, 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
 
Methods inherited from interface edu.rice.cs.drjava.model.repl.InteractionsModelCallback
getCompilerBootClassPath, transformCommands
 

Field Detail

_jvm

protected final MainJVM _jvm
RMI interface to the remote Java interpreter.

Constructor Detail

RMIInteractionsModel

public RMIInteractionsModel(MainJVM jvm,
                            ConsoleDocumentInterface cDoc,
                            File wd,
                            int historySize,
                            int writeDelay)
Constructs an InteractionsModel which can communicate with another JVM.

Parameters:
jvm - RMI interface to the slave JVM
cDoc - document to use in the InteractionsDocument
historySize - Number of lines to store in the history
writeDelay - Number of milliseconds to wait after each println
Method Detail

_interpret

protected void _interpret(String toEval)
Interprets the given command.

Specified by:
_interpret in class InteractionsModel
Parameters:
toEval - command to be evaluated

getVariableToString

public Pair<String,String> getVariableToString(String var)
Gets the string representation of the value of a variable in the current interpreter.

Specified by:
getVariableToString in class InteractionsModel
Parameters:
var - the name of the variable
Returns:
A string representation of the value, or null if the variable is not defined.

addProjectClassPath

public void addProjectClassPath(File f)
Adds the given path to the interpreter's class path.

Specified by:
addProjectClassPath in class InteractionsModel
Parameters:
f - the path to add

addBuildDirectoryClassPath

public void addBuildDirectoryClassPath(File f)
These add the given path to the build directory class paths used in the interpreter.

Specified by:
addBuildDirectoryClassPath in class InteractionsModel
Parameters:
f - the path to add

addProjectFilesClassPath

public void addProjectFilesClassPath(File f)
These add the given path to the project files class paths used in the interpreter.

Specified by:
addProjectFilesClassPath in class InteractionsModel
Parameters:
f - the path to add

addExternalFilesClassPath

public void addExternalFilesClassPath(File f)
These add the given path to the external files class paths used in the interpreter.

Specified by:
addExternalFilesClassPath in class InteractionsModel
Parameters:
f - the path to add

addExtraClassPath

public void addExtraClassPath(File f)
These add the given path to the extra class paths used in the interpreter.

Specified by:
addExtraClassPath in class InteractionsModel
Parameters:
f - the path to add

_resetInterpreter

protected void _resetInterpreter(File wd,
                                 boolean force)
Resets the Java interpreter.

Specified by:
_resetInterpreter in class InteractionsModel

addInterpreter

public void addInterpreter(String name)
Adds a named interpreter to the list.

Parameters:
name - the unique name for the interpreter
Throws:
IllegalArgumentException - if the name is not unique

removeInterpreter

public void removeInterpreter(String name)
Removes the interpreter with the given name, if it exists.

Parameters:
name - Name of the interpreter to remove

setActiveInterpreter

public void setActiveInterpreter(String name,
                                 String prompt)
Sets the active interpreter.

Parameters:
name - the (unique) name of the interpreter.
prompt - the prompt the interpreter should have.

setToDefaultInterpreter

public void setToDefaultInterpreter()
Sets the default interpreter to be the current one.


_updateDocument

private void _updateDocument(String prompt,
                             boolean inProgress)
Updates the prompt and status of the document after an interpreter change. Must run in event thread. (TODO: is it okay that related RMI calls occur in the event thread?)

Parameters:
prompt - New prompt to display
inProgress - whether the interpreter is currently in progress

_notifyInterpreterChanged

protected abstract void _notifyInterpreterChanged(boolean inProgress)
Notifies listeners that the interpreter has changed. (Subclasses must maintain listeners.)

Parameters:
inProgress - Whether the new interpreter is currently in progress with an interaction, i.e., whether an interactionEnded event will be fired)

setEnforceAllAccess

public void setEnforceAllAccess(boolean enforce)
Sets whether or not the interpreter should enforce access to all members.


setEnforcePrivateAccess

public void setEnforcePrivateAccess(boolean enforce)
Sets whether or not the interpreter should enforce access to private members.


setRequireSemicolon

public void setRequireSemicolon(boolean require)
Require a semicolon at the end of statements.


setRequireVariableType

public void setRequireVariableType(boolean require)
Require variable declarations to include an explicit type.


getClassPath

public Iterable<File> getClassPath()
Gets the interpreter class path from the interpreter jvm.

Returns:
a list of class path elements