1 22 23 package hero.hook; 24 25 import hero.interfaces.BnNodeLocal; 26 import hero.util.HeroException; 27 import hero.util.HeroHookException; 28 import java.io.Serializable ; 29 import hero.interfaces.Constants; 30 31 public abstract class Hook implements Serializable { 32 33 private String name; 34 private String event; 35 private int type; 36 private String script; 37 38 public static Hook make(String name, String event, int type) throws HeroException { 39 if (type==Constants.Hook.JAVA) {return new JavaHook(name,event,type);} 40 if (type==Constants.Hook.TCL) {return new TclHook(name,event,type);} 41 if (type==Constants.Hook.BEANSHELL) {return new BeanShellHook(name,event,type);} 42 throw new HeroException("Wrong Hook Type "+type); 43 } 44 45 public static Hook make(String name, String event, int type, String script) throws HeroException { 46 if (type==Constants.Hook.BSINTERACTIVE) {return new InteractiveBSHook(name,event,type,script);} 47 throw new HeroException("Wrong Hook Type "+type); 48 } 49 50 protected Hook(String name, String event, int type) { 51 this.name=name; 52 this.event=event; 53 this.type=type; 54 } 55 56 protected Hook(String name, String event, int type, String script) { 57 this.name=name; 58 this.event=event; 59 this.type=type; 60 this.script=script; 61 } 62 63 public String getName() {return this.name;} 64 public void setName(String name) {this.name=name;} 65 66 public int getType() {return this.type;} 67 public void setType(int type) {this.type=type;} 68 69 public String getEvent() {return this.event;} 70 public void setEvent(String event) {this.event=event;} 71 72 public String getScript() {return this.script;} 73 public void setScript(String script) {this.script=script;} 74 75 public String toXML() { 76 String result=new String (); 77 result="<hook name=\""+this.getName()+ 78 "\" type=\""+this.getType()+ 79 "\" event=\""+this.getEvent()+"\"/>"; 80 return result; 81 } 82 83 public abstract void execute(Object bean,String eventName, BnNodeLocal node) throws HeroHookException; 84 85 } 86 | Popular Tags |