01: package hero.hook;
02:
03: /*
04: * 02/01/2002 - 15:24:07
05: *
06: * JavaProcessHook.java -
07: * Copyright (C) 2002 Ecoo Team
08: * charoy@loria.fr
09: *
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.BnProjectLocal;
27: import hero.util.HeroHookException;
28:
29: import java.lang.reflect.InvocationTargetException;
30: import java.lang.reflect.Method;
31:
32: public class JavaProcessHook extends ProcessHook {
33:
34: public JavaProcessHook(String name, String event, int type) {
35: super (name, event, type);
36: }
37:
38: public void execute(Object bean, String eventName,
39: BnProjectLocal project) throws HeroHookException {
40: try {
41: ClassLoader cl = Thread.currentThread()
42: .getContextClassLoader();
43: Class clhook = cl.loadClass(this .getName());
44: ProcessHookI prh = (ProcessHookI) clhook.newInstance();
45: Class[] param = { java.lang.Object.class,
46: hero.interfaces.BnProjectLocal.class };
47: Method evth = clhook.getMethod(eventName, param);
48: Object[] o = { bean, project };
49: evth.invoke(prh, o);
50: } catch (InvocationTargetException ite) {
51: throw new HeroHookException(
52: "Failure during Process hook execution"
53: + ite.getMessage());
54: } catch (Exception e) {
55: throw new HeroHookException("Dynamic invocation failed :"
56: + this .getName() + "#" + project.getName() + "-->"
57: + eventName + " ///" + e);
58: }
59: }
60:
61: }
|