1 55 56 package org.apache.bsf.engines.jacl; 57 58 import java.util.*; 59 import java.io.*; 60 61 import tcl.lang.*; 62 63 import org.apache.bsf.*; 64 import org.apache.bsf.util.*; 65 66 class BSFCommand implements Command { 68 BSFManager mgr; 69 BSFEngine jengine; 70 71 BSFCommand (BSFManager mgr, BSFEngine jengine) { 72 this.mgr = mgr; 73 this.jengine = jengine; 74 } 75 public void cmdProc (Interp interp, 76 TclObject argv[]) throws TclException { 77 if (argv.length < 2) { 78 interp.setResult ("invalid # of args; usage: bsf " + 79 "lookupBean|registerBean|unregisterBean|addEventListener args"); 80 throw new TclException (TCL.ERROR); 81 } 82 83 String op = argv[1].toString (); 84 85 if (op.equals ("lookupBean")) { 86 if (argv.length != 3) { 87 interp.setResult ("invalid # of args; usage: bsf " + 88 "lookupBean name-of-bean"); 89 throw new TclException (TCL.ERROR); 90 } 91 92 String beanName = argv[2].toString (); 93 Object bean = mgr.lookupBean (beanName); 94 if (bean == null) { 95 interp.setResult ("unknown object: " + beanName); 96 throw new TclException (TCL.ERROR); 97 } 98 interp.setResult (ReflectObject.newInstance (interp, bean.getClass (), 99 bean)); 100 101 } else if (op.equals ("registerBean")) { 102 if (argv.length != 4) { 103 interp.setResult ("invalid # of args; usage: bsf " + 104 "registerBean name-of-bean bean"); 105 throw new TclException (TCL.ERROR); 106 } 107 mgr.registerBean (argv[2].toString (), 108 ReflectObject.get (interp, argv[3])); 109 interp.setResult (""); 110 111 } else if (op.equals ("unregisterBean")) { 112 if (argv.length != 3) { 113 interp.setResult ("invalid # of args; usage: bsf " + 114 "unregisterBean name-of-bean"); 115 throw new TclException (TCL.ERROR); 116 } 117 mgr.unregisterBean (argv[2].toString ()); 118 interp.setResult (""); 119 120 } else if (op.equals ("addEventListener")) { 121 if (argv.length != 6) { 122 interp.setResult ("invalid # of args; usage: bsf " + 123 "addEventListener object event-set-name filter " + 124 "script-to-run"); 125 throw new TclException (TCL.ERROR); 126 } 127 try { 128 String filter = argv[4].toString (); 130 filter = filter.equals ("") ? null : filter; 131 EngineUtils.addEventListener (ReflectObject.get (interp, argv[2]), 132 argv[3].toString (), filter, 133 jengine, mgr, "<event-script>", 0, 0, 134 argv[5].toString ()); 135 } catch (BSFException e) { 136 e.printStackTrace (); 137 interp.setResult ("got BSF exception: " + e.getMessage ()); 138 throw new TclException (TCL.ERROR); 139 } 140 } 141 } 142 } 143 | Popular Tags |