KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > hook > Hook


1 /*
2 *
3 * Hook.java -
4 * Copyright (C) 2003 Ecoo Team
5 * charoy@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.HeroException;
27 import hero.util.HeroHookException;
28 import java.io.Serializable JavaDoc;
29 import hero.interfaces.Constants;
30
31 public abstract class Hook implements Serializable JavaDoc{
32
33     private String JavaDoc name;
34     private String JavaDoc event;
35     private int type;
36     private String JavaDoc script;
37
38     public static Hook make(String JavaDoc name, String JavaDoc event, int type) throws HeroException {
39     if (type==Constants.Hook.JAVA) {return new JavaHook(name,event,type);}
40         if (type==Constants.Hook.TCL) {return new TclHook(name,event,type);}
41         if (type==Constants.Hook.BEANSHELL) {return new BeanShellHook(name,event,type);}
42     throw new HeroException("Wrong Hook Type "+type);
43     }
44
45     public static Hook make(String JavaDoc name, String JavaDoc event, int type, String JavaDoc script) throws HeroException {
46         if (type==Constants.Hook.BSINTERACTIVE) {return new InteractiveBSHook(name,event,type,script);}
47         throw new HeroException("Wrong Hook Type "+type);
48         }
49     
50     protected Hook(String JavaDoc name, String JavaDoc event, int type) {
51     this.name=name;
52     this.event=event;
53     this.type=type;
54     }
55     
56     protected Hook(String JavaDoc name, String JavaDoc event, int type, String JavaDoc script) {
57         this.name=name;
58         this.event=event;
59         this.type=type;
60         this.script=script;
61       }
62
63     public String JavaDoc getName() {return this.name;}
64     public void setName(String JavaDoc name) {this.name=name;}
65
66     public int getType() {return this.type;}
67     public void setType(int type) {this.type=type;}
68
69     public String JavaDoc getEvent() {return this.event;}
70     public void setEvent(String JavaDoc event) {this.event=event;}
71     
72     public String JavaDoc getScript() {return this.script;}
73     public void setScript(String JavaDoc script) {this.script=script;}
74
75     public String JavaDoc toXML() {
76     String JavaDoc result=new String JavaDoc();
77     result="<hook name=\""+this.getName()+
78         "\" type=\""+this.getType()+
79         "\" event=\""+this.getEvent()+"\"/>";
80     return result;
81     }
82
83     public abstract void execute(Object JavaDoc bean,String JavaDoc eventName, BnNodeLocal node) throws HeroHookException;
84
85 }
86
Popular Tags