1 package hero.hook; 2 3 25 26 import hero.interfaces.BnNodeLocal; 27 import hero.util.HeroHookException; 28 29 import java.lang.reflect.InvocationTargetException ; 30 import java.lang.reflect.Method ; 31 32 import org.apache.log4j.Category; 33 34 public class JavaHook extends Hook { 35 36 private static final Category log = Category.getInstance(JavaHook.class); 38 39 40 public JavaHook(String name, String event, int type) { 41 super(name,event,type); 42 } 43 44 public void execute(Object bean,String eventName,BnNodeLocal node) throws HeroHookException { 45 log.debug("execute: event="+eventName+" node="+node.getName()); 46 try { 47 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 48 Class clhook=cl.loadClass(this.getName()); 49 NodeHookI ndh =(NodeHookI)clhook.newInstance(); 50 Class [] param={ 51 java.lang.Object .class, 52 hero.interfaces.BnNodeLocal.class}; 53 Method evth=clhook.getMethod(eventName,param); 54 Object [] o={bean,node}; 55 evth.invoke(ndh,o); 56 } catch (InvocationTargetException ite) { 57 throw new HeroHookException("Failure during hook execution"+ite.getMessage()); 58 } catch (Exception e) { 59 throw new HeroHookException("Dynamic invocation failed :"+this.getName()+"#"+node.getName()+"-->"+eventName+" ///"+e); 60 } 61 } 62 63 64 } 65 | Popular Tags |