01: /*
02: * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.wso2.esb;
18:
19: import org.apache.axiom.om.OMElement;
20: import org.apache.commons.logging.Log;
21: import org.apache.commons.logging.LogFactory;
22: import org.wso2.utils.ServerConfiguration;
23: import org.wso2.utils.ServerConfigurationException;
24:
25: /*
26: * Loads the service bus configuration from the config file server.xml
27: */
28:
29: public class ServiceBusConfiguration {
30:
31: private static Log log = LogFactory
32: .getLog(ServiceBusConfiguration.class);
33:
34: private static ServiceBusConfiguration configuration = null;
35:
36: private final static String defaultConfigurationXMLLocation = "webapp/WEB-INF/classes/conf/server.xml";
37:
38: private final static ServerConfiguration serverConfiguration = ServerConfiguration
39: .getInstance();
40:
41: private ServiceBusConfiguration() {
42: }
43:
44: public static ServiceBusConfiguration getInstance() {
45:
46: if (configuration == null) {
47: // intializing the defaultConfigurationXMLLocation
48: configuration = new ServiceBusConfiguration();
49: String esbXml = System
50: .getProperty(ServiceBusConstants.ESB_SERVER_XML);
51: try {
52: if (esbXml == null || "".equals(esbXml)) {
53: esbXml = defaultConfigurationXMLLocation;
54: }
55: serverConfiguration.init(esbXml.trim());
56: } catch (ServerConfigurationException e) {
57: log.error(e);
58: }
59: log.info("Configuration loaded from : " + esbXml);
60: }
61: return configuration;
62: }
63:
64: public String getFirstProperty(String key) {
65: return serverConfiguration.getFirstProperty(key);
66: }
67:
68: public OMElement getDocumentElement() {
69: return serverConfiguration.getDocumentElement();
70: }
71: }
|