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 console.println(" where filename defaults to looking in $SCT_DAQ_ROOT/share/scripts");
00061
00062 return i;
00063 }
00064
00066 private ScriptingInterface() {
00067 manager = new BSFManager();
00068 registry = new SearchableObjectRegistry();
00069 manager.setObjectRegistry(registry);
00070
00071 try {
00072 manager.declareBean("SI", SystemInterface.getInstance(), SystemInterface.class);
00073 } catch (BSFException be) {
00074 System.err.println("Error initializing manager: " + be);
00075 }
00076 }
00077
00078 private static ScriptingInterface instance = null;
00079 private BSFManager manager;
00080 private SearchableObjectRegistry registry;
00081 private WeakReference currentInterpreter = new WeakReference(null);
00082 }