KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > qfs > apps > qflog > App


1 // {{{ copyright
2

3 /********************************************************************
4  *
5  * $Id: App.java,v 1.13 2000/07/05 14:07:43 gs Exp $
6  *
7  * The contents of this file are subject to the Mozilla Public
8  * License Version 1.1 (the "License"); you may not use this file
9  * except in compliance with the License. You may obtain a copy of
10  * the License at http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS
13  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14  * implied. See the License for the specific language governing
15  * rights and limitations under the License.
16  *
17  * The Original Code is qfs.de code.
18  *
19  * The Initial Developer of the Original Code is Gregor Schmid.
20  * Portions created by Gregor Schmid are
21  * Copyright (C) 1999 Quality First Software, Gregor Schmid.
22  * All Rights Reserved.
23  *
24  * Contributor(s):
25  *
26  *******************************************************************/

27
28 // }}}
29

30 package de.qfs.apps.qflog;
31
32 // {{{ imports
33

34 import java.io.File JavaDoc;
35 import java.io.IOException JavaDoc;
36
37 import java.util.Locale JavaDoc;
38 import java.util.MissingResourceException JavaDoc;
39 import java.util.PropertyResourceBundle JavaDoc;
40 import java.util.ResourceBundle JavaDoc;
41
42 import de.qfs.lib.command.CommandDistributor;
43 import de.qfs.lib.config.Configuration;
44 import de.qfs.lib.log.Log;
45 import de.qfs.lib.log.Logger;
46 import de.qfs.lib.option.IntegerOption;
47 import de.qfs.lib.option.OptionSet;
48 import de.qfs.lib.util.MapResourceBundle;
49
50 import de.qfs.apps.qflog.logview.LogView;
51
52 // }}}
53

54 /**
55  * Convenience class that gives access to the major pieces of the qflog
56  * application.
57  *
58  * @author Gregor Schmid
59  * @version $Revision: 1.13 $
60  */

61 public class App
62 {
63     // {{{ variables
64

65     /**
66      * The Logger used for logging.
67      */

68     private final static Logger logger = new Logger (App.class);
69
70     /**
71      * The instance.
72      */

73     private static App theApp = new App ();
74
75     /**
76      * The Options.
77      */

78     private OptionSet options;
79
80     /**
81      * The resources.
82      */

83     private MapResourceBundle resources;
84
85     /**
86      * The CommandDistributor.
87      */

88     private CommandDistributor cd = new CommandDistributor();
89
90     /**
91      * The configFile of the App.
92      */

93     private File JavaDoc configFile;
94
95     /**
96      * The serverName of the App.
97      */

98     private String JavaDoc serverName;
99
100     /**
101      * The serverHost of the App.
102      */

103     private String JavaDoc serverHost;
104
105     // }}}
106

107     // {{{ constructor
108

109     /**
110      * Create a new App. Private due to singleton pattern.
111      */

112     private App()
113     {
114         if (logger.level >= Log.MTD) {
115             logger.log(Log.MTD, "App()", "");
116         }
117         reloadResources();
118         initOptions();
119     }
120
121     // }}}
122

123     // {{{ instance
124

125     /**
126      * Get the singleton App instance.
127      *
128      * @return The single App instance.
129      */

130     public static App instance()
131     {
132         if (logger.level >= Log.MTD) {
133             logger.log(Log.MTD, "instance()", "");
134         }
135         return theApp;
136     }
137
138
139     // }}}
140

141     //----------------------------------------------------------------------
142
// static convenience shortcuts
143
//----------------------------------------------------------------------
144
// {{{ getResources
145

146     /**
147      * Get the resources of the application.
148      *
149      * @return The resources of the App.
150      */

151     public final static MapResourceBundle getResources()
152     {
153         if (logger.level >= Log.MTD) {
154             logger.log(Log.MTD, "getResources()", "");
155         }
156         return instance()._getResources();
157     }
158
159     // }}}
160
// {{{ getCommandDistributor
161

162     /**
163      * Get the CommandDistributor used by the application.
164      *
165      * @return The CommandDistributor.
166      */

167     public static CommandDistributor getCommandDistributor()
168     {
169         return instance()._getCommandDistributor();
170     }
171
172     // }}}
173
// {{{ getOptions
174

175     /**
176      * Get the Options for the application.
177      *
178      * @return The Options.
179      */

180     public static OptionSet getOptions()
181     {
182         return instance()._getOptions();
183     }
184
185     // }}}
186

187     //----------------------------------------------------------------------
188
// instance methods
189
//----------------------------------------------------------------------
190
// {{{ _getResources
191

192     /**
193      * Get the resources of the application.
194      *
195      * @return The resources of the App.
196      */

197     private final MapResourceBundle _getResources()
198     {
199         return resources;
200     }
201
202     // }}}
203
// {{{ _getCommandDistributor
204

205     /**
206      * Get the CommandDistributor used by the application.
207      *
208      * @return The CommandDistributor.
209      */

210     private final CommandDistributor _getCommandDistributor()
211     {
212         return cd;
213     }
214
215     // }}}
216
// {{{ _getOptions
217

218     /**
219      * Get the Options for the application.
220      *
221      * @return The Options.
222      */

223     private final OptionSet _getOptions()
224     {
225         return options;
226     }
227
228     // }}}
229

230     // {{{ reloadResources
231

232     /**
233      * (Re)load the resources for the application.
234      */

235     public void reloadResources ()
236     {
237         if (logger.level >= Log.MTD) {
238             logger.log(Log.MTD, "reloadResources()", "");
239         }
240         try {
241             resources = new MapResourceBundle();
242             ((MapResourceBundle)resources).fetchProperties
243                 ("/de/qfs/lib/resources/properties/qflib",
244                  MapResourceBundle.class);
245             ((MapResourceBundle)resources).fetchProperties
246                 ("/de/qfs/apps/qflog/logview/resources/properties/logview",
247                  LogView.class);
248             ((MapResourceBundle)resources).fetchProperties
249                 ("/de/qfs/apps/qflog/logview/resources/properties/loglevelview",
250                  LogView.class);
251             ((MapResourceBundle)resources).fetchProperties
252                 ("/de/qfs/apps/qflog/logview/resources/properties/logtableview",
253                  LogView.class);
254             ((MapResourceBundle)resources).fetchProperties
255                 ("/de/qfs/apps/qflog/resources/properties/logserver",
256                  getClass());
257         } catch (MissingResourceException JavaDoc ex) {
258             if (logger.level >= Log.ERR) {
259                 logger.log("reloadResources()", ex);
260             }
261         }
262     }
263
264     // }}}
265

266     // {{{ getConfigFile
267

268     /**
269      * Get the configFile of the application.
270      *
271      * @return The configFile of the application.
272      */

273     public final File JavaDoc getConfigFile()
274     {
275         return configFile;
276     }
277
278     // }}}
279
// {{{ setConfigFile
280

281     /**
282      * Set the configFile of the application.
283      *
284      * @param configFile The configFile to set.
285      */

286     public final void setConfigFile(File JavaDoc configFile)
287     {
288         this.configFile = configFile;
289     }
290
291     // }}}
292
// {{{ getServerName
293

294     /**
295      * Get the serverName of the application.
296      *
297      * @return The serverName of the application.
298      */

299     public final String JavaDoc getServerName()
300     {
301         return serverName;
302     }
303
304     // }}}
305
// {{{ setServerName
306

307     /**
308      * Set the serverName of the application.
309      *
310      * @param serverName The serverName to set.
311      */

312     public final void setServerName(String JavaDoc serverName)
313     {
314         this.serverName = serverName;
315     }
316
317     // }}}
318
// {{{ getServerHost
319

320     /**
321      * Get the serverHost of the application.
322      *
323      * @return The serverHost of the application.
324      */

325     public final String JavaDoc getServerHost()
326     {
327         return serverHost;
328     }
329
330     // }}}
331
// {{{ setServerHost
332

333     /**
334      * Set the serverHost of the application.
335      *
336      * @param serverHost The serverHost to set.
337      */

338     public final void setServerHost(String JavaDoc serverHost)
339     {
340         this.serverHost = serverHost;
341     }
342
343     // }}}
344

345     // {{{ initOptions
346

347     /**
348      * Initialize the Options for the application.
349      */

350     private void initOptions()
351     {
352         options = new OptionSet ("LogServer Options");
353         options.add(new IntegerOption ("maxClients", 4));
354         options.add(new IntegerOption ("maxNamedClients", 2));
355         options.add(new IntegerOption ("maxDeadClients", 2));
356         options.add(new IntegerOption ("maxDeadNamedClients", 1));
357         Configuration.instance().register(options);
358     }
359
360     // }}}
361
}
362
Popular Tags