KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > hook > BeanShellHook


1 /*
2 *
3 * BeanShellHook.java -
4 * Copyright (C) 2003 Ecoo Team
5 * valdes@loria.fr
6 *
7 *
8 * This program is free software; you can redistribute it and/or
9 * 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 JavaDoc name, String JavaDoc event, int type) {
32     super(name,event,type);
33     }
34
35     public void execute(Object JavaDoc bean,String JavaDoc eventName,BnNodeLocal node) throws HeroHookException {
36     try {
37
38         Interpreter i = new Interpreter();
39         i.set("node",node);
40         i.set("bean",bean);
41         ClassLoader JavaDoc cl = this.getClass().getClassLoader();
42         if (cl.getResource("/"+this.getName()+".bsh") != null)
43         {
44         i.source((cl.getResource("/"+this.getName()+".bsh")).toString());
45         //i.source("/"+this.getName()+".bsh");
46
i.eval(eventName+"(bean,node)");
47         }
48         
49     } catch (Exception JavaDoc t) {
50         throw new HeroHookException("Cannot execute JAVA hook "+t.getMessage());
51     }
52     }
53
54 }
55
Popular Tags