KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > rero > bridges > event > CodeSnippet


1 package rero.bridges.event;
2
3 import sleep.runtime.*;
4 import sleep.interfaces.*;
5 import sleep.engine.*;
6
7 import rero.script.*;
8
9 import java.util.HashMap JavaDoc;
10
11 public class CodeSnippet
12 {
13    protected ScriptEnvironment environment;
14    protected ScriptInstance si;
15    protected Block code;
16
17    public CodeSnippet(Block c, ScriptEnvironment e)
18    {
19       code = c;
20       environment = e;
21
22       si = environment.getScriptInstance();
23    }
24
25    public int getLineNumber()
26    {
27       return code.getApproximateLineNumber();
28    }
29
30    public boolean isValid()
31    {
32       return si.isLoaded();
33    }
34
35    public int execute(HashMap JavaDoc eventData)
36    {
37       //
38
// if the script associated with this listener is no longer valid (i.e. loaded) then umm delete the listener
39
//
40
if (!isValid())
41       {
42          return rero.ircfw.interfaces.ChatListener.REMOVE_LISTENER;
43       }
44
45       Scalar rv;
46
47       synchronized (environment.getScriptVariables())
48       {
49          environment.getScriptVariables().pushLocalLevel();
50
51          LocalVariables locals = (LocalVariables)environment.getScriptVariables().getLocalVariables();
52          locals.setDataSource(eventData);
53
54          rv = SleepUtils.runCode(code, environment);
55
56          environment.getScriptVariables().popLocalLevel();
57       }
58
59       if (rv == null)
60       {
61          return 0;
62       }
63
64       return rv.getValue().intValue();
65    }
66 }
67
Popular Tags