001: /*
002: *
003: * Hook.java -
004: * Copyright (C) 2003 Ecoo Team
005: * charoy@loria.fr
006: *
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Lesser General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or (at your option) any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: */
022:
023: package hero.hook;
024:
025: import hero.interfaces.BnNodeLocal;
026: import hero.util.HeroException;
027: import hero.util.HeroHookException;
028: import java.io.Serializable;
029: import hero.interfaces.Constants;
030:
031: public abstract class Hook implements Serializable {
032:
033: private String name;
034: private String event;
035: private int type;
036: private String script;
037:
038: public static Hook make(String name, String event, int type)
039: throws HeroException {
040: if (type == Constants.Hook.JAVA) {
041: return new JavaHook(name, event, type);
042: }
043: if (type == Constants.Hook.TCL) {
044: return new TclHook(name, event, type);
045: }
046: if (type == Constants.Hook.BEANSHELL) {
047: return new BeanShellHook(name, event, type);
048: }
049: throw new HeroException("Wrong Hook Type " + type);
050: }
051:
052: public static Hook make(String name, String event, int type,
053: String script) throws HeroException {
054: if (type == Constants.Hook.BSINTERACTIVE) {
055: return new InteractiveBSHook(name, event, type, script);
056: }
057: throw new HeroException("Wrong Hook Type " + type);
058: }
059:
060: protected Hook(String name, String event, int type) {
061: this .name = name;
062: this .event = event;
063: this .type = type;
064: }
065:
066: protected Hook(String name, String event, int type, String script) {
067: this .name = name;
068: this .event = event;
069: this .type = type;
070: this .script = script;
071: }
072:
073: public String getName() {
074: return this .name;
075: }
076:
077: public void setName(String name) {
078: this .name = name;
079: }
080:
081: public int getType() {
082: return this .type;
083: }
084:
085: public void setType(int type) {
086: this .type = type;
087: }
088:
089: public String getEvent() {
090: return this .event;
091: }
092:
093: public void setEvent(String event) {
094: this .event = event;
095: }
096:
097: public String getScript() {
098: return this .script;
099: }
100:
101: public void setScript(String script) {
102: this .script = script;
103: }
104:
105: public String toXML() {
106: String result = new String();
107: result = "<hook name=\"" + this .getName() + "\" type=\""
108: + this .getType() + "\" event=\"" + this .getEvent()
109: + "\"/>";
110: return result;
111: }
112:
113: public abstract void execute(Object bean, String eventName,
114: BnNodeLocal node) throws HeroHookException;
115:
116: }
|