01: /*
02: *
03: * BeanShellHook.java -
04: * Copyright (C) 2003 Ecoo Team
05: * valdes@loria.fr
06: *
07: *
08: * This program is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU Lesser General Public License
10: * as published by the Free Software Foundation; either version 2
11: * of the License, or (at your option) any later version.
12: *
13: * This program is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: * GNU Lesser General Public License for more details.
17: *
18: * You should have received a copy of the GNU Lesser General Public License
19: * along with this program; if not, write to the Free Software
20: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21: */
22:
23: package hero.hook;
24:
25: import hero.interfaces.BnNodeLocal;
26: import hero.util.HeroHookException;
27: import bsh.Interpreter;
28:
29: public class BeanShellHook extends Hook {
30:
31: public BeanShellHook(String name, String event, int type) {
32: super (name, event, type);
33: }
34:
35: public void execute(Object bean, String eventName, BnNodeLocal node)
36: throws HeroHookException {
37: try {
38:
39: Interpreter i = new Interpreter();
40: i.set("node", node);
41: i.set("bean", bean);
42: ClassLoader cl = this .getClass().getClassLoader();
43: if (cl.getResource("/" + this .getName() + ".bsh") != null) {
44: i
45: .source((cl.getResource("/" + this .getName()
46: + ".bsh")).toString());
47: //i.source("/"+this.getName()+".bsh");
48: i.eval(eventName + "(bean,node)");
49: }
50:
51: } catch (Exception t) {
52: throw new HeroHookException("Cannot execute JAVA hook "
53: + t.getMessage());
54: }
55: }
56:
57: }
|