001: /*
002: * This file is part of the QuickServer library
003: * Copyright (C) QuickServer.org
004: *
005: * Use, modification, copying and distribution of this software is subject to
006: * the terms and conditions of the GNU Lesser General Public License.
007: * You should have received a copy of the GNU LGP License along with this
008: * library; if not, you can download a copy from <http://www.quickserver.org/>.
009: *
010: * For questions, suggestions, bug-reports, enhancement-requests etc.
011: * visit http://www.quickserver.org
012: *
013: */
014:
015: package org.quickserver.util.xmlreader;
016:
017: import org.apache.commons.digester.*;
018: import java.io.*;
019: import java.util.*;
020: import org.quickserver.util.*;
021: import org.quickserver.util.io.*;
022: import java.util.logging.*;
023: import org.quickserver.swing.*;
024: import org.quickserver.net.server.QuickServer;
025:
026: /**
027: * This class reads the xml configuration and gives
028: * QuickServerConfig object.
029: * @author Akshathkumar Shetty
030: * @since 1.3
031: */
032: public class ConfigReader {
033: private static Logger logger = Logger.getLogger(ConfigReader.class
034: .getName());
035:
036: /**
037: * Parses XML config of QuickServer of version 1.3 and above
038: * @since 1.3
039: */
040: public static QuickServerConfig read(String fileName)
041: throws Exception {
042: File input = new File(fileName);
043: return read(input);
044: }
045:
046: /**
047: * Parses XML config of QuickServer of version 1.3 and above
048: * @since 1.4
049: */
050: public static QuickServerConfig read(File input) throws Exception {
051: Digester digester = new Digester();
052: digester.setValidating(false);
053:
054: //digester.setNamespaceAware(true);
055: //String xsd = "" + new File("quickserver_config.xsd").toURI();
056: //digester.setSchema(xsd);
057: String mainTag = "quickserver";
058: String subTag = "";
059:
060: digester.addObjectCreate(mainTag, QuickServerConfig.class);
061: digester.addBeanPropertySetter(mainTag + "/name", "name");
062: digester.addBeanPropertySetter(mainTag + "/server-banner",
063: "serverBanner");
064: digester.addBeanPropertySetter(mainTag + "/port", "port");
065: digester.addBeanPropertySetter(mainTag + "/bind-address",
066: "bindAddr");
067: //<server-mode>
068: String curTag = mainTag + "/server-mode";
069: digester.addObjectCreate(curTag, ServerMode.class);
070: digester
071: .addBeanPropertySetter(curTag + "/blocking", "blocking");
072: digester.addSetNext(curTag, "setServerMode");
073: //</server-mode>
074: digester.addBeanPropertySetter(mainTag
075: + "/client-event-handler", "clientEventHandler");//v1.4.6
076: digester.addBeanPropertySetter(mainTag
077: + "/client-command-handler", "clientCommandHandler");
078: digester.addBeanPropertySetter(mainTag
079: + "/client-object-handler", "clientObjectHandler");
080: digester.addBeanPropertySetter(mainTag
081: + "/client-binary-handler", "clientBinaryHandler");//v1.4
082: digester.addBeanPropertySetter(mainTag
083: + "/client-write-handler", "clientWriteHandler");//v1.4.5
084: digester.addBeanPropertySetter(mainTag + "/authenticator",
085: "authenticator"); //v1.3
086: digester.addBeanPropertySetter(mainTag
087: + "/client-authentication-handler",
088: "clientAuthenticationHandler"); //v1.4.6
089: digester.addBeanPropertySetter(mainTag + "/client-data",
090: "clientData");
091: digester.addBeanPropertySetter(mainTag
092: + "/client-extended-event-handler",
093: "clientExtendedEventHandler");//v1.4.6
094: digester.addBeanPropertySetter(mainTag + "/timeout", "timeout");
095: digester.addBeanPropertySetter(mainTag + "/timeout-msg",
096: "timeoutMsg");
097: digester.addBeanPropertySetter(mainTag + "/max-auth-try",
098: "maxAuthTry");
099: digester.addBeanPropertySetter(mainTag + "/max-auth-try-msg",
100: "maxAuthTryMsg");
101: digester.addBeanPropertySetter(mainTag + "/max-connection",
102: "maxConnection");
103: digester.addBeanPropertySetter(mainTag + "/max-connection-msg",
104: "maxConnectionMsg");
105: digester.addBeanPropertySetter(mainTag
106: + "/console-logging-level", "consoleLoggingLevel");
107: digester.addBeanPropertySetter(mainTag
108: + "/console-logging-formatter",
109: "consoleLoggingFormatter");
110: //<default-data-mode>
111: curTag = mainTag + "/default-data-mode";
112: digester.addObjectCreate(curTag, DefaultDataMode.class);
113: digester.addBeanPropertySetter(curTag + "/data-type-in",
114: "dataModeIn");
115: digester.addBeanPropertySetter(curTag + "/data-type-out",
116: "dataModeOut");
117: digester.addSetNext(curTag, "setDefaultDataMode");
118: //</default-data-mode>
119: //<object-pool>
120: curTag = mainTag + "/object-pool";
121: digester.addObjectCreate(curTag, ObjectPoolConfig.class);
122: digester.addBeanPropertySetter(curTag + "/max-active",
123: "maxActive");
124: digester.addBeanPropertySetter(curTag + "/max-idle", "maxIdle");
125: digester.addBeanPropertySetter(curTag + "/init-size",
126: "initSize");
127: digester.addBeanPropertySetter(curTag + "/pool-manager",
128: "poolManager");
129: //<thread-object-pool>
130: digester.addObjectCreate(curTag + "/thread-object-pool",
131: ThreadObjectPoolConfig.class);
132: digester.addBeanPropertySetter(curTag
133: + "/thread-object-pool/max-active", "maxActive");
134: digester.addBeanPropertySetter(curTag
135: + "/thread-object-pool/max-idle", "maxIdle");
136: digester.addBeanPropertySetter(curTag
137: + "/thread-object-pool/init-size", "initSize");
138: digester.addSetNext(curTag + "/thread-object-pool",
139: "setThreadObjectPoolConfig");
140: //</thread-object-pool>
141: //<client-handler-object-pool>
142: digester.addObjectCreate(
143: curTag + "/client-handler-object-pool",
144: ClientHandlerObjectPoolConfig.class);
145: digester
146: .addBeanPropertySetter(curTag
147: + "/client-handler-object-pool/max-active",
148: "maxActive");
149: digester.addBeanPropertySetter(curTag
150: + "/client-handler-object-pool/max-idle", "maxIdle");
151: digester.addBeanPropertySetter(curTag
152: + "/client-handler-object-pool/init-size", "initSize");
153: digester.addSetNext(curTag + "/client-handler-object-pool",
154: "setClientHandlerObjectPoolConfig");
155: //</client-handler-object-pool>
156: //<byte-buffer-object-pool>
157: digester.addObjectCreate(curTag + "/byte-buffer-object-pool",
158: ByteBufferObjectPoolConfig.class);
159: digester.addBeanPropertySetter(curTag
160: + "/byte-buffer-object-pool/max-active", "maxActive");
161: digester.addBeanPropertySetter(curTag
162: + "/byte-buffer-object-pool/max-idle", "maxIdle");
163: digester.addBeanPropertySetter(curTag
164: + "/byte-buffer-object-pool/init-size", "initSize");
165: digester.addSetNext(curTag + "/byte-buffer-object-pool",
166: "setByteBufferObjectPoolConfig");
167: //</byte-buffer-object-pool>
168: //<client-data-object-pool>
169: digester.addObjectCreate(curTag + "/client-data-object-pool",
170: ClientDataObjectPoolConfig.class);
171: digester.addBeanPropertySetter(curTag
172: + "/client-data-object-pool/max-active", "maxActive");
173: digester.addBeanPropertySetter(curTag
174: + "/client-data-object-pool/max-idle", "maxIdle");
175: digester.addBeanPropertySetter(curTag
176: + "/client-data-object-pool/init-size", "initSize");
177: digester.addSetNext(curTag + "/client-data-object-pool",
178: "setClientDataObjectPoolConfig");
179: //</client-data-object-pool>
180: digester.addSetNext(curTag, "setObjectPoolConfig");
181: //</object-pool>
182: //<communication-logging>
183: digester.addBeanPropertySetter(mainTag
184: + "/communication-logging/enable",
185: "communicationLogging");
186: //</communication-logging>
187: digester.addBeanPropertySetter(mainTag
188: + "/security-manager-class", "securityManagerClass");
189:
190: //<access-constraint>
191: digester.addObjectCreate(mainTag + "/access-constraint",
192: AccessConstraintConfig.class);
193: //<ip-filter>
194: digester.addObjectCreate(mainTag
195: + "/access-constraint/ip-filter", IpFilterConfig.class);
196: digester.addBeanPropertySetter(mainTag
197: + "/access-constraint/ip-filter/enable", "enable");
198: digester.addBeanPropertySetter(mainTag
199: + "/access-constraint/ip-filter/allow-access",
200: "allowAccess");
201: //<ip-collection>
202: digester
203: .addCallMethod(
204: mainTag
205: + "/access-constraint/ip-filter/ip-collection/client-ip-address",
206: "addClientIpAddress", 0);
207: //<ip-collection>
208: digester.addSetNext(mainTag + "/access-constraint/ip-filter",
209: "setIpFilterConfig");
210: //<ip-filter>
211: digester.addSetNext(mainTag + "/access-constraint",
212: "setAccessConstraintConfig");
213: //</access-constraint>
214:
215: //<application-jar-path>
216: digester.addBeanPropertySetter(mainTag
217: + "/application-jar-path", "applicationJarPath");
218:
219: //<server-hooks>
220: digester.addObjectCreate(mainTag + "/server-hooks",
221: ServerHooks.class);
222: digester.addCallMethod(mainTag + "/server-hooks/class-name",
223: "addClassName", 0);
224: digester
225: .addSetNext(mainTag + "/server-hooks", "setServerHooks");
226: //</server-hooks>
227:
228: //<secure>
229: curTag = mainTag + "/secure";
230: digester.addObjectCreate(curTag, Secure.class);
231: digester.addBeanPropertySetter(curTag + "/enable", "enable");
232: digester.addBeanPropertySetter(curTag + "/load", "load");
233: digester.addBeanPropertySetter(curTag + "/port", "port");
234: digester
235: .addBeanPropertySetter(curTag + "/protocol", "protocol");
236: digester.addBeanPropertySetter(curTag + "/client-auth-enable",
237: "clientAuthEnable");
238: //<secure-store>
239: digester.addObjectCreate(curTag + "/secure-store",
240: SecureStore.class);
241: digester.addBeanPropertySetter(curTag + "/secure-store/type",
242: "type");
243: digester.addBeanPropertySetter(curTag
244: + "/secure-store/algorithm", "algorithm");
245: digester.addBeanPropertySetter(curTag
246: + "/secure-store/provider", "provider");
247: //<key-store-info>
248: digester.addObjectCreate(curTag
249: + "/secure-store/key-store-info", KeyStoreInfo.class);
250: digester.addBeanPropertySetter(curTag
251: + "/secure-store/key-store-info/store-file",
252: "storeFile");
253: digester.addBeanPropertySetter(curTag
254: + "/secure-store/key-store-info/store-password",
255: "storePassword");
256: digester.addBeanPropertySetter(curTag
257: + "/secure-store/key-store-info/key-password",
258: "keyPassword");
259: digester.addSetNext(curTag + "/secure-store/key-store-info",
260: "setKeyStoreInfo");
261: //</key-store-info>
262: //<trust-store-info>
263: digester.addObjectCreate(curTag
264: + "/secure-store/trust-store-info",
265: TrustStoreInfo.class);
266: digester.addBeanPropertySetter(curTag
267: + "/secure-store/trust-store-info/store-file",
268: "storeFile");
269: digester.addBeanPropertySetter(curTag
270: + "/secure-store/trust-store-info/store-password",
271: "storePassword");
272: digester.addBeanPropertySetter(curTag
273: + "/secure-store/trust-store-info/type", "type");
274: digester
275: .addBeanPropertySetter(curTag
276: + "/secure-store/trust-store-info/provider",
277: "provider");
278: digester.addSetNext(curTag + "/secure-store/trust-store-info",
279: "setTrustStoreInfo");
280: //</trust-store-info>
281: digester.addBeanPropertySetter(curTag
282: + "/secure-store/secure-store-manager",
283: "secureStoreManager");
284: digester.addSetNext(curTag + "/secure-store", "setSecureStore");
285: //</secure-store>
286: digester.addSetNext(curTag, "setSecure");
287: //</secure>
288:
289: //<advanced-settings>
290: curTag = mainTag + "/advanced-settings";
291: digester.addObjectCreate(curTag, AdvancedSettings.class);
292: digester.addBeanPropertySetter(curTag + "/charset", "charset");
293: digester.addBeanPropertySetter(curTag + "/byte-buffer-size",
294: "byteBufferSize");
295: digester.addBeanPropertySetter(curTag + "/backlog", "backlog");
296: digester.addBeanPropertySetter(curTag
297: + "/use-direct-byte-buffer", "useDirectByteBuffer");
298: digester.addBeanPropertySetter(curTag + "/socket-linger",
299: "socketLinger");
300: digester.addBeanPropertySetter(curTag
301: + "/debug-non-blocking-mode", "debugNonBlockingMode");
302: digester.addBeanPropertySetter(curTag + "/client-identifier",
303: "clientIdentifier");
304: digester.addBeanPropertySetter(curTag + "/qsobject-pool-maker",
305: "qSObjectPoolMaker");
306: digester
307: .addBeanPropertySetter(curTag
308: + "/max-threads-for-nio-write",
309: "maxThreadsForNioWrite");
310: digester.addSetNext(curTag, "setAdvancedSettings");
311: //</advanced-settings>
312:
313: //<qsadmin-server>
314: subTag = "qsadmin-server";
315: curTag = mainTag + "/" + subTag;
316: digester.addObjectCreate(curTag, QSAdminServerConfig.class);
317: digester.addBeanPropertySetter(curTag + "/name", "name");
318: digester.addBeanPropertySetter(curTag + "/server-banner",
319: "serverBanner");
320: digester.addBeanPropertySetter(curTag + "/port", "port");
321: //<server-mode>
322: digester.addObjectCreate(curTag + "/server-mode",
323: ServerMode.class);
324: digester.addBeanPropertySetter(
325: curTag + "/server-mode/blocking", "blocking");
326: digester.addSetNext(curTag + "/server-mode", "setServerMode");
327: //</server-mode>
328: digester.addBeanPropertySetter(
329: curTag + "/client-event-handler", "clientEventHandler");
330: digester.addBeanPropertySetter(curTag
331: + "/client-command-handler", "clientCommandHandler");
332: digester.addBeanPropertySetter(curTag
333: + "/client-object-handler", "clientObjectHandler");
334: digester.addBeanPropertySetter(curTag
335: + "/client-binary-handler", "clientBinaryHandler");//v1.4
336: digester.addBeanPropertySetter(
337: curTag + "/client-write-handler", "clientWriteHandler");//v1.4.5
338: digester.addBeanPropertySetter(curTag + "/authenticator",
339: "authenticator"); //v1.3
340: digester.addBeanPropertySetter(curTag
341: + "/client-authentication-handler",
342: "clientAuthenticationHandler"); //v1.4.6
343: digester.addBeanPropertySetter(curTag + "/client-data",
344: "clientData");
345: digester.addBeanPropertySetter(curTag
346: + "/client-extended-event-handler",
347: "clientExtendedEventHandler");//v1.4.6
348: digester.addBeanPropertySetter(curTag + "/timeout", "timeout");
349: digester.addBeanPropertySetter(curTag + "/max-auth-try",
350: "maxAuthTry");
351: digester.addBeanPropertySetter(curTag + "/max-auth-try-msg",
352: "maxAuthTryMsg");
353: digester.addBeanPropertySetter(curTag + "/timeout-msg",
354: "timeoutMsg");
355: digester.addBeanPropertySetter(curTag + "/max-connection",
356: "maxConnection");
357: digester.addBeanPropertySetter(curTag + "/max-connection-msg",
358: "maxConnectionMsg");
359: digester.addBeanPropertySetter(curTag + "/bind-address",
360: "bindAddr");
361: digester.addBeanPropertySetter(curTag
362: + "/client-object-handler", "clientObjectHandler");
363: digester.addBeanPropertySetter(curTag
364: + "/console-logging-level", "consoleLoggingLevel");
365: digester.addBeanPropertySetter(curTag
366: + "/console-logging-formatter",
367: "consoleLoggingFormatter");
368: //<default-data-mode>
369: digester.addObjectCreate(curTag + "/default-data-mode",
370: DefaultDataMode.class);
371: digester.addBeanPropertySetter(curTag
372: + "/default-data-mode/data-type-in", "dataModeIn");
373: digester.addBeanPropertySetter(curTag
374: + "/default-data-mode/data-type-out", "dataModeOut");
375: digester.addSetNext(curTag + "/default-data-mode",
376: "setDefaultDataMode");
377: //</default-data-mode>
378: //<object-pool>
379: digester.addObjectCreate(curTag + "/object-pool",
380: ObjectPoolConfig.class);
381: digester.addBeanPropertySetter(curTag
382: + "/object-pool/max-active", "maxActive");
383: digester.addBeanPropertySetter(
384: curTag + "/object-pool/max-idle", "maxIdle");
385: digester.addBeanPropertySetter(curTag
386: + "/object-pool/init-size", "initSize");
387: digester.addBeanPropertySetter(curTag
388: + "/object-pool/pool-manager", "poolManager");
389: //<thread-object-pool>
390: digester.addObjectCreate(curTag
391: + "/object-pool/thread-object-pool",
392: ThreadObjectPoolConfig.class);
393: digester.addBeanPropertySetter(curTag
394: + "/object-pool/thread-object-pool/max-active",
395: "maxActive");
396: digester
397: .addBeanPropertySetter(curTag
398: + "/object-pool/thread-object-pool/max-idle",
399: "maxIdle");
400: digester.addBeanPropertySetter(curTag
401: + "/object-pool/thread-object-pool/init-size",
402: "initSize");
403: digester.addSetNext(curTag + "/object-pool/thread-object-pool",
404: "setThreadObjectPoolConfig");
405: //</thread-object-pool>
406: //<client-handler-object-pool>
407: digester.addObjectCreate(curTag
408: + "/object-pool/client-handler-object-pool",
409: ClientHandlerObjectPoolConfig.class);
410: digester.addBeanPropertySetter(curTag
411: + "/object-pool/client-handler-object-pool/max-active",
412: "maxActive");
413: digester.addBeanPropertySetter(curTag
414: + "/object-pool/client-handler-object-pool/max-idle",
415: "maxIdle");
416: digester.addBeanPropertySetter(curTag
417: + "/object-pool/client-handler-object-pool/init-size",
418: "initSize");
419: digester.addSetNext(curTag
420: + "/object-pool/client-handler-object-pool",
421: "setClientHandlerObjectPoolConfig");
422: //</client-handler-object-pool>
423: //<byte-buffer-object-pool>
424: digester.addObjectCreate(curTag
425: + "/object-pool/byte-buffer-object-pool",
426: ByteBufferObjectPoolConfig.class);
427: digester.addBeanPropertySetter(curTag
428: + "/object-pool/byte-buffer-object-pool/max-active",
429: "maxActive");
430: digester.addBeanPropertySetter(curTag
431: + "/object-pool/byte-buffer-object-pool/max-idle",
432: "maxIdle");
433: digester.addBeanPropertySetter(curTag
434: + "/object-pool/byte-buffer-object-pool/init-size",
435: "initSize");
436: digester.addSetNext(curTag
437: + "/object-pool/byte-buffer-object-pool",
438: "setByteBufferObjectPoolConfig");
439: //</byte-buffer-object-pool>
440: //<client-data-object-pool>
441: digester.addObjectCreate(curTag
442: + "/object-pool/client-data-object-pool",
443: ClientDataObjectPoolConfig.class);
444: digester.addBeanPropertySetter(curTag
445: + "/object-pool/client-data-object-pool/max-active",
446: "maxActive");
447: digester.addBeanPropertySetter(curTag
448: + "/object-pool/client-data-object-pool/max-idle",
449: "maxIdle");
450: digester.addBeanPropertySetter(curTag
451: + "/object-pool/client-data-object-pool/init-size",
452: "initSize");
453: digester.addSetNext(curTag
454: + "/object-pool/client-data-object-pool",
455: "setClientDataObjectPoolConfig");
456: //</client-data-object-pool>
457: digester.addSetNext(curTag + "/object-pool",
458: "setObjectPoolConfig");
459: //</object-pool>
460: //<command-shell>
461: digester.addBeanPropertySetter(
462: curTag + "/command-shell/enable", "commandShellEnable");
463: digester.addBeanPropertySetter(curTag
464: + "/command-shell/prompt-name",
465: "commandShellPromptName");
466: //</command-shell>
467: //<communication-logging><enable>
468: digester.addBeanPropertySetter(curTag
469: + "/communication-logging/enable",
470: "communicationLogging");
471: //<access-constraint>
472: digester.addObjectCreate(curTag + "/access-constraint",
473: AccessConstraintConfig.class);
474: //<ip-filter>
475: digester.addObjectCreate(curTag
476: + "/access-constraint/ip-filter", IpFilterConfig.class);
477: digester.addBeanPropertySetter(curTag
478: + "/access-constraint/ip-filter/enable", "enable");
479: digester.addBeanPropertySetter(curTag
480: + "/access-constraint/ip-filter/allow-access",
481: "allowAccess");
482: //<ip-collection>
483: digester
484: .addCallMethod(
485: curTag
486: + "/access-constraint/ip-filter/ip-collection/client-ip-address",
487: "addClientIpAddress", 0);
488: //<ip-collection>
489: digester.addSetNext(curTag + "/access-constraint/ip-filter",
490: "setIpFilterConfig");
491: //<ip-filter>
492: digester.addSetNext(curTag + "/access-constraint",
493: "setAccessConstraintConfig");
494: //</access-constraint>
495: //<server-hooks>
496: digester.addObjectCreate(curTag + "/server-hooks",
497: ServerHooks.class);
498: digester.addCallMethod(curTag + "/server-hooks/class-name",
499: "addClassName", 0);
500: digester.addSetNext(curTag + "/server-hooks", "setServerHooks");
501: //</server-hooks>
502:
503: //<secure>
504: digester.addObjectCreate(curTag + "/secure", Secure.class);
505: digester.addBeanPropertySetter(curTag + "/secure/enable",
506: "enable");
507: digester.addBeanPropertySetter(curTag + "/secure/load", "load");
508: digester.addBeanPropertySetter(curTag + "/secure/port", "port");
509: digester.addBeanPropertySetter(curTag + "/secure/protocol",
510: "protocol");
511: digester.addBeanPropertySetter(curTag
512: + "/secure/client-auth-enable", "clientAuthEnable");
513: //<secure-store>
514: digester.addObjectCreate(curTag + "/secure/secure-store",
515: SecureStore.class);
516: digester.addBeanPropertySetter(curTag
517: + "/secure/secure-store/type", "type");
518: digester.addBeanPropertySetter(curTag
519: + "/secure/secure-store/algorithm", "algorithm");
520: digester.addBeanPropertySetter(curTag
521: + "/secure/secure-store/provider", "provider");
522: //<key-store-info>
523: digester.addObjectCreate(curTag
524: + "/secure/secure-store/key-store-info",
525: KeyStoreInfo.class);
526: digester.addBeanPropertySetter(curTag
527: + "/secure/secure-store/key-store-info/store-file",
528: "storeFile");
529: digester.addBeanPropertySetter(curTag
530: + "/secure/secure-store/key-store-info/store-password",
531: "storePassword");
532: digester.addBeanPropertySetter(curTag
533: + "/secure/secure-store/key-store-info/key-password",
534: "keyPassword");
535: digester.addSetNext(curTag
536: + "/secure/secure-store/key-store-info",
537: "setKeyStoreInfo");
538: //</key-store-info>
539: //<trust-store-info>
540: digester.addObjectCreate(curTag
541: + "/secure/secure-store/trust-store-info",
542: TrustStoreInfo.class);
543: digester.addBeanPropertySetter(curTag
544: + "/secure/secure-store/trust-store-info/store-file",
545: "storeFile");
546: digester
547: .addBeanPropertySetter(
548: curTag
549: + "/secure/secure-store/trust-store-info/store-password",
550: "storePassword");
551: digester.addBeanPropertySetter(curTag
552: + "/secure/secure-store/trust-store-info/type", "type");
553: digester.addBeanPropertySetter(curTag
554: + "/secure/secure-store/trust-store-info/provider",
555: "provider");
556: digester.addSetNext(curTag
557: + "/secure/secure-store/trust-store-info",
558: "setTrustStoreInfo");
559: //</trust-store-info>
560: digester.addBeanPropertySetter(curTag
561: + "/secure/secure-store/secure-store-manager",
562: "secureStoreManager");
563: digester.addSetNext(curTag + "/secure/secure-store",
564: "setSecureStore");
565: //</secure-store>
566: digester.addSetNext(curTag + "/secure", "setSecure");
567: //</secure>
568: digester.addBeanPropertySetter(curTag + "/command-plugin",
569: "commandPlugin");
570: //<advanced-settings>
571: digester.addObjectCreate(curTag + "/advanced-settings",
572: AdvancedSettings.class);
573: digester.addBeanPropertySetter(curTag
574: + "/advanced-settings/charset", "charset");
575: digester.addBeanPropertySetter(curTag
576: + "/advanced-settings/byte-buffer-size",
577: "byteBufferSize");
578: digester.addBeanPropertySetter(curTag
579: + "/advanced-settings/backlog", "backlog");
580: digester.addBeanPropertySetter(curTag
581: + "/advanced-settings/use-direct-byte-buffer",
582: "useDirectByteBuffer");
583: digester.addBeanPropertySetter(curTag
584: + "/advanced-settings/socket-linger", "socketLinger");
585: digester.addBeanPropertySetter(curTag
586: + "/advanced-settings/debug-non-blocking-mode",
587: "debugNonBlockingMode");
588: digester.addBeanPropertySetter(curTag
589: + "/advanced-settings/client-identifier",
590: "clientIdentifier");
591: digester.addBeanPropertySetter(curTag
592: + "/advanced-settings/qsobject-pool-maker",
593: "qSObjectPoolMaker");
594: digester.addBeanPropertySetter(curTag
595: + "/advanced-settings/max-threads-for-nio-write",
596: "maxThreadsForNioWrite");
597: digester.addSetNext(curTag + "/advanced-settings",
598: "setAdvancedSettings");
599: //</advanced-settings>
600: digester.addSetNext(curTag, "setQSAdminServerConfig");
601: //</qsadmin-server>
602:
603: //<db-object-pool>
604: subTag = "db-object-pool";
605: digester.addObjectCreate(mainTag + "/" + subTag,
606: DBObjectPoolConfig.class);
607: //<database-connection-set>
608: digester.addObjectCreate(mainTag + "/" + subTag
609: + "/database-connection-set",
610: DatabaseConnectionSet.class);
611: //<database-connection>
612: curTag = mainTag + "/" + subTag
613: + "/database-connection-set/database-connection";
614: digester
615: .addObjectCreate(curTag, DatabaseConnectionConfig.class);
616: digester.addBeanPropertySetter(curTag + "/id", "id");
617: digester.addBeanPropertySetter(curTag + "/driver", "driver");
618: digester.addBeanPropertySetter(curTag + "/url", "url");
619: digester
620: .addBeanPropertySetter(curTag + "/username", "username");
621: digester
622: .addBeanPropertySetter(curTag + "/password", "password");
623: digester.addSetNext(curTag, "addDatabaseConnection");
624: //</database-connection>
625: digester.addSetNext(mainTag + "/" + subTag
626: + "/database-connection-set",
627: "setDatabaseConnectionSet");
628: //</database-connection-set>
629: //<db-pool-util>
630: curTag = mainTag + "/" + subTag + "/db-pool-util";
631: digester.addBeanPropertySetter(curTag, "dbPoolUtil");
632: //</db-pool-util>
633: digester.addSetNext(mainTag + "/" + subTag,
634: "setDBObjectPoolConfig");
635: //</db-object-pool>
636:
637: //<application-configuration>
638: subTag = "application-configuration";
639: digester.addObjectCreate(mainTag + "/" + subTag,
640: ApplicationConfiguration.class);
641: digester.addBeanPropertySetter(mainTag + "/" + subTag
642: + "/prompt-type", "promptType");
643: curTag = mainTag + "/" + subTag + "/" + "property";
644: digester.addObjectCreate(curTag, Property.class);
645: digester.addBeanPropertySetter(curTag + "/property-name",
646: "name");
647: digester.addBeanPropertySetter(curTag + "/property-value",
648: "value");
649: digester.addSetNext(curTag, "addProperty");
650: digester.addSetNext(mainTag + "/" + subTag,
651: "setApplicationConfiguration");
652: //</application-configuration>
653:
654: //<init-server-hooks>
655: subTag = "init-server-hooks";
656: digester.addObjectCreate(mainTag + "/" + subTag,
657: InitServerHooks.class);
658: digester.addCallMethod(mainTag + "/" + subTag + "/class-name",
659: "addClassName", 0);
660: digester.addSetNext(mainTag + "/" + subTag,
661: "setInitServerHooks");
662: //</init-server-hooks>
663:
664: logger.fine("Loading config from xml file : "
665: + input.getAbsolutePath());
666: QuickServerConfig qsc = (QuickServerConfig) digester
667: .parse(input);
668: qsc.setConfigFile(input.getAbsolutePath());
669:
670: loadMissingApplicationConfiguration(qsc);
671:
672: QuickServer.setDebugNonBlockingMode(qsc.getAdvancedSettings()
673: .getDebugNonBlockingMode());
674:
675: return qsc;
676: }
677:
678: private static void loadMissingApplicationConfiguration(
679: QuickServerConfig qsc) throws IOException {
680: ApplicationConfiguration ac = qsc.getApplicationConfiguration();
681: if (ac == null)
682: return;
683:
684: //check if any application-configuration had missing property-value
685: Set propertyNames = ac.keySet();
686: Iterator iterator = propertyNames.iterator();
687: String key = null;
688: Object value = null;
689: char sv[] = null;
690: SensitiveInput sensitiveInput = null;
691: boolean guiPrompt = ac.getPromptType().equals("console") == false ? true
692: : false;
693:
694: while (iterator.hasNext()) {
695: key = (String) iterator.next();
696: value = ac.get(key);
697: if (value == null) {
698: if (guiPrompt && sensitiveInput == null) {
699: sensitiveInput = new SensitiveInput(qsc.getName()
700: + " - Input Prompt");
701: }
702:
703: if (guiPrompt)
704: sv = sensitiveInput.getInput(key);
705: else
706: sv = PasswordField
707: .getPassword("Input property value for "
708: + key + " : ");
709:
710: if (sv != null) {
711: value = new String(sv);
712: ac.put(key, value);
713: }
714: value = null;
715: }
716: }
717: }
718:
719: /**
720: * Make the file passed absolute, relative to the location of
721: * configuration file that loaded QuickServerConfig object passed.
722: * @since 1.4
723: */
724: public static File makeAbsoluteToConfig(String fileName,
725: QuickServerConfig config) {
726: File file = new File(fileName);
727: if (config == null)
728: return file;
729: if (file.isAbsolute() == false) {
730: String temp = config.getConfigFile();
731: file = new File(temp);
732: temp = file.getParent() + File.separatorChar + fileName;
733: file = new File(temp);
734: }
735: return file;
736: }
737: }
|