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:
019: /**
020: * This class encapsulate the configuration of QuickServer.
021: * <p>
022: * This is used by {@link QuickServer#configQuickServer} and
023: * {@link QuickServer#initService} method to initialise
024: * QuickServer.
025: * </p>
026: * @author Akshathkumar Shetty
027: * @since 1.2
028: */
029: public class QuickServerConfig extends BasicServerConfig {
030:
031: private QSAdminServerConfig qSAdminServerConfig;
032: private DBObjectPoolConfig dDObjectPoolConfig;
033: private ApplicationConfiguration applicationConfiguration;
034: private InitServerHooks initServerHooks;
035:
036: private String securityManagerClass = null;
037: private String configFile = null;
038: private String applicationJarPath = null;
039:
040: public QuickServerConfig() {
041: setName("QuickServer v" + QuickServer.getVersion());
042: }
043:
044: /**
045: * Sets the QSAdminServer configuration.
046: * XML Tag: <qsadmin-server></qsadmin-server>
047: */
048: public void setQSAdminServerConfig(QSAdminServerConfig config) {
049: qSAdminServerConfig = config;
050: }
051:
052: /**
053: * Returns QSAdminServer configuration.
054: */
055: public QSAdminServerConfig getQSAdminServerConfig() {
056: return qSAdminServerConfig;
057: }
058:
059: /**
060: * Sets the DBObjectPoolConfig
061: * XML Tag: <object-pool></object-pool>
062: * @since 1.3
063: */
064: public void setDBObjectPoolConfig(
065: DBObjectPoolConfig dDObjectPoolConfig) {
066: this .dDObjectPoolConfig = dDObjectPoolConfig;
067: }
068:
069: /**
070: * Returns DBObjectPoolConfig
071: * @since 1.3
072: */
073: public DBObjectPoolConfig getDBObjectPoolConfig() {
074: return dDObjectPoolConfig;
075: }
076:
077: /**
078: * Sets the Application Configuration. This can be used by application to
079: * store its configuration information.
080: * XML Tag: <application-configuration></application-configuration>
081: * @since 1.3.2
082: */
083: public void setApplicationConfiguration(
084: ApplicationConfiguration applicationConfiguration) {
085: this .applicationConfiguration = applicationConfiguration;
086: }
087:
088: /**
089: * Returns ApplicationConfiguration
090: * @since 1.3.2
091: */
092: public ApplicationConfiguration getApplicationConfiguration() {
093: return applicationConfiguration;
094: }
095:
096: /**
097: * Sets the SecurityManager class
098: * XML Tag: <security-manager-class></security-manager-class>
099: * @param securityManagerClass className the fully qualified name of the
100: * class that extends {@link java.lang.SecurityManager}.
101: * @see #getSecurityManagerClass
102: * @since 1.3.3
103: */
104: public void setSecurityManagerClass(String securityManagerClass) {
105: if (securityManagerClass != null)
106: this .securityManagerClass = securityManagerClass;
107: }
108:
109: /**
110: * Returns the SecurityManager class
111: * @see #setSecurityManagerClass
112: * @since 1.3.3
113: */
114: public String getSecurityManagerClass() {
115: return securityManagerClass;
116: }
117:
118: /**
119: * Sets the file path of the file that loaded the config from.
120: * @since 1.3.3
121: */
122: protected void setConfigFile(String fileName) {
123: configFile = fileName;
124: }
125:
126: /**
127: * Returns the file path of the file that loaded the configuration file.
128: * @since 1.3.3
129: */
130: public String getConfigFile() {
131: return configFile;
132: }
133:
134: /**
135: * Sets the applications jar/s path. This can be either absolute or
136: * relative(to config file) path to the jar file or the directory containing the jars
137: * needed by the application.
138: * @see #getApplicationJarPath
139: * @since 1.3.3
140: */
141: public void setApplicationJarPath(String applicationJarPath) {
142: this .applicationJarPath = applicationJarPath;
143: }
144:
145: /**
146: * Returns the applications jar/s path. This can be either absolute or
147: * relative(to config file) path to the jar file or the directory containing the jars
148: * needed by the application.
149: * @see #setApplicationJarPath
150: * @since 1.3.3
151: */
152: public String getApplicationJarPath() {
153: return applicationJarPath;
154: }
155:
156: /**
157: * Sets the InitServerHooks.
158: * @see #getInitServerHooks
159: * @since 1.4
160: */
161: public void setInitServerHooks(InitServerHooks initServerHooks) {
162: this .initServerHooks = initServerHooks;
163: }
164:
165: /**
166: * Returns the InitServerHooks.
167: * @see #setInitServerHooks
168: * @since 1.4
169: */
170: public InitServerHooks getInitServerHooks() {
171: return initServerHooks;
172: }
173:
174: /**
175: * Returns XML config of this class.
176: * @since 1.3
177: */
178: public String toXML(String pad) {
179: if (pad == null)
180: pad = "";
181: StringBuffer sb = new StringBuffer();
182: sb.append(pad + "<quickserver>\n");
183:
184: if (getName() != null)
185: sb.append(pad + "\t<name>" + getName() + "</name>\n");
186: if (getServerBanner() != null)
187: sb.append(pad + "\t<server-banner>" + getServerBanner()
188: + "</server-banner>\n");
189: sb.append(pad + "\t<port>" + getPort() + "</port>\n");
190: if (getBindAddr() != null)
191: sb.append(pad + "\t<bind-address>" + getBindAddr()
192: + "</bind-address>\n");
193:
194: sb.append(getServerMode().toXML(pad + "\t"));
195:
196: if (getClientEventHandler() != null)
197: sb.append(pad + "\t<client-event-handler>"
198: + getClientEventHandler()
199: + "</client-event-handler>\n");
200: if (getClientCommandHandler() != null)
201: sb.append(pad + "\t<client-command-handler>"
202: + getClientCommandHandler()
203: + "</client-command-handler>\n");
204: if (getClientObjectHandler() != null)
205: sb.append(pad + "\t<client-object-handler>"
206: + getClientObjectHandler()
207: + "</client-object-handler>\n");
208: if (getClientBinaryHandler() != null)
209: sb.append(pad + "\t<client-binary-handler>"
210: + getClientBinaryHandler()
211: + "</client-binary-handler>\n");
212: if (getClientWriteHandler() != null)
213: sb.append(pad + "\t<client-write-handler>"
214: + getClientWriteHandler()
215: + "</client-write-handler>\n");
216: if (getClientAuthenticationHandler() != null)
217: sb.append(pad + "\t<client-authentication-handler>"
218: + getClientAuthenticationHandler()
219: + "</client-authentication-handler>\n");
220: else if (getAuthenticator() != null)
221: sb.append(pad + "\t<authenticator>" + getAuthenticator()
222: + "</authenticator>\n");
223: if (getClientData() != null)
224: sb.append(pad + "\t<client-data>" + getClientData()
225: + "</client-data>\n");
226: if (getClientExtendedEventHandler() != null)
227: sb.append(pad + "\t<client-extended-event-handler>"
228: + getClientExtendedEventHandler()
229: + "</client-extended-event-handler>\n");
230:
231: sb.append(getDefaultDataMode().toXML(pad + "\t"));
232:
233: sb.append(pad + "\t<timeout>" + getTimeout() + "</timeout>\n");
234: if (getTimeoutMsg() != null)
235: sb.append(pad + "\t<timeout-msg>" + getTimeoutMsg()
236: + "</timeout-msg>\n");
237:
238: sb.append(pad + "\t<max-auth-try>" + getMaxAuthTry()
239: + "</max-auth-try>\n");
240: if (getMaxAuthTryMsg() != null)
241: sb.append(pad + "\t<max-auth-try-msg>" + getMaxAuthTryMsg()
242: + "</max-auth-try-msg>\n");
243:
244: sb.append(pad + "\t<max-connection>" + getMaxConnection()
245: + "</max-connection>\n");
246: if (getMaxConnectionMsg() != null)
247: sb
248: .append(pad + "\t<max-connection-msg>"
249: + getMaxConnectionMsg()
250: + "</max-connection-msg>\n");
251:
252: if (getConsoleLoggingLevel() != null)
253: sb.append(pad + "\t<console-logging-level>"
254: + getConsoleLoggingLevel()
255: + "</console-logging-level>\n");
256: if (getConsoleLoggingFormatter() != null)
257: sb.append(pad + "\t<console-logging-formatter>"
258: + getConsoleLoggingFormatter()
259: + "</console-logging-formatter>\n");
260:
261: sb.append(getObjectPoolConfig().toXML(pad + "\t"));
262:
263: sb.append(pad + "\t<communication-logging>\n");
264: sb.append(pad + "\t\t<enable>" + getCommunicationLogging()
265: + "</enable>\n");
266: sb.append(pad + "\t</communication-logging>\n");
267:
268: if (getDBObjectPoolConfig() != null) {
269: sb.append(getDBObjectPoolConfig().toXML(pad + "\t"));
270: }
271:
272: if (getSecurityManagerClass() != null) {
273: sb.append(pad + "\t<security-manager-class>"
274: + getSecurityManagerClass()
275: + "</security-manager-class>\n");
276: }
277:
278: if (getAccessConstraintConfig() != null) {
279: sb.append(getAccessConstraintConfig().toXML(pad + "\t"));
280: }
281:
282: if (getQSAdminServerConfig() != null)
283: sb.append(getQSAdminServerConfig().toXML(pad + "\t"));
284:
285: if (getApplicationConfiguration() != null) {
286: sb.append(getApplicationConfiguration().toXML(pad + "\t"));
287: }
288:
289: if (getApplicationJarPath() != null) {
290: sb.append(pad + "\t<application-jar-path>"
291: + getApplicationJarPath()
292: + "</application-jar-path>\n");
293: }
294:
295: if (getServerHooks() != null) {
296: sb.append(getServerHooks().toXML(pad + "\t"));
297: }
298:
299: if (getInitServerHooks() != null) {
300: sb.append(getInitServerHooks().toXML(pad + "\t"));
301: }
302:
303: sb.append(getSecure().toXML(pad + "\t"));
304: sb.append(getAdvancedSettings().toXML(pad + "\t"));
305:
306: sb.append(pad + "</quickserver>\n");
307: return sb.toString();
308: }
309:
310: public String toString() {
311: return toXML(null);
312: }
313: }
|