KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > rero > client > Capabilities


1 package rero.client;
2
3 import rero.net.*;
4 import rero.ircfw.*;
5 import rero.ircfw.interfaces.*;
6 import rero.script.*;
7 import rero.util.*;
8 import rero.dcc.*;
9
10 import java.util.*;
11 import java.io.*;
12
13 import sleep.runtime.*;
14
15 import rero.client.user.*; // import features
16
import rero.client.server.*;
17 import rero.client.notify.*;
18 import rero.client.dcc.*;
19 import rero.client.listeners.*; // misc. built in client events. fun fun.
20
import rero.client.output.*;
21 import rero.client.data.*;
22 import rero.client.script.*;
23
24 import rero.client.functions.*; // built in functions
25

26 import rero.gui.*;
27
28 /** capabilities that feature classes may want to take advantage of */
29 public class Capabilities
30 {
31     protected SocketConnection socket;
32     protected ChatFramework ircfw;
33     protected ScriptCore script;
34     protected OutputCapabilities output;
35     protected ChatCapabilities actions;
36
37     protected rero.gui.UICapabilities gui;
38
39     protected static TimerUtil timer; // heres an important capability... yeah we *might* want access to this.
40

41     protected WeakHashMap data;
42     protected LinkedList featureList;
43
44     public Capabilities(ChatFramework _ircfw, SocketConnection _socket, ScriptCore _script, UICapabilities _gui, WeakHashMap _data)
45     {
46         //
47
// setup some of the stored stuff.
48
//
49
ircfw = _ircfw;
50         socket = _socket;
51         script = _script;
52         gui = _gui;
53
54         data = _data;
55
56         if (timer == null)
57         {
58            timer = new TimerUtil();
59            timer.start();
60         }
61
62         //
63
// setup all of the built in features...
64
//
65
featureList = new LinkedList();
66
67         output = new OutputCapabilities();
68         setupFeature(output, featureList);
69
70         actions = new ChatCapabilities();
71         setupFeature(actions, featureList);
72
73         UserHandler userInput = new UserHandler(); // handle user input, aliases, and active stuff
74
setupFeature(userInput, featureList);
75
76         ServerHandler serverOutput = new ServerHandler(); // handle output from the server feature(s)
77
setupFeature(serverOutput, featureList);
78
79         FeatureDCC dcc = new FeatureDCC(); // built in dcc stuff, fun fun fun
80
setupFeature(dcc, featureList);
81
82         ProcessEvents processEvents = new ProcessEvents(); // process some basic sets from the server i.e. DCC before everyone e$
83
setupFeature(processEvents, featureList);
84
85         NotifyData notify = new NotifyData(); // notify feature
86
setupFeature(notify, featureList);
87
88         InternalEvents internalEvents = new InternalEvents(); // built in events, non framework related
89
setupFeature(internalEvents, featureList);
90
91         LocalInfo localInfo = new LocalInfo(); // local host information so dcc's go through properly. whee.
92
setupFeature(localInfo, featureList);
93     
94         ScriptManager scriptManager = new ScriptManager(); // load the script manager
95
setupFeature(scriptManager, featureList);
96
97         PerformOnConnect performConnect = new PerformOnConnect(); // stuff for performing commands upon connecting
98
setupFeature(performConnect, featureList);
99
100         //
101
// scripting related features
102
//
103
DataStructureBridge dataStructs = new DataStructureBridge(); // bridges some of the data structures to the scripting
104
setupFeature(dataStructs, featureList);
105  
106         ChannelOperators chanops = new ChannelOperators(); // channel operators i.e. ison isop etc..
107
setupFeature(chanops, featureList);
108         script.addBridge(chanops);
109
110         UserOperators userops = new UserOperators(); // user related operators/functions etc.
111
setupFeature(userops, featureList);
112         script.addBridge(userops);
113
114         BuiltInOperators builtinops = new BuiltInOperators(); // built in commands and such
115
setupFeature(builtinops, featureList);
116         script.addBridge(builtinops);
117
118         NotifyOperators notifyops = new NotifyOperators(); // notify related stuff..
119
setupFeature(notifyops, featureList);
120         script.addBridge(notifyops);
121
122         TimerOperators timerops = new TimerOperators(); // timer related stuff..
123
setupFeature(timerops, featureList);
124
125         ConfigOperators configops = new ConfigOperators(); // interface with the client state
126
setupFeature(configops, featureList);
127
128         DCCOperators dccops = new DCCOperators(); // interface with the dcc code... *uNF*
129
setupFeature(dccops, featureList);
130
131         UtilOperators utilops = new UtilOperators(); // interface with the utility functions
132
setupFeature(utilops, featureList);
133
134         TokenOperators tokenops = new TokenOperators(); // interface with the token functions
135
setupFeature(tokenops, featureList);
136
137         ServerOperators serverops = new ServerOperators(); // interface with the servers.ini data
138
setupFeature(serverops, featureList);
139
140         SoundOperators soundops = new SoundOperators(); // add sound playing functions to jIRCii
141
setupFeature(soundops, featureList);
142
143         finalizeFeatures(featureList);
144
145         //
146
// do other fun stuff... i.e. script loading and such
147
//
148
}
149
150     public TimerUtil getTimer()
151     {
152         return timer;
153     }
154
155     public void cleanup()
156     {
157         ListIterator i = featureList.listIterator();
158         while (i.hasNext())
159         {
160            Feature temp = (Feature)i.next();
161            temp.cleanup();
162         }
163
164         data.clear();
165         featureList.clear();
166     }
167
168     public boolean isConnected()
169     {
170         return socket.getSocketInformation().isConnected; // yeah the socket stuff is goofy, my bad.
171
}
172
173     public ChatCapabilities getChatCapabilities()
174     {
175         return actions;
176     }
177
178     public OutputCapabilities getOutputCapabilities()
179     {
180         return output;
181     }
182
183     public rero.gui.UICapabilities getUserInterface()
184     {
185         return gui;
186     }
187
188     public ScriptCore getScriptCore()
189     {
190         return script;
191     }
192
193     public SocketConnection getSocketConnection()
194     {
195         return socket;
196     }
197
198     public void sendln(String JavaDoc text)
199     {
200         socket.println(text);
201     }
202
203     public Object JavaDoc getDataStructure(String JavaDoc key)
204     {
205         return data.get(key);
206     }
207
208     public void injectEvent(String JavaDoc text)
209     {
210         ircfw.injectEvent(text);
211     }
212
213     public void dispatchEvent(HashMap data)
214     {
215         ircfw.getProtocolDispatcher().dispatchEvent(data);
216     }
217
218     public void addChatListener(ChatListener l)
219     {
220         ircfw.addChatListener(l);
221     }
222
223     public void addTemporaryListener(ChatListener l)
224     {
225         ircfw.addTemporaryListener(l);
226     }
227
228     public ChatFramework getChatFramework()
229     {
230         return ircfw;
231     }
232
233     public void registerCommand(String JavaDoc command, ClientCommand code)
234     {
235         UserHandler commands = (UserHandler)getDataStructure("commands");
236         commands.registerCommand(command, code);
237     }
238
239     public void setupFeature(Feature aFeature, LinkedList features)
240     {
241         aFeature.storeDataStructures(data);
242         aFeature.installCapabilities(this);
243  
244         features.add(aFeature);
245     }
246  
247     public void finalizeFeatures(LinkedList features)
248     {
249         ListIterator i = features.listIterator();
250         while (i.hasNext())
251         {
252            Feature temp = (Feature)i.next();
253            temp.init();
254         }
255     }
256
257     public GlobalCapabilities getGlobalCapabilities()
258     {
259         return SessionManager.getGlobalCapabilities();
260     }
261 }
262
Popular Tags