KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > hook > TclHook


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

24
25 import hero.interfaces.BnNodeLocal;
26 import hero.util.HeroHookException;
27 import tcl.lang.Interp;
28 import tcl.lang.ReflectObject;
29 import tcl.lang.TclObject;
30
31 public class TclHook extends Hook {
32
33     public TclHook(String JavaDoc name, String JavaDoc event, int type) {
34     super(name,event,type);
35     }
36
37     public void execute(Object JavaDoc bean,String JavaDoc eventName,BnNodeLocal node) throws HeroHookException {
38     try {
39         Interp interp=new Interp();
40         interp.evalResource("/"+this.getName()+".tcl");
41         TclObject tclNode=ReflectObject.newInstance(interp,BnNodeLocal.class,node);
42         TclObject tclEJB=ReflectObject.newInstance(interp,Object JavaDoc.class,bean);
43         interp.setVar("node",tclNode,1);
44         interp.setVar("bean",tclEJB,1);
45         interp.eval(this.getName()+"::"+eventName+" $bean $node");
46     } catch (Exception JavaDoc t) {
47         throw new HeroHookException("Cannot execute tcl hook "+t.getMessage());
48     }
49     }
50
51 }
52
Popular Tags