KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quickserver > util > xmlreader > ConfigReader


1 /*
2  * This file is part of the QuickServer library
3  * Copyright (C) QuickServer.org
4  *
5  * Use, modification, copying and distribution of this software is subject to
6  * the terms and conditions of the GNU Lesser General Public License.
7  * You should have received a copy of the GNU LGP License along with this
8  * library; if not, you can download a copy from <http://www.quickserver.org/>.
9  *
10  * For questions, suggestions, bug-reports, enhancement-requests etc.
11  * visit http://www.quickserver.org
12  *
13  */

14
15 package org.quickserver.util.xmlreader;
16
17 import org.apache.commons.digester.*;
18 import java.io.*;
19 import java.util.*;
20 import org.quickserver.util.*;
21 import org.quickserver.util.io.*;
22 import java.util.logging.*;
23 import org.quickserver.swing.*;
24 import org.quickserver.net.server.QuickServer;
25
26 /**
27  * This class reads the xml configuration and gives
28  * QuickServerConfig object.
29  * @author Akshathkumar Shetty
30  * @since 1.3
31  */

32 public class ConfigReader {
33     private static Logger logger = Logger.getLogger(ConfigReader.class.getName());
34
35     /**
36      * Parses XML config of QuickServer of version 1.3 and above
37      * @since 1.3
38      */

39     public static QuickServerConfig read(String JavaDoc fileName) throws Exception JavaDoc {
40         File input = new File(fileName);
41         return read(input);
42     }
43
44     /**
45      * Parses XML config of QuickServer of version 1.3 and above
46      * @since 1.4
47      */

48     public static QuickServerConfig read(File input) throws Exception JavaDoc {
49         Digester digester = new Digester();
50         digester.setValidating(false);
51
52         //digester.setNamespaceAware(true);
53
//String xsd = "" + new File("quickserver_config.xsd").toURI();
54
//digester.setSchema(xsd);
55
String JavaDoc mainTag = "quickserver";
56         String JavaDoc subTag = "";
57         
58         digester.addObjectCreate(mainTag, QuickServerConfig.class);
59         digester.addBeanPropertySetter(mainTag+"/name", "name");
60         digester.addBeanPropertySetter(mainTag+"/server-banner", "serverBanner");
61         digester.addBeanPropertySetter(mainTag+"/port", "port");
62         digester.addBeanPropertySetter(mainTag+"/bind-address", "bindAddr");
63         //<server-mode>
64
String JavaDoc curTag = mainTag+"/server-mode";
65         digester.addObjectCreate(curTag, ServerMode.class);
66         digester.addBeanPropertySetter(curTag+"/blocking", "blocking");
67         digester.addSetNext(curTag,"setServerMode");
68         //</server-mode>
69
digester.addBeanPropertySetter(mainTag+"/client-event-handler", "clientEventHandler");//v1.4.6
70
digester.addBeanPropertySetter(mainTag+"/client-command-handler", "clientCommandHandler");
71         digester.addBeanPropertySetter(mainTag+"/client-object-handler", "clientObjectHandler");
72         digester.addBeanPropertySetter(mainTag+"/client-binary-handler", "clientBinaryHandler");//v1.4
73
digester.addBeanPropertySetter(mainTag+"/client-write-handler", "clientWriteHandler");//v1.4.5
74
digester.addBeanPropertySetter(mainTag+"/authenticator", "authenticator"); //v1.3
75
digester.addBeanPropertySetter(mainTag+"/client-authentication-handler", "clientAuthenticationHandler"); //v1.4.6
76
digester.addBeanPropertySetter(mainTag+"/client-data", "clientData");
77         digester.addBeanPropertySetter(mainTag+"/client-extended-event-handler", "clientExtendedEventHandler");//v1.4.6
78
digester.addBeanPropertySetter(mainTag+"/timeout", "timeout");
79         digester.addBeanPropertySetter(mainTag+"/timeout-msg", "timeoutMsg");
80         digester.addBeanPropertySetter(mainTag+"/max-auth-try", "maxAuthTry");
81         digester.addBeanPropertySetter(mainTag+"/max-auth-try-msg", "maxAuthTryMsg");
82         digester.addBeanPropertySetter(mainTag+"/max-connection", "maxConnection");
83         digester.addBeanPropertySetter(mainTag+"/max-connection-msg", "maxConnectionMsg");
84         digester.addBeanPropertySetter(mainTag+"/console-logging-level", "consoleLoggingLevel");
85         digester.addBeanPropertySetter(mainTag+"/console-logging-formatter", "consoleLoggingFormatter");
86         //<default-data-mode>
87
curTag = mainTag+"/default-data-mode";
88         digester.addObjectCreate(curTag, DefaultDataMode.class);
89         digester.addBeanPropertySetter(curTag+"/data-type-in", "dataModeIn");
90         digester.addBeanPropertySetter(curTag+"/data-type-out", "dataModeOut");
91         digester.addSetNext(curTag,"setDefaultDataMode");
92         //</default-data-mode>
93
//<object-pool>
94
curTag = mainTag+"/object-pool";
95         digester.addObjectCreate(curTag, ObjectPoolConfig.class);
96         digester.addBeanPropertySetter(curTag+"/max-active", "maxActive");
97         digester.addBeanPropertySetter(curTag+"/max-idle", "maxIdle");
98         digester.addBeanPropertySetter(curTag+"/init-size", "initSize");
99         digester.addBeanPropertySetter(curTag+"/pool-manager", "poolManager");
100         //<thread-object-pool>
101
digester.addObjectCreate(curTag+"/thread-object-pool", ThreadObjectPoolConfig.class);
102         digester.addBeanPropertySetter(curTag+"/thread-object-pool/max-active", "maxActive");
103         digester.addBeanPropertySetter(curTag+"/thread-object-pool/max-idle", "maxIdle");
104         digester.addBeanPropertySetter(curTag+"/thread-object-pool/init-size", "initSize");
105         digester.addSetNext(curTag+"/thread-object-pool","setThreadObjectPoolConfig");
106         //</thread-object-pool>
107
//<client-handler-object-pool>
108
digester.addObjectCreate(curTag+"/client-handler-object-pool", ClientHandlerObjectPoolConfig.class);
109         digester.addBeanPropertySetter(curTag+"/client-handler-object-pool/max-active", "maxActive");
110         digester.addBeanPropertySetter(curTag+"/client-handler-object-pool/max-idle", "maxIdle");
111         digester.addBeanPropertySetter(curTag+"/client-handler-object-pool/init-size", "initSize");
112         digester.addSetNext(curTag+"/client-handler-object-pool","setClientHandlerObjectPoolConfig");
113         //</client-handler-object-pool>
114
//<byte-buffer-object-pool>
115
digester.addObjectCreate(curTag+"/byte-buffer-object-pool", ByteBufferObjectPoolConfig.class);
116         digester.addBeanPropertySetter(curTag+"/byte-buffer-object-pool/max-active", "maxActive");
117         digester.addBeanPropertySetter(curTag+"/byte-buffer-object-pool/max-idle", "maxIdle");
118         digester.addBeanPropertySetter(curTag+"/byte-buffer-object-pool/init-size", "initSize");
119         digester.addSetNext(curTag+"/byte-buffer-object-pool","setByteBufferObjectPoolConfig");
120         //</byte-buffer-object-pool>
121
//<client-data-object-pool>
122
digester.addObjectCreate(curTag+"/client-data-object-pool", ClientDataObjectPoolConfig.class);
123         digester.addBeanPropertySetter(curTag+"/client-data-object-pool/max-active", "maxActive");
124         digester.addBeanPropertySetter(curTag+"/client-data-object-pool/max-idle", "maxIdle");
125         digester.addBeanPropertySetter(curTag+"/client-data-object-pool/init-size", "initSize");
126         digester.addSetNext(curTag+"/client-data-object-pool","setClientDataObjectPoolConfig");
127         //</client-data-object-pool>
128
digester.addSetNext(curTag,"setObjectPoolConfig");
129         //</object-pool>
130
//<communication-logging>
131
digester.addBeanPropertySetter(mainTag+"/communication-logging/enable", "communicationLogging");
132         //</communication-logging>
133
digester.addBeanPropertySetter(mainTag+"/security-manager-class", "securityManagerClass");
134         
135         //<access-constraint>
136
digester.addObjectCreate(mainTag+"/access-constraint", AccessConstraintConfig.class);
137         //<ip-filter>
138
digester.addObjectCreate(mainTag+"/access-constraint/ip-filter", IpFilterConfig.class);
139         digester.addBeanPropertySetter(mainTag+"/access-constraint/ip-filter/enable", "enable");
140         digester.addBeanPropertySetter(mainTag+"/access-constraint/ip-filter/allow-access", "allowAccess");
141         //<ip-collection>
142
digester.addCallMethod(mainTag+"/access-constraint/ip-filter/ip-collection/client-ip-address", "addClientIpAddress", 0);
143         //<ip-collection>
144
digester.addSetNext(mainTag+"/access-constraint/ip-filter", "setIpFilterConfig");
145         //<ip-filter>
146
digester.addSetNext(mainTag+"/access-constraint", "setAccessConstraintConfig");
147         //</access-constraint>
148

149         //<application-jar-path>
150
digester.addBeanPropertySetter(mainTag+"/application-jar-path", "applicationJarPath");
151
152         //<server-hooks>
153
digester.addObjectCreate(mainTag+"/server-hooks", ServerHooks.class);
154         digester.addCallMethod(mainTag+"/server-hooks/class-name", "addClassName", 0);
155         digester.addSetNext(mainTag+"/server-hooks", "setServerHooks");
156         //</server-hooks>
157

158         //<secure>
159
curTag = mainTag+"/secure";
160         digester.addObjectCreate(curTag, Secure.class);
161         digester.addBeanPropertySetter(curTag+"/enable", "enable");
162         digester.addBeanPropertySetter(curTag+"/load", "load");
163         digester.addBeanPropertySetter(curTag+"/port", "port");
164         digester.addBeanPropertySetter(curTag+"/protocol", "protocol");
165         digester.addBeanPropertySetter(curTag+"/client-auth-enable", "clientAuthEnable");
166         //<secure-store>
167
digester.addObjectCreate(curTag+"/secure-store", SecureStore.class);
168         digester.addBeanPropertySetter(curTag+"/secure-store/type", "type");
169         digester.addBeanPropertySetter(curTag+"/secure-store/algorithm", "algorithm");
170         digester.addBeanPropertySetter(curTag+"/secure-store/provider", "provider");
171         //<key-store-info>
172
digester.addObjectCreate(curTag+"/secure-store/key-store-info", KeyStoreInfo.class);
173         digester.addBeanPropertySetter(curTag+"/secure-store/key-store-info/store-file", "storeFile");
174         digester.addBeanPropertySetter(curTag+"/secure-store/key-store-info/store-password", "storePassword");
175         digester.addBeanPropertySetter(curTag+"/secure-store/key-store-info/key-password", "keyPassword");
176         digester.addSetNext(curTag+"/secure-store/key-store-info","setKeyStoreInfo");
177         //</key-store-info>
178
//<trust-store-info>
179
digester.addObjectCreate(curTag+"/secure-store/trust-store-info", TrustStoreInfo.class);
180         digester.addBeanPropertySetter(curTag+"/secure-store/trust-store-info/store-file", "storeFile");
181         digester.addBeanPropertySetter(curTag+"/secure-store/trust-store-info/store-password", "storePassword");
182         digester.addBeanPropertySetter(curTag+"/secure-store/trust-store-info/type", "type");
183         digester.addBeanPropertySetter(curTag+"/secure-store/trust-store-info/provider", "provider");
184         digester.addSetNext(curTag+"/secure-store/trust-store-info","setTrustStoreInfo");
185         //</trust-store-info>
186
digester.addBeanPropertySetter(curTag+"/secure-store/secure-store-manager", "secureStoreManager");
187         digester.addSetNext(curTag+"/secure-store","setSecureStore");
188         //</secure-store>
189
digester.addSetNext(curTag,"setSecure");
190         //</secure>
191

192         //<advanced-settings>
193
curTag = mainTag+"/advanced-settings";
194         digester.addObjectCreate(curTag, AdvancedSettings.class);
195         digester.addBeanPropertySetter(curTag+"/charset", "charset");
196         digester.addBeanPropertySetter(curTag+"/byte-buffer-size", "byteBufferSize");
197         digester.addBeanPropertySetter(curTag+"/backlog", "backlog");
198         digester.addBeanPropertySetter(curTag+"/use-direct-byte-buffer", "useDirectByteBuffer");
199         digester.addBeanPropertySetter(curTag+"/socket-linger", "socketLinger");
200         digester.addBeanPropertySetter(curTag+"/debug-non-blocking-mode", "debugNonBlockingMode");
201         digester.addBeanPropertySetter(curTag+"/client-identifier", "clientIdentifier");
202         digester.addBeanPropertySetter(curTag+"/qsobject-pool-maker", "qSObjectPoolMaker");
203         digester.addBeanPropertySetter(curTag+"/max-threads-for-nio-write", "maxThreadsForNioWrite");
204         digester.addSetNext(curTag,"setAdvancedSettings");
205         //</advanced-settings>
206

207         //<qsadmin-server>
208
subTag = "qsadmin-server";
209         curTag = mainTag+"/"+subTag;
210         digester.addObjectCreate(curTag, QSAdminServerConfig.class);
211         digester.addBeanPropertySetter(curTag+"/name", "name");
212         digester.addBeanPropertySetter(curTag+"/server-banner", "serverBanner");
213         digester.addBeanPropertySetter(curTag+"/port", "port");
214         //<server-mode>
215
digester.addObjectCreate(curTag+"/server-mode", ServerMode.class);
216         digester.addBeanPropertySetter(curTag+"/server-mode/blocking", "blocking");
217         digester.addSetNext(curTag+"/server-mode","setServerMode");
218         //</server-mode>
219
digester.addBeanPropertySetter(curTag+"/client-event-handler", "clientEventHandler");
220         digester.addBeanPropertySetter(curTag+"/client-command-handler", "clientCommandHandler");
221         digester.addBeanPropertySetter(curTag+"/client-object-handler", "clientObjectHandler");
222         digester.addBeanPropertySetter(curTag+"/client-binary-handler", "clientBinaryHandler");//v1.4
223
digester.addBeanPropertySetter(curTag+"/client-write-handler", "clientWriteHandler");//v1.4.5
224
digester.addBeanPropertySetter(curTag+"/authenticator", "authenticator"); //v1.3
225
digester.addBeanPropertySetter(curTag+"/client-authentication-handler", "clientAuthenticationHandler"); //v1.4.6
226
digester.addBeanPropertySetter(curTag+"/client-data", "clientData");
227         digester.addBeanPropertySetter(curTag+"/client-extended-event-handler", "clientExtendedEventHandler");//v1.4.6
228
digester.addBeanPropertySetter(curTag+"/timeout", "timeout");
229         digester.addBeanPropertySetter(curTag+"/max-auth-try", "maxAuthTry");
230         digester.addBeanPropertySetter(curTag+"/max-auth-try-msg", "maxAuthTryMsg");
231         digester.addBeanPropertySetter(curTag+"/timeout-msg", "timeoutMsg");
232         digester.addBeanPropertySetter(curTag+"/max-connection", "maxConnection");
233         digester.addBeanPropertySetter(curTag+"/max-connection-msg", "maxConnectionMsg");
234         digester.addBeanPropertySetter(curTag+"/bind-address", "bindAddr");
235         digester.addBeanPropertySetter(curTag+"/client-object-handler", "clientObjectHandler");
236         digester.addBeanPropertySetter(curTag+"/console-logging-level", "consoleLoggingLevel");
237         digester.addBeanPropertySetter(curTag+"/console-logging-formatter", "consoleLoggingFormatter");
238         //<default-data-mode>
239
digester.addObjectCreate(curTag+"/default-data-mode", DefaultDataMode.class);
240         digester.addBeanPropertySetter(curTag+"/default-data-mode/data-type-in", "dataModeIn");
241         digester.addBeanPropertySetter(curTag+"/default-data-mode/data-type-out", "dataModeOut");
242         digester.addSetNext(curTag+"/default-data-mode","setDefaultDataMode");
243         //</default-data-mode>
244
//<object-pool>
245
digester.addObjectCreate(curTag+"/object-pool", ObjectPoolConfig.class);
246         digester.addBeanPropertySetter(curTag+"/object-pool/max-active", "maxActive");
247         digester.addBeanPropertySetter(curTag+"/object-pool/max-idle", "maxIdle");
248         digester.addBeanPropertySetter(curTag+"/object-pool/init-size", "initSize");
249         digester.addBeanPropertySetter(curTag+"/object-pool/pool-manager", "poolManager");
250         //<thread-object-pool>
251
digester.addObjectCreate(curTag+"/object-pool/thread-object-pool", ThreadObjectPoolConfig.class);
252         digester.addBeanPropertySetter(curTag+"/object-pool/thread-object-pool/max-active", "maxActive");
253         digester.addBeanPropertySetter(curTag+"/object-pool/thread-object-pool/max-idle", "maxIdle");
254         digester.addBeanPropertySetter(curTag+"/object-pool/thread-object-pool/init-size", "initSize");
255         digester.addSetNext(curTag+"/object-pool/thread-object-pool","setThreadObjectPoolConfig");
256         //</thread-object-pool>
257
//<client-handler-object-pool>
258
digester.addObjectCreate(curTag+"/object-pool/client-handler-object-pool", ClientHandlerObjectPoolConfig.class);
259         digester.addBeanPropertySetter(curTag+"/object-pool/client-handler-object-pool/max-active", "maxActive");
260         digester.addBeanPropertySetter(curTag+"/object-pool/client-handler-object-pool/max-idle", "maxIdle");
261         digester.addBeanPropertySetter(curTag+"/object-pool/client-handler-object-pool/init-size", "initSize");
262         digester.addSetNext(curTag+"/object-pool/client-handler-object-pool","setClientHandlerObjectPoolConfig");
263         //</client-handler-object-pool>
264
//<byte-buffer-object-pool>
265
digester.addObjectCreate(curTag+"/object-pool/byte-buffer-object-pool", ByteBufferObjectPoolConfig.class);
266         digester.addBeanPropertySetter(curTag+"/object-pool/byte-buffer-object-pool/max-active", "maxActive");
267         digester.addBeanPropertySetter(curTag+"/object-pool/byte-buffer-object-pool/max-idle", "maxIdle");
268         digester.addBeanPropertySetter(curTag+"/object-pool/byte-buffer-object-pool/init-size", "initSize");
269         digester.addSetNext(curTag+"/object-pool/byte-buffer-object-pool","setByteBufferObjectPoolConfig");
270         //</byte-buffer-object-pool>
271
//<client-data-object-pool>
272
digester.addObjectCreate(curTag+"/object-pool/client-data-object-pool", ClientDataObjectPoolConfig.class);
273         digester.addBeanPropertySetter(curTag+"/object-pool/client-data-object-pool/max-active", "maxActive");
274         digester.addBeanPropertySetter(curTag+"/object-pool/client-data-object-pool/max-idle", "maxIdle");
275         digester.addBeanPropertySetter(curTag+"/object-pool/client-data-object-pool/init-size", "initSize");
276         digester.addSetNext(curTag+"/object-pool/client-data-object-pool","setClientDataObjectPoolConfig");
277         //</client-data-object-pool>
278
digester.addSetNext(curTag+"/object-pool", "setObjectPoolConfig");
279         //</object-pool>
280
//<command-shell>
281
digester.addBeanPropertySetter(curTag+"/command-shell/enable", "commandShellEnable");
282         digester.addBeanPropertySetter(curTag+"/command-shell/prompt-name", "commandShellPromptName");
283         //</command-shell>
284
//<communication-logging><enable>
285
digester.addBeanPropertySetter(curTag+"/communication-logging/enable", "communicationLogging");
286         //<access-constraint>
287
digester.addObjectCreate(curTag+"/access-constraint", AccessConstraintConfig.class);
288         //<ip-filter>
289
digester.addObjectCreate(curTag+"/access-constraint/ip-filter", IpFilterConfig.class);
290         digester.addBeanPropertySetter(curTag+"/access-constraint/ip-filter/enable", "enable");
291         digester.addBeanPropertySetter(curTag+"/access-constraint/ip-filter/allow-access", "allowAccess");
292         //<ip-collection>
293
digester.addCallMethod(curTag+"/access-constraint/ip-filter/ip-collection/client-ip-address", "addClientIpAddress", 0);
294         //<ip-collection>
295
digester.addSetNext(curTag+"/access-constraint/ip-filter", "setIpFilterConfig");
296         //<ip-filter>
297
digester.addSetNext(curTag+"/access-constraint", "setAccessConstraintConfig");
298         //</access-constraint>
299
//<server-hooks>
300
digester.addObjectCreate(curTag+"/server-hooks", ServerHooks.class);
301         digester.addCallMethod(curTag+"/server-hooks/class-name", "addClassName", 0);
302         digester.addSetNext(curTag+"/server-hooks", "setServerHooks");
303         //</server-hooks>
304

305         //<secure>
306
digester.addObjectCreate(curTag+"/secure", Secure.class);
307         digester.addBeanPropertySetter(curTag+"/secure/enable", "enable");
308         digester.addBeanPropertySetter(curTag+"/secure/load", "load");
309         digester.addBeanPropertySetter(curTag+"/secure/port", "port");
310         digester.addBeanPropertySetter(curTag+"/secure/protocol", "protocol");
311         digester.addBeanPropertySetter(curTag+"/secure/client-auth-enable", "clientAuthEnable");
312         //<secure-store>
313
digester.addObjectCreate(curTag+"/secure/secure-store", SecureStore.class);
314         digester.addBeanPropertySetter(curTag+"/secure/secure-store/type", "type");
315         digester.addBeanPropertySetter(curTag+"/secure/secure-store/algorithm", "algorithm");
316         digester.addBeanPropertySetter(curTag+"/secure/secure-store/provider", "provider");
317         //<key-store-info>
318
digester.addObjectCreate(curTag+"/secure/secure-store/key-store-info", KeyStoreInfo.class);
319         digester.addBeanPropertySetter(curTag+"/secure/secure-store/key-store-info/store-file", "storeFile");
320         digester.addBeanPropertySetter(curTag+"/secure/secure-store/key-store-info/store-password", "storePassword");
321         digester.addBeanPropertySetter(curTag+"/secure/secure-store/key-store-info/key-password", "keyPassword");
322         digester.addSetNext(curTag+"/secure/secure-store/key-store-info","setKeyStoreInfo");
323         //</key-store-info>
324
//<trust-store-info>
325
digester.addObjectCreate(curTag+"/secure/secure-store/trust-store-info", TrustStoreInfo.class);
326         digester.addBeanPropertySetter(curTag+"/secure/secure-store/trust-store-info/store-file", "storeFile");
327         digester.addBeanPropertySetter(curTag+"/secure/secure-store/trust-store-info/store-password", "storePassword");
328         digester.addBeanPropertySetter(curTag+"/secure/secure-store/trust-store-info/type", "type");
329         digester.addBeanPropertySetter(curTag+"/secure/secure-store/trust-store-info/provider", "provider");
330         digester.addSetNext(curTag+"/secure/secure-store/trust-store-info","setTrustStoreInfo");
331         //</trust-store-info>
332
digester.addBeanPropertySetter(curTag+"/secure/secure-store/secure-store-manager", "secureStoreManager");
333         digester.addSetNext(curTag+"/secure/secure-store","setSecureStore");
334         //</secure-store>
335
digester.addSetNext(curTag+"/secure","setSecure");
336         //</secure>
337
digester.addBeanPropertySetter(curTag+"/command-plugin", "commandPlugin");
338         //<advanced-settings>
339
digester.addObjectCreate(curTag+"/advanced-settings", AdvancedSettings.class);
340         digester.addBeanPropertySetter(curTag+"/advanced-settings/charset", "charset");
341         digester.addBeanPropertySetter(curTag+"/advanced-settings/byte-buffer-size", "byteBufferSize");
342         digester.addBeanPropertySetter(curTag+"/advanced-settings/backlog", "backlog");
343         digester.addBeanPropertySetter(curTag+"/advanced-settings/use-direct-byte-buffer", "useDirectByteBuffer");
344         digester.addBeanPropertySetter(curTag+"/advanced-settings/socket-linger", "socketLinger");
345         digester.addBeanPropertySetter(curTag+"/advanced-settings/debug-non-blocking-mode", "debugNonBlockingMode");
346         digester.addBeanPropertySetter(curTag+"/advanced-settings/client-identifier", "clientIdentifier");
347         digester.addBeanPropertySetter(curTag+"/advanced-settings/qsobject-pool-maker", "qSObjectPoolMaker");
348         digester.addBeanPropertySetter(curTag+"/advanced-settings/max-threads-for-nio-write", "maxThreadsForNioWrite");
349         digester.addSetNext(curTag+"/advanced-settings","setAdvancedSettings");
350         //</advanced-settings>
351
digester.addSetNext(curTag, "setQSAdminServerConfig");
352         //</qsadmin-server>
353

354
355         //<db-object-pool>
356
subTag = "db-object-pool";
357         digester.addObjectCreate(mainTag+"/"+subTag, DBObjectPoolConfig.class);
358         //<database-connection-set>
359
digester.addObjectCreate(mainTag+"/"+subTag+"/database-connection-set", DatabaseConnectionSet.class);
360         //<database-connection>
361
curTag = mainTag+"/"+subTag+"/database-connection-set/database-connection";
362         digester.addObjectCreate(curTag, DatabaseConnectionConfig.class);
363         digester.addBeanPropertySetter(curTag+"/id", "id");
364         digester.addBeanPropertySetter(curTag+"/driver", "driver");
365         digester.addBeanPropertySetter(curTag+"/url", "url");
366         digester.addBeanPropertySetter(curTag+"/username", "username");
367         digester.addBeanPropertySetter(curTag+"/password", "password");
368         digester.addSetNext(curTag, "addDatabaseConnection");
369         //</database-connection>
370
digester.addSetNext(mainTag+"/"+subTag+"/database-connection-set", "setDatabaseConnectionSet");
371         //</database-connection-set>
372
//<db-pool-util>
373
curTag = mainTag+"/"+subTag+"/db-pool-util";
374         digester.addBeanPropertySetter(curTag, "dbPoolUtil");
375         //</db-pool-util>
376
digester.addSetNext(mainTag+"/"+subTag, "setDBObjectPoolConfig");
377         //</db-object-pool>
378

379
380         //<application-configuration>
381
subTag = "application-configuration";
382         digester.addObjectCreate(mainTag+"/"+subTag, ApplicationConfiguration.class);
383         digester.addBeanPropertySetter(mainTag+"/"+subTag+"/prompt-type", "promptType");
384         curTag = mainTag+"/"+subTag+"/"+"property";
385         digester.addObjectCreate(curTag, Property.class);
386         digester.addBeanPropertySetter(curTag+"/property-name", "name");
387         digester.addBeanPropertySetter(curTag+"/property-value", "value");
388         digester.addSetNext(curTag, "addProperty");
389         digester.addSetNext(mainTag+"/"+subTag, "setApplicationConfiguration");
390         //</application-configuration>
391

392
393         //<init-server-hooks>
394
subTag = "init-server-hooks";
395         digester.addObjectCreate(mainTag+"/"+subTag, InitServerHooks.class);
396         digester.addCallMethod(mainTag+"/"+subTag+"/class-name",
397             "addClassName", 0);
398         digester.addSetNext(mainTag+"/"+subTag, "setInitServerHooks");
399         //</init-server-hooks>
400

401         logger.fine("Loading config from xml file : " + input.getAbsolutePath());
402         QuickServerConfig qsc = (QuickServerConfig) digester.parse(input);
403         qsc.setConfigFile(input.getAbsolutePath());
404         
405         loadMissingApplicationConfiguration(qsc);
406
407         QuickServer.setDebugNonBlockingMode(qsc.getAdvancedSettings().getDebugNonBlockingMode());
408
409         return qsc;
410     }
411
412     private static void loadMissingApplicationConfiguration(QuickServerConfig qsc)
413             throws IOException {
414         ApplicationConfiguration ac = qsc.getApplicationConfiguration();
415         if(ac==null) return;
416
417         //check if any application-configuration had missing property-value
418
Set propertyNames = ac.keySet();
419         Iterator iterator = propertyNames.iterator();
420         String JavaDoc key = null;
421         Object JavaDoc value = null;
422         char sv[] = null;
423         SensitiveInput sensitiveInput = null;
424         boolean guiPrompt = ac.getPromptType().equals("console")==false?true:false;
425
426         while(iterator.hasNext()) {
427             key = (String JavaDoc) iterator.next();
428             value = ac.get(key);
429             if(value==null) {
430                 if(guiPrompt && sensitiveInput==null) {
431                     sensitiveInput = new SensitiveInput(
432                         qsc.getName()+" - Input Prompt");
433                 }
434                 
435                 if(guiPrompt)
436                     sv = sensitiveInput.getInput(key);
437                 else
438                     sv = PasswordField.getPassword("Input property value for "+key+" : ");
439
440                 if(sv!=null) {
441                     value = new String JavaDoc(sv);
442                     ac.put(key, value);
443                 }
444                 value = null;
445             }
446         }
447     }
448
449     /**
450      * Make the file passed absolute, relative to the location of
451      * configuration file that loaded QuickServerConfig object passed.
452      * @since 1.4
453      */

454     public static File makeAbsoluteToConfig(String JavaDoc fileName,
455             QuickServerConfig config) {
456         File file = new File(fileName);
457         if(config==null) return file;
458         if(file.isAbsolute()==false) {
459             String JavaDoc temp = config.getConfigFile();
460             file = new File(temp);
461             temp = file.getParent() + File.separatorChar + fileName;
462             file = new File(temp);
463         }
464         return file;
465     }
466 }
467
Popular Tags