1 22 23 package hero.hook; 24 25 import hero.interfaces.BnNodeInterHookLocal; 26 import hero.interfaces.BnNodeLocal; 27 import hero.interfaces.BnNodePropertyLocal; 28 import hero.interfaces.BnProjectPropertyLocal; 29 import hero.interfaces.BnProjectInterHookLocal; 30 import hero.interfaces.BnProjectLocal; 31 import hero.util.HeroHookException; 32 33 import java.util.Collection ; 34 import java.util.Iterator ; 35 36 import bsh.Interpreter; 37 38 public class InteractiveBSHook extends Hook { 39 40 public InteractiveBSHook(String name, String event, int type, String script) { 41 super(name,event,type,script); 42 } 43 44 public void execute(Object bean,String eventName,BnNodeLocal node) throws HeroHookException { 45 try { 46 String value = this.getScript(); 47 BnNodeLocal nd=node; 48 49 Interpreter i = new Interpreter(); 50 i.set("node",node); 51 i.set("bean",bean); 52 53 55 Collection prop = node.getBnProperties(); 56 for (Iterator props=prop.iterator();props.hasNext();) { 57 BnNodePropertyLocal pl=(BnNodePropertyLocal)props.next(); 58 i.set(pl.getTheKey(),pl.getTheValue()); 59 } 60 61 BnProjectLocal project = node.getBnProject(); 63 Collection projectProp = project.getBnProperties(); 64 for (Iterator props=projectProp.iterator();props.hasNext();) { 65 BnProjectPropertyLocal pP=(BnProjectPropertyLocal)props.next(); 66 if (!pP.getTheKey().matches("iterate_.*")) 67 i.set(pP.getTheKey(),pP.getTheValue()); 68 } 69 70 i.eval(value); 71 i.eval(eventName+"(bean,node)"); 72 73 } catch (Exception t) {t.printStackTrace(); 74 if (node.getType()==hero.interfaces.Constants.Nd.SUB_PROCESS_NODE && eventName.equals(hero.interfaces.Constants.Nd.BEFORETERMINATE)) 75 throw new HeroHookException("You have to terminate subProcess activities previuosly"); 76 else if (eventName.equals(hero.interfaces.Constants.Nd.AFTERSTART) || eventName.equals(hero.interfaces.Constants.Nd.BEFORETERMINATE) 77 || eventName.equals(hero.interfaces.Constants.Nd.ANTICIPATE) || eventName.equals(hero.interfaces.Constants.Nd.ONCANCEL)) 78 79 throw new HeroHookException("Cannot execute beanshell hook "+t.getMessage()); 80 } 81 } 82 } 83 | Popular Tags |