KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > rero > bridges > bind > BindEnvironment


1 package rero.bridges.bind;
2  
3 import java.util.*;
4 import java.io.*;
5
6 import java.awt.event.*;
7
8 import sleep.engine.*;
9 import sleep.interfaces.*;
10 import sleep.runtime.*;
11
12 import rero.bridges.alias.*;
13
14 /**
15  * kind of dirty, implementation of sets just piggy backs off of the implementation of aliases.
16  * API's are different, however the data structures are the same and the unloading code can be shared this way.
17 **/

18
19 public class BindEnvironment extends AliasEnvironment
20 {
21     public void bindFunction(ScriptInstance si, String JavaDoc type, String JavaDoc name, Block code)
22     {
23         ScriptedBind temp = null;
24
25         if (aliases.get(name) != null)
26         {
27             temp = (ScriptedBind)aliases.get(name);
28         }
29
30         ScriptedBind mybind = new ScriptedBind(si, code, temp);
31
32         aliases.put(name.toUpperCase(), mybind);
33     }
34
35     public boolean scriptLoaded (ScriptInstance si)
36     {
37         Hashtable env = si.getScriptEnvironment().getEnvironment(); // assuming the environment is shared. hah right
38

39         env.put("bind", this);
40         return true;
41     }
42
43     public ScriptedBind getBinding(String JavaDoc description)
44     {
45         return (ScriptedBind)aliases.get(description.toUpperCase());
46     }
47
48     public boolean isBound(String JavaDoc description)
49     {
50         return getBinding(description) != null;
51     }
52
53     public void processEvent(String JavaDoc description)
54     {
55         getBinding(description).process();
56     }
57 }
58
Popular Tags