KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > rero > bridges > set > SetEnvironment


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

16
17 public class SetEnvironment extends AliasEnvironment
18 {
19     public void bindFunction(ScriptInstance si, String JavaDoc type, String JavaDoc name, Block code)
20     {
21         ScriptedSet temp = null;
22
23         boolean timestamp = true;
24
25         if (name.charAt(name.length() - 1) == '!')
26         {
27             name = name.substring(0, name.length() - 1);
28             timestamp = false;
29         }
30
31         if (aliases.get(name) != null)
32         {
33             temp = (ScriptedSet)aliases.get(name);
34         }
35
36         ScriptedSet myset = new ScriptedSet(si, code, temp);
37         myset.setTimeStamp(timestamp);
38
39         aliases.put(name, myset);
40     }
41
42     public boolean scriptLoaded (ScriptInstance si)
43     {
44         Hashtable env = si.getScriptEnvironment().getEnvironment(); // assuming the environment is shared. hah right
45

46         env.put("set", this);
47         return true;
48     }
49
50     public boolean isSet(String JavaDoc name)
51     {
52         return aliases.containsKey(name);
53     }
54
55     public boolean isTimeStamped(String JavaDoc name)
56     {
57         if (isSet(name))
58         {
59            return ((ScriptedSet)aliases.get(name)).isTimeStamped();
60         }
61
62         return false;
63     }
64
65     public String JavaDoc parseSet(String JavaDoc name, HashMap eventData)
66     {
67         if (isSet(name))
68         {
69            return ((ScriptedSet)aliases.get(name)).parseSet(eventData);
70         }
71
72         return null;
73     }
74 }
75
Popular Tags