1 33 34 package edu.rice.cs.drjava.model.repl; 35 36 import java.net.URL ; 37 import java.io.File ; 38 39 40 import edu.rice.cs.drjava.model.repl.newjvm.InterpreterJVM; 41 import edu.rice.cs.drjava.model.repl.newjvm.ClassPathManager; 42 43 import edu.rice.cs.util.swing.Utilities; 44 45 import edu.rice.cs.util.text.ConsoleDocument; 46 47 51 public class SimpleInteractionsModel extends InteractionsModel { 52 53 54 protected static final int WRITE_DELAY = 5; 55 56 57 protected JavaInterpreter _interpreter; 58 59 60 public SimpleInteractionsModel() { this(new InteractionsDJDocument()); } 61 62 65 public SimpleInteractionsModel(InteractionsDJDocument document) { 66 super(document, new File (System.getProperty("user.dir")), 1000, WRITE_DELAY); 67 _interpreter = new DynamicJavaAdapter(new ClassPathManager()); 68 69 _interpreter.defineVariable("INTERPRETER", _interpreter); 70 } 71 72 76 protected void _interpret(String toEval) { 77 try { 78 Object result = _interpreter.interpret(toEval); 79 if (result != Interpreter.NO_RESULT) { 80 append(String.valueOf(result) + System.getProperty("line.separator"), 81 InteractionsDocument.OBJECT_RETURN_STYLE); 82 } 83 } 84 catch (ExceptionReturnedException e) { 85 Throwable t = e.getContainedException(); 86 _document.appendExceptionResult(t.getClass().getName(), 88 t.getMessage(), 89 InterpreterJVM.getStackTrace(t), 90 InteractionsDocument.DEFAULT_STYLE); 91 } 92 finally { _interactionIsOver(); } 93 } 94 95 99 public String getVariableToString(String var) { 100 Object value = _interpreter.getVariable(var); 101 return value.toString(); 102 } 103 104 108 public String getVariableClassName(String var) { 109 Class c = _interpreter.getVariableClass(var); 110 return c.getName(); 111 } 112 113 116 public void addProjectClassPath(URL path) { _interpreter.addProjectClassPath(path); } 117 118 121 public void addBuildDirectoryClassPath(URL path) { _interpreter.addBuildDirectoryClassPath(path); } 122 123 126 public void addProjectFilesClassPath(URL path) { _interpreter.addProjectFilesClassPath(path); } 127 128 131 public void addExternalFilesClassPath(URL path) { _interpreter.addExternalFilesClassPath(path); } 132 133 136 public void addExtraClassPath(URL path) { _interpreter.addExtraClassPath(path); } 137 138 139 140 public void defineVariable(String name, Object value) { _interpreter.defineVariable(name, value); } 141 142 143 public void defineConstant(String name, Object value) { _interpreter.defineConstant(name, value); } 144 145 146 public void setInterpreterPrivateAccessible(boolean accessible) { _interpreter.setPrivateAccessible(accessible); } 147 148 151 protected void _interpreterResetFailed(Throwable t) { 152 _document.insertBeforeLastPrompt("Reset Failed!" + _newLine, InteractionsDocument.ERROR_STYLE); 153 } 154 155 156 protected void _resetInterpreter(File wd) { 157 interpreterResetting(); 158 _interpreter = new DynamicJavaAdapter(new ClassPathManager()); 159 interpreterReady(wd); 160 } 161 162 163 protected void _notifyInteractionStarted() { 164 Utilities.invokeLater(new Runnable () { public void run() { _notifier.interactionStarted(); } }); 165 } 166 167 168 protected void _notifyInteractionEnded() { 169 Utilities.invokeLater(new Runnable () { public void run() { _notifier.interactionEnded(); } }); 170 } 171 172 173 protected void _notifySyntaxErrorOccurred(final int offset, final int length) { 174 Utilities.invokeLater(new Runnable () { public void run() { _notifier.interactionErrorOccurred(offset, length); } }); 175 } 176 177 178 protected void _notifyInterpreterResetting() { } 179 180 181 public void _notifyInterpreterReady(File wd) { 182 } 184 185 188 protected void _notifyInterpreterExited(final int status) { 189 } 191 192 193 protected void _notifyInterpreterResetFailed(Throwable t) { 194 } 196 197 198 protected void _notifyInteractionIncomplete() { 199 } 201 202 203 protected void _notifySlaveJVMUsed() { } 204 205 206 public ConsoleDocument getConsoleDocument() { return null; } 207 } 208 | Popular Tags |