| 1 package org.sapia.soto.state.code; 2 3 import bsh.EvalError; 4 import bsh.Interpreter; 5 import bsh.TargetError; 6 7 import org.apache.commons.lang.ClassUtils; 8 9 import org.sapia.soto.state.Result; 10 import org.sapia.soto.state.Step; 11 12 import java.io.StringReader ; 13 14 15 23 public class BeanshellStep implements Step { 24 private StringReader _src; 25 26 public BeanshellStep() { 27 super(); 28 } 29 30 33 public String getName() { 34 return ClassUtils.getShortClassName(getClass()); 35 } 36 37 40 public void execute(Result result) { 41 if (_src == null) { 42 throw new IllegalStateException ("Beanshell source not specified"); 43 } 44 45 Interpreter interp = new Interpreter(); 46 47 try { 48 interp.set("result", result); 49 } catch (EvalError e) { 50 result.error("Could not initialize interpreter", e); 51 } 52 53 try { 54 interp.eval(_src); 55 } catch (TargetError e) { 56 result.error(e.getTarget()); 57 } catch (EvalError e) { 58 result.error("Could not interpret Beanshell script", e); 59 } 60 } 61 62 public void setText(String src) { 63 _src = new StringReader (src); 64 } 65 } 66 | Popular Tags |