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.QuickServer;
018: import org.quickserver.net.qsadmin.QSAdminServer;
019:
020: /**
021: * This class encapsulate the configuration of QSAdminServer.
022: * This class is used by
023: * {@link org.quickserver.net.server.QuickServer#configQuickServer}
024: * and {@link org.quickserver.net.server.QuickServer#initService} method to
025: * initialise QSAdminServer.
026: * @author Akshathkumar Shetty
027: * @since 1.2
028: */
029: public class QSAdminServerConfig extends BasicServerConfig {
030:
031: private String commandPlugin;
032: private String commandShellEnabled = "false";
033: private String commandShellPromptName = "QSAdmin";
034:
035: public QSAdminServerConfig() {
036: setName("QSAdminServer v " + QSAdminServer.getVersion());
037: setPort(9877);
038: setBindAddr("127.0.0.1");
039: setClientCommandHandler("org.quickserver.net.qsadmin.CommandHandler");
040: setClientEventHandler("org.quickserver.net.qsadmin.CommandHandler");
041: setClientAuthenticationHandler("org.quickserver.net.qsadmin.Authenticator");
042: setClientData("org.quickserver.net.qsadmin.Data");
043: setMaxConnection(1);
044: getServerMode().setBlocking(false);
045: }
046:
047: /**
048: * Set the CommandPlugin for QSAdminServer class which plugs in into
049: * CommandHandler of QsAdminServer,it will be null if not set.
050: * XML Tag: <command-plugin></command-plugin>
051: */
052: public void setCommandPlugin(String plugin) {
053: if (plugin != null && plugin.equals("") == false)
054: commandPlugin = plugin;
055: }
056:
057: /**
058: * Gets the CommandPlugin for QSAdminServer class which plugsin into
059: * CommandHandler of QsAdminServer,it will be null if not set.
060: */
061: public String getCommandPlugin() {
062: return commandPlugin;
063: }
064:
065: /**
066: * Set the CommandShellEnable flag for QSAdminServer
067: * XML Tag: <command-shell><enable>true</enable></command-shell>
068: * Allowed values = <code>true</code> | <code>false</code>
069: * @since 1.3.2
070: */
071: public void setCommandShellEnable(String enable) {
072: if (enable != null && enable.equals("") == false)
073: commandShellEnabled = enable;
074: }
075:
076: /**
077: * Gets the CommandShellEnable flag for QSAdminServer
078: * @since 1.3.2
079: */
080: public String getCommandShellEnable() {
081: return commandShellEnabled;
082: }
083:
084: /**
085: * Set the PromptName for QSAdminShell
086: * XML Tag: <command-shell><prompt-name>true</prompt-name></command-shell>
087: * Default values = <code>QSAdmin</code>
088: * @since 1.3.2
089: */
090: public void setCommandShellPromptName(String commandShellPromptName) {
091: if (commandShellPromptName != null
092: && commandShellPromptName.equals("") == false)
093: this .commandShellPromptName = commandShellPromptName;
094: }
095:
096: /**
097: * Gets the PromptName for QSAdminShell
098: * @since 1.3.2
099: */
100: public String getCommandShellPromptName() {
101: return commandShellPromptName;
102: }
103:
104: /**
105: * Returns XML config of this class.
106: * @since 1.3
107: */
108: public String toXML(String pad) {
109: if (pad == null)
110: pad = "";
111:
112: StringBuffer sb = new StringBuffer();
113: sb.append(pad + "<qsadmin-server>\n");
114:
115: if (getName() != null)
116: sb.append(pad + "\t<name>" + getName() + "</name>\n");
117: if (getServerBanner() != null)
118: sb.append(pad + "\t<server-banner>" + getServerBanner()
119: + "</server-banner>\n");
120: sb.append(pad + "\t<port>" + getPort() + "</port>\n");
121: sb.append(pad + "\t<bind-address>" + getBindAddr()
122: + "</bind-address>\n");
123:
124: sb.append(getServerMode().toXML(pad + "\t"));
125:
126: if (getClientEventHandler() != null)
127: sb.append(pad + "\t<client-event-handler>"
128: + getClientEventHandler()
129: + "</client-event-handler>\n");
130: if (getClientCommandHandler() != null)
131: sb.append(pad + "\t<client-command-handler>"
132: + getClientCommandHandler()
133: + "</client-command-handler>\n");
134: if (getClientObjectHandler() != null)
135: sb.append(pad + "\t<client-object-handler>"
136: + getClientObjectHandler()
137: + "</client-object-handler>\n");
138: if (getClientBinaryHandler() != null)
139: sb.append(pad + "\t<client-binary-handler>"
140: + getClientBinaryHandler()
141: + "</client-binary-handler>\n");
142: if (getClientWriteHandler() != null)
143: sb.append(pad + "\t<client-write-handler>"
144: + getClientWriteHandler()
145: + "</client-write-handler>\n");
146: if (getClientAuthenticationHandler() != null)
147: sb.append(pad + "\t<client-authentication-handler>"
148: + getClientAuthenticationHandler()
149: + "</client-authentication-handler>\n");
150: else if (getAuthenticator() != null)
151: sb.append(pad + "\t<authenticator>" + getAuthenticator()
152: + "</authenticator>\n");
153: if (getClientData() != null)
154: sb.append(pad + "\t<client-data>" + getClientData()
155: + "</client-data>\n");
156: if (getClientExtendedEventHandler() != null)
157: sb.append(pad + "\t<client-extended-event-handler>"
158: + getClientExtendedEventHandler()
159: + "</client-extended-event-handler>\n");
160:
161: sb.append(pad + "\t<timeout>" + getTimeout() + "</timeout>\n");
162: if (getTimeoutMsg() != null)
163: sb.append(pad + "\t<timeout-msg>" + getTimeoutMsg()
164: + "</timeout-msg>\n");
165:
166: sb.append(pad + "\t<max-auth-try>" + getMaxAuthTry()
167: + "</max-auth-try>\n");
168: if (getMaxAuthTryMsg() != null)
169: sb.append(pad + "\t<max-auth-try-msg>" + getMaxAuthTryMsg()
170: + "</max-auth-try-msg>\n");
171:
172: sb.append(pad + "\t<max-connection>" + getMaxConnection()
173: + "</max-connection>\n");
174: if (getMaxConnectionMsg() != null)
175: sb
176: .append(pad + "\t<max-connection-msg>"
177: + getMaxConnectionMsg()
178: + "</max-connection-msg>\n");
179:
180: /*
181: //Not used. Use main QS console logging
182: if(getConsoleLoggingLevel()!=null)
183: sb.append(pad+"\t<console-logging-level>"+getConsoleLoggingLevel()+"</console-logging-level>\n");
184: if(getConsoleLoggingFormatter()!=null)
185: sb.append(pad+"\t<console-logging-formatter>"+getConsoleLoggingFormatter()+"</consoleLoggingFormatter>\n");
186: */
187:
188: sb.append(getObjectPoolConfig().toXML(pad + "\t"));
189:
190: sb.append(pad + "\t<communication-logging>\n");
191: sb.append(pad + "\t\t<enable>" + getCommunicationLogging()
192: + "</enable>\n");
193: sb.append(pad + "\t</communication-logging>\n");
194:
195: if (getCommandPlugin() != null)
196: sb.append(pad + "\t<command-plugin>" + getCommandPlugin()
197: + "</command-plugin>\n");
198:
199: sb.append(pad + "\t<command-shell>\n");
200: sb.append(pad + "\t\t<enable>" + getCommandShellEnable()
201: + "</enable>\n");
202: sb.append(pad + "\t\t<prompt-name>"
203: + getCommandShellPromptName() + "</prompt-name>\n");
204: sb.append(pad + "\t</command-shell>\n");
205:
206: if (getAccessConstraintConfig() != null) {
207: sb.append(getAccessConstraintConfig().toXML(pad + "\t"));
208: }
209:
210: if (getServerHooks() != null) {
211: sb.append(getServerHooks().toXML(pad + "\t"));
212: }
213:
214: sb.append(getSecure().toXML(pad + "\t"));
215: sb.append(getAdvancedSettings().toXML(pad + "\t"));
216:
217: sb.append(pad + "</qsadmin-server>\n");
218: return sb.toString();
219: }
220:
221: public String toString() {
222: return toXML(null);
223: }
224: }
|