001: /*
002: * This file is part of the QuickServer library
003: * Copyright (C) 2003-2005 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.quickserver.net.server.*;
018:
019: /**
020: * This class encapsulate the basic configuration of QuickServer.
021: * @author Akshathkumar Shetty
022: * @since 1.2
023: * @see org.quickserver.util.xmlreader.QuickServerConfig
024: * @see org.quickserver.util.xmlreader.QSAdminServerConfig
025: */
026: public class BasicServerConfig implements java.io.Serializable {
027:
028: private String clientAuthenticationHandler; //v1.4.6
029: private String clientEventHandler; //v1.4.6
030: private String clientExtendedEventHandler; //v1.4.6
031: private String clientCommandHandler;
032: private String clientObjectHandler;
033: private String clientBinaryHandler;
034: private String clientData;
035: private String clientWriteHandler; //v1.4.5
036:
037: private String serverBanner;
038: private String name = null;
039: private String maxConnectionMsg = "-ERR Server Busy. Max Connection Reached";
040: private String timeoutMsg = "-ERR Timeout";
041: private int maxAuthTry = 5;
042: private String maxAuthTryMsg = "-ERR Max Auth Try Reached";
043: private int port = 9876;
044: private String bindAddr;
045: private long maxConnection = -1;
046: private int timeout = 1 * 60 * 1000; //1 min. socket timeout
047:
048: private String consoleLoggingLevel = "INFO";
049: private String consoleLoggingFormatter;
050:
051: //for object pool
052: private ObjectPoolConfig objectPoolConfig = new ObjectPoolConfig();
053: private boolean communicationLogging = false;
054:
055: //v1.3.3
056: private AccessConstraintConfig accessConstraintConfig;
057: private ServerHooks serverHooks;
058:
059: //v1.4.0
060: private Secure secure = new Secure();
061: private ServerMode serverMode = new ServerMode();
062:
063: //v1.4.5
064: private AdvancedSettings advancedSettings = new AdvancedSettings();
065:
066: //v1.4.6
067: private DefaultDataMode defaultDataMode = new DefaultDataMode();
068:
069: /**
070: * Returns the name of the QuickServer
071: * @see #setName
072: */
073: public String getName() {
074: return name;
075: }
076:
077: /**
078: * Sets the name for the QuickServer.
079: * XML Tag: <name></name>
080: * @param name for the QuickServer
081: * @see #getName
082: */
083: public void setName(String name) {
084: if (name != null && name.equals("") == false)
085: this .name = name;
086: }
087:
088: /**
089: * Returns the Server Banner of the QuickServer
090: * @see #setServerBanner
091: */
092: public String getServerBanner() {
093: return serverBanner;
094: }
095:
096: /**
097: * Sets the serverBanner for the QuickServer
098: * that will be displayed on the standard output [console]
099: * when server starts. <br> <br>
100: * To set welcome message to your client
101: * {@link org.quickserver.net.server.ClientEventHandler#gotConnected}
102: * XML Tag: <server-banner></server-banner>
103: * @param banner for the QuickServer
104: * @see #getServerBanner
105: */
106: public void setServerBanner(String banner) {
107: if (banner != null && banner.equals("") == false)
108: serverBanner = banner;
109: }
110:
111: /**
112: * Sets the port for the QuickServer to listen on.
113: * If not set, it will run on Port 9876<br/>
114: * XML Tag: <port></port>
115: * @param port to listen on.
116: * @see #getPort
117: */
118: public void setPort(int port) {
119: if (port >= 0)
120: this .port = port;
121: }
122:
123: /**
124: * Returns the port for the QuickServer
125: * @see #setPort
126: */
127: public int getPort() {
128: return port;
129: }
130:
131: /**
132: * Sets the ClientCommandHandler class that interacts with
133: * client sockets.
134: * XML Tag: <client-command-handler></client-command-handler>
135: * @param handler the fully qualified name of the class that
136: * implements {@link org.quickserver.net.server.ClientCommandHandler}
137: * @see #getClientCommandHandler
138: */
139: public void setClientCommandHandler(String handler) {
140: if (handler != null && handler.equals("") == false)
141: clientCommandHandler = handler;
142: }
143:
144: /**
145: * Sets the ClientCommandHandler class that interacts with
146: * client sockets.
147: * @since 1.4.6
148: */
149: public void setClientCommandHandler(ClientCommandHandler handler) {
150: if (handler != null)
151: clientCommandHandler = handler.getClass().getName();
152: }
153:
154: /**
155: * Returns the ClientCommandHandler class that interacts with
156: * client sockets.
157: * @see #setClientCommandHandler
158: */
159: public String getClientCommandHandler() {
160: return clientCommandHandler;
161: }
162:
163: /**
164: * Sets the ClientEventHandler class that gets notified of
165: * client events.
166: * XML Tag: <client-event-handler></client-event-handler>
167: * @param handler the fully qualified name of the class that
168: * implements {@link org.quickserver.net.server.ClientEventHandler}
169: * @see #getClientEventHandler
170: * @since 1.4.6
171: */
172: public void setClientEventHandler(String handler) {
173: if (handler != null && handler.equals("") == false)
174: clientEventHandler = handler;
175: }
176:
177: /**
178: * Sets the ClientEventHandler class that gets notified of
179: * client events.
180: * @since 1.4.6
181: */
182: public void setClientEventHandler(ClientEventHandler handler) {
183: if (handler != null)
184: clientEventHandler = handler.getClass().getName();
185: }
186:
187: /**
188: * Returns the ClientEventHandler class that gets notified of
189: * client events.
190: * @see #setClientEventHandler
191: * @since 1.4.6
192: */
193: public String getClientEventHandler() {
194: return clientEventHandler;
195: }
196:
197: /**
198: * Sets the ClientExtendedEventHandler class that gets notified of
199: * client's extended events.
200: * XML Tag: <client-extended-event-handler></client-extended-event-handler>
201: * @param handler the fully qualified name of the class that
202: * implements {@link org.quickserver.net.server.ClientExtendedEventHandler}
203: * @see #getClientExtendedEventHandler
204: * @since 1.4.6
205: */
206: public void setClientExtendedEventHandler(String handler) {
207: if (handler != null && handler.equals("") == false)
208: clientExtendedEventHandler = handler;
209: }
210:
211: /**
212: * Sets the ClientExtendedEventHandler class that gets notified of
213: * client's extended events.
214: * @since 1.4.6
215: */
216: public void setClientExtendedEventHandler(
217: ClientExtendedEventHandler handler) {
218: if (handler != null)
219: clientExtendedEventHandler = handler.getClass().getName();
220: }
221:
222: /**
223: * Returns the ClientExtendedEventHandler class that gets notified of
224: * client's extended events.
225: * @see #setClientExtendedEventHandler
226: * @since 1.4.6
227: */
228: public String getClientExtendedEventHandler() {
229: return clientExtendedEventHandler;
230: }
231:
232: /**
233: * Sets the Authenticator class that handles the
234: * authentication of the client.
235: * XML Tag: <authenticator></authenticator>
236: * @param authenticator the fully qualified name of the class
237: * that implements {@link org.quickserver.net.server.Authenticator}.
238: * @see #getAuthenticator
239: * @since 1.3
240: */
241: public void setAuthenticator(String authenticator) {
242: if (authenticator != null && authenticator.equals("") == false)
243: this .clientAuthenticationHandler = authenticator;
244: }
245:
246: /**
247: * Sets the Authenticator class that handles the
248: * authentication of the client.
249: * @since 1.4.6
250: */
251: public void setAuthenticator(Authenticator authenticator) {
252: if (authenticator != null)
253: this .clientAuthenticationHandler = authenticator.getClass()
254: .getName();
255: }
256:
257: /**
258: * Returns the Authenticator class that handles the
259: * authentication of the client.
260: * @see #setAuthenticator
261: * @since 1.3
262: */
263: public String getAuthenticator() {
264: return clientAuthenticationHandler;
265: }
266:
267: /**
268: * Sets the ClientAuthenticationHandler class that handles the
269: * authentication of the client.
270: * XML Tag: <client-authentication-handler></client-authentication-handler>
271: * @param clientAuthenticationHandler the fully qualified name of the class
272: * that implements {@link org.quickserver.net.server.ClientAuthenticationHandler}.
273: * @see #getClientAuthenticationHandler
274: * @since 1.4.6
275: */
276: public void setClientAuthenticationHandler(
277: String clientAuthenticationHandler) {
278: if (clientAuthenticationHandler != null
279: && clientAuthenticationHandler.equals("") == false)
280: this .clientAuthenticationHandler = clientAuthenticationHandler;
281: }
282:
283: /**
284: * Sets the ClientAuthenticationHandler class that handles the
285: * authentication of the client.
286: * @since 1.4.6
287: */
288: public void setClientAuthenticationHandler(
289: ClientAuthenticationHandler clientAuthenticationHandler) {
290: if (clientAuthenticationHandler != null)
291: this .clientAuthenticationHandler = clientAuthenticationHandler
292: .getClass().getName();
293: }
294:
295: /**
296: * Returns the ClientAuthenticationHandler class that handles the
297: * authentication of the client.
298: * @see #setClientAuthenticationHandler
299: * @since 1.4.6
300: */
301: public String getClientAuthenticationHandler() {
302: return clientAuthenticationHandler;
303: }
304:
305: /**
306: * Sets the ClientData class that carries client data.
307: * XML Tag: <client-data></client-data>
308: * @param data the fully qualified name of the class that
309: * extends {@link org.quickserver.net.server.ClientData}.
310: * @see #getClientData
311: */
312: public void setClientData(String data) {
313: if (data != null && data.equals("") == false)
314: this .clientData = data;
315: }
316:
317: /**
318: * Sets the ClientData class that carries client data.
319: * @since 1.4.6
320: */
321: public void setClientData(ClientData data) {
322: if (data != null)
323: this .clientData = data.getClass().getName();
324: }
325:
326: /**
327: * Returns the ClientData class string that carries client data
328: * @return the fully qualified name of the class that
329: * implements {@link org.quickserver.net.server.ClientData}.
330: * @see #setClientData
331: */
332: public String getClientData() {
333: return clientData;
334: }
335:
336: /**
337: * Sets the Client Socket timeout in milliseconds.
338: * XML Tag: <timeout></timeout>
339: * @param time client socket timeout in milliseconds.
340: * @see #getTimeout
341: */
342: public void setTimeout(int time) {
343: timeout = time;
344: }
345:
346: /**
347: * Returns the Client Socket timeout in milliseconds.
348: * @see #setTimeout
349: */
350: public int getTimeout() {
351: return timeout;
352: }
353:
354: /**
355: * Sets maximum allowed login attempts.
356: * XML Tag: <max-auth-try></max-auth-try>
357: */
358: public void setMaxAuthTry(int authTry) {
359: maxAuthTry = authTry;
360: }
361:
362: /**
363: * Returns maximum allowed login attempts.
364: * Default is : 5
365: */
366: public int getMaxAuthTry() {
367: return maxAuthTry;
368: }
369:
370: /**
371: * Sets message to be displayed when maximum allowed login
372: * attempts has reached.
373: * Default is : -ERR Max Auth Try Reached<br/>
374: * XML Tag: <max-auth-try-msg></max-auth-try-msg>
375: * @see #getMaxAuthTryMsg
376: */
377: public void setMaxAuthTryMsg(String msg) {
378: if (msg != null && msg.equals("") == false)
379: maxAuthTryMsg = msg;
380: }
381:
382: /**
383: * Returns message to be displayed when maximum allowed login
384: * attempts has reached.
385: * @see #getMaxAuthTryMsg
386: */
387: public String getMaxAuthTryMsg() {
388: return maxAuthTryMsg;
389: }
390:
391: /**
392: * Sets timeout message.
393: * Default is : -ERR Timeout<br/>
394: * XML Tag: <timeout-msg></timeout-msg>
395: * @see #getTimeoutMsg
396: */
397: public void setTimeoutMsg(String msg) {
398: if (msg != null && msg.equals("") == false)
399: timeoutMsg = msg;
400: }
401:
402: /**
403: * Returns timeout message.
404: * @see #setTimeoutMsg
405: */
406: public String getTimeoutMsg() {
407: return timeoutMsg;
408: }
409:
410: /**
411: * Sets the maximum number of client connection allowed..
412: * XML Tag: <max-connection></max-connection>
413: * @see #getMaxConnection
414: */
415: public void setMaxConnection(long maxConnection) {
416: this .maxConnection = maxConnection;
417: }
418:
419: /**
420: * Returns the maximum number of client connection allowed.
421: * @see #setMaxConnection
422: */
423: public long getMaxConnection() {
424: return maxConnection;
425: }
426:
427: /**
428: * Sets the message to be sent to any new client connected after
429: * maximum client connection has reached.
430: * Default is : <code>-ERR Server Busy. Max Connection Reached</code><br/>
431: * XML Tag: <max-connection-msg></max-connection-msg>
432: * @see #getMaxConnectionMsg
433: */
434: public void setMaxConnectionMsg(String maxConnectionMsg) {
435: if (maxConnectionMsg != null
436: && maxConnectionMsg.equals("") == false)
437: this .maxConnectionMsg = maxConnectionMsg;
438: }
439:
440: /**
441: * Returns the message to be sent to any new client connected
442: * after maximum client connection has reached.
443: * @see #setMaxConnectionMsg
444: */
445: public String getMaxConnectionMsg() {
446: return maxConnectionMsg;
447: }
448:
449: /**
450: * Sets the Ip address to bind to.
451: * @param bindAddr argument can be used on a multi-homed host for a
452: * QuickServer that will only accept connect requests to one
453: * of its addresses. If not set, it will default accepting
454: * connections on any/all local addresses.
455: * XML Tag: <bind-address></bind-address>
456: * @see #getBindAddr
457: */
458: public void setBindAddr(String bindAddr) {
459: if (bindAddr != null && bindAddr.equals("") == false)
460: this .bindAddr = bindAddr;
461: }
462:
463: /**
464: * Returns the Ip address binding to.
465: * @see #setBindAddr
466: */
467: public String getBindAddr() {
468: return bindAddr;
469: }
470:
471: /**
472: * Sets the ClientObjectHandler class that interacts with
473: * client sockets.
474: * XML Tag: <client-object-handler></client-object-handler>
475: * @param handler object the fully qualified name of the class that
476: * implements {@link org.quickserver.net.server.ClientObjectHandler}
477: * @see #getClientObjectHandler
478: */
479: public void setClientObjectHandler(String handler) {
480: if (handler != null && handler.equals("") == false)
481: clientObjectHandler = handler;
482: }
483:
484: /**
485: * Sets the ClientObjectHandler class that interacts with
486: * client sockets.
487: * @since 1.4.6
488: */
489: public void setClientObjectHandler(ClientObjectHandler handler) {
490: if (handler != null)
491: clientObjectHandler = handler.getClass().getName();
492: }
493:
494: /**
495: * Returns the ClientObjectHandler class that interacts with
496: * client sockets.
497: * @see #setClientObjectHandler
498: */
499: public String getClientObjectHandler() {
500: return clientObjectHandler;
501: }
502:
503: /**
504: * Sets the console log handler level.
505: * XML Tag: <console-logging-level></console-logging-level>
506: * @param level like INFO, FINE, CONFIG
507: */
508: public void setConsoleLoggingLevel(String level) {
509: if (level != null && level.equals("") == false)
510: consoleLoggingLevel = level;
511: }
512:
513: /**
514: * Returns the console log handler level.
515: */
516: public String getConsoleLoggingLevel() {
517: return consoleLoggingLevel;
518: }
519:
520: /**
521: * Sets the console log handler formatter.
522: * XML Tag: <console-logging-formatter></console-logging-formatter>
523: * @param formatter fully qualified name of the class that
524: * implements {@link java.util.logging.Formatter}
525: */
526: public void setConsoleLoggingFormatter(String formatter) {
527: if (formatter != null && formatter.equals("") == false)
528: consoleLoggingFormatter = formatter;
529: }
530:
531: /**
532: * Returns the console log handler level.
533: */
534: public String getConsoleLoggingFormatter() {
535: return consoleLoggingFormatter;
536: }
537:
538: /**
539: * Sets the ObjectPool Config object.
540: * XML Tag: <object-pool></object-pool>
541: */
542: public void setObjectPoolConfig(ObjectPoolConfig objectPoolConfig) {
543: if (objectPoolConfig != null)
544: this .objectPoolConfig = objectPoolConfig;
545: }
546:
547: /**
548: * Returns the ObjectPool Config object.
549: */
550: public ObjectPoolConfig getObjectPoolConfig() {
551: return objectPoolConfig;
552: }
553:
554: /**
555: * Sets the communication logging flag.
556: * @see #getCommunicationLogging
557: * XML Tag: <communication-logging><enable>true</enable></communication-logging>
558: * Allowed values = <code>true</code> | <code>false</code>
559: * @since 1.3.2
560: */
561: public void setCommunicationLogging(boolean enable) {
562: this .communicationLogging = enable;
563: }
564:
565: /**
566: * Returns the communication logging flag.
567: * @see #setCommunicationLogging
568: * @since 1.3.2
569: */
570: public boolean getCommunicationLogging() {
571: return communicationLogging;
572: }
573:
574: /**
575: * Sets the Access constraints
576: * @since 1.3.3
577: */
578: public void setAccessConstraintConfig(
579: AccessConstraintConfig accessConstraintConfig) {
580: this .accessConstraintConfig = accessConstraintConfig;
581: }
582:
583: /**
584: * Returns Access constraints if present else <code>null</code>.
585: * @since 1.3.3
586: */
587: public AccessConstraintConfig getAccessConstraintConfig() {
588: return accessConstraintConfig;
589: }
590:
591: /**
592: * Sets the ServerHooks
593: * @since 1.3.3
594: */
595: public void setServerHooks(ServerHooks serverHooks) {
596: this .serverHooks = serverHooks;
597: }
598:
599: /**
600: * Returns ServerHooks if present else <code>null</code>.
601: * @since 1.3.3
602: */
603: public ServerHooks getServerHooks() {
604: return serverHooks;
605: }
606:
607: /**
608: * Sets the Secure setting for QuickServer
609: * @since 1.4.0
610: */
611: public void setSecure(Secure secure) {
612: this .secure = secure;
613: }
614:
615: /**
616: * Returns Secure setting for QuickServer
617: * @since 1.4.0
618: */
619: public Secure getSecure() {
620: return secure;
621: }
622:
623: /**
624: * Sets the ClientBinaryHandler class that interacts with
625: * client sockets.
626: * XML Tag: <client-binary-handler></client-binary-handler>
627: * @param handler the fully qualified name of the class that
628: * implements {@link org.quickserver.net.server.ClientBinaryHandler}
629: * @see #getClientBinaryHandler
630: */
631: public void setClientBinaryHandler(String handler) {
632: if (handler != null && handler.equals("") == false)
633: clientBinaryHandler = handler;
634: }
635:
636: /**
637: * Sets the ClientBinaryHandler class that interacts with
638: * client sockets.
639: * @since 1.4.6
640: */
641: public void setClientBinaryHandler(ClientBinaryHandler handler) {
642: if (handler != null)
643: clientBinaryHandler = handler.getClass().getName();
644: }
645:
646: /**
647: * Returns the ClientBinaryHandler class that interacts with
648: * client sockets.
649: * @see #setClientBinaryHandler
650: */
651: public String getClientBinaryHandler() {
652: return clientBinaryHandler;
653: }
654:
655: /**
656: * Sets the ServerMode for the QuickServer.
657: * @param serverMode ServerMode object.
658: * @see #getServerMode
659: * @since 1.4.5
660: */
661: public void setServerMode(ServerMode serverMode) {
662: if (serverMode == null)
663: serverMode = new ServerMode();
664: this .serverMode = serverMode;
665: }
666:
667: /**
668: * Returns the ServerMode for the QuickServer.
669: * @see #setServerMode
670: * @since 1.4.5
671: */
672: public ServerMode getServerMode() {
673: return serverMode;
674: }
675:
676: /**
677: * Sets the ClientWriteHandler class that interacts with
678: * client sockets.
679: * XML Tag: <client-write-handler></client-write-handler>
680: * @param handler the fully qualified name of the class that
681: * implements {@link org.quickserver.net.server.ClientWriteHandler}
682: * @see #getClientWriteHandler
683: * @since 1.4.5
684: */
685: public void setClientWriteHandler(String handler) {
686: if (handler != null && handler.equals("") == false)
687: clientWriteHandler = handler;
688: }
689:
690: /**
691: * Sets the ClientWriteHandler class that interacts with
692: * client sockets.
693: * @since 1.4.6
694: */
695: public void setClientWriteHandler(ClientWriteHandler handler) {
696: if (handler != null)
697: clientWriteHandler = handler.getClass().getName();
698: }
699:
700: /**
701: * Returns the ClientWriteHandler class that interacts with
702: * client sockets.
703: * @see #setClientWriteHandler
704: */
705: public String getClientWriteHandler() {
706: return clientWriteHandler;
707: }
708:
709: /**
710: * Sets the AdvancedSettings for the QuickServer.
711: * @param advancedSettings AdvancedSettings object.
712: * @see #getAdvancedSettings
713: * @since 1.4.5
714: */
715: public void setAdvancedSettings(AdvancedSettings advancedSettings) {
716: this .advancedSettings = advancedSettings;
717: }
718:
719: /**
720: * Returns the AdvancedSettings for the QuickServer.
721: * @see #setAdvancedSettings
722: * @since 1.4.5
723: */
724: public AdvancedSettings getAdvancedSettings() {
725: if (advancedSettings == null)
726: advancedSettings = new AdvancedSettings();
727: return advancedSettings;
728: }
729:
730: /**
731: * Sets the DefaultDataMode for the QuickServer.
732: * @param defaultDataMode DefaultDataMode object.
733: * @see #getDefaultDataMode
734: * @since 1.4.6
735: */
736: public void setDefaultDataMode(DefaultDataMode defaultDataMode) {
737: this .defaultDataMode = defaultDataMode;
738: }
739:
740: /**
741: * Returns the DefaultDataMode for the QuickServer.
742: * @see #setDefaultDataMode
743: * @since 1.4.6
744: */
745: public DefaultDataMode getDefaultDataMode() {
746: if (defaultDataMode == null)
747: defaultDataMode = new DefaultDataMode();
748: return defaultDataMode;
749: }
750: }
|