KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > hook > JavaHook


1 package hero.hook;
2
3 /*
4 * 02/01/2002 - 15:24:07
5 *
6 * JavaHook.java -
7 * Copyright (C) 2002 Ecoo Team
8 * charoy@loria.fr
9 *
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */

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