00001
00002
00003
00004
00005
00006
00007 package GuiComponents.scripting;
00008
00009 import org.apache.bsf.*;
00010 import java.lang.ref.*;
00011 import GuiComponents.Console.*;
00012 import GuiComponents.System.*;
00013
00018 public class ScriptingInterface {
00019
00020 public static ScriptingInterface instance() {
00021 if (instance == null) instance = new ScriptingInterface();
00022 return instance;
00023 }
00024
00028 public BSFManager getManager() {
00029 return manager;
00030 }
00031
00032 public Interpreter getBeanShellInterpreter() {
00033 return createInterpreter(new BeanShellFactory());
00034 }
00035
00036 public Interpreter getJythonInterpreter() {
00037 return createInterpreter(new JythonFactory());
00038 }
00039
00040
00041
00042
00043
00044
00045 private Interpreter createInterpreter(ScriptFactory sf) {
00047 if (currentInterpreter.get() != null) {
00048 Interpreter i = (Interpreter)currentInterpreter.get();
00049
00050 return null;
00051 }
00052
00053 Interpreter i = sf.createInterpreter(manager);
00054
00055 JConsole console = i.getConsole();
00056 console.println("SctRodDaq scripting");
00057 console.println("The most useful object is \"SI\" which is an interface to the rest of the system.");
00058 console.println("There may also be rudimentary tab completion");
00059 console.println("Finally, you may load and execute from a file by typing \".x <filename>\"");
00060
00061 return i;
00062 }
00063
00065 private ScriptingInterface() {
00066 manager = new BSFManager();
00067 registry = new SearchableObjectRegistry();
00068 manager.setObjectRegistry(registry);
00069
00070 try {
00071 manager.declareBean("SI", SystemInterface.getInstance(), SystemInterface.class);
00072 } catch (BSFException be) {
00073 System.err.println("Error initializing manager: " + be);
00074 }
00075 }
00076
00077 private static ScriptingInterface instance = null;
00078 private BSFManager manager;
00079 private SearchableObjectRegistry registry;
00080 private WeakReference currentInterpreter = new WeakReference(null);
00081 }