001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.rm.logging;
020:
021: import org.openharmonise.commons.dsi.*;
022: import org.openharmonise.rm.config.*;
023: import org.openharmonise.rm.dsi.*;
024:
025: /**
026: * Controls the logging of events within the Harmonise framework. There are two
027: * available implementations of <code>EventLogger</code> which can be used
028: * and this class controls which is used in a particular deployment based
029: * on the configuration property 'LOG_OUTPUT', which can take a value of
030: * either 'XML' or 'DB'. This class provides a single point of access for
031: * the core classes of the framework to log events with.
032: *
033: * @author Michael Bell
034: * @version $Revision: 1.2 $
035: *
036: */
037: public class EventLogController implements EventLogger {
038:
039: /**
040: * The singleton instance of this class
041: */
042: static EventLogController m_instance = null;
043:
044: /**
045: * The event logger for the current deployment
046: */
047: private EventLogger m_logger = null;
048:
049: /**
050: * Configuration parameter name which determines the type of event
051: * logger that is used
052: */
053: private static String PNAME_LOG_OUTPUT = "LOG_OUTPUT";
054:
055: /**
056: * Database logging constant. Value for the <code>PNAME_LOG_OUTPUT</code>
057: * configuration parameter which specifies that events should be logged
058: * to the database
059: */
060: public static final String LOGTYPE_DB = "DB";
061:
062: /**
063: * XML logging constant. Value for the <code>PNAME_LOG_OUTPUT</code>
064: * configuration parameter which specifies that events should be logged
065: * to an XML file
066: */
067: public static final String LOGTYPE_XML = "XML";
068:
069: /**
070: * Creates a new instance of a event log controller
071: */
072: protected EventLogController() throws LogException {
073: try {
074: String sLogType = ConfigSettings.getProperty(
075: PNAME_LOG_OUTPUT, "DB");
076:
077: if (sLogType != null) {
078: if (sLogType.equals(LOGTYPE_DB) == true) {
079: m_logger = new DBEventLogger(
080: DataStoreInterfaceFactory
081: .getDataStoreInterface());
082: } else if (sLogType.equals(LOGTYPE_XML) == true) {
083: m_logger = new XMLEventLogger();
084: }
085: } else {
086: throw new LogException(
087: "Error getting log config setting");
088: }
089: } catch (ConfigException e) {
090: throw new LogException("Error getting log config setting",
091: e);
092: } catch (DataStoreException e) {
093: throw new LogException("Error getting data store inteface",
094: e);
095: }
096: }
097:
098: /**
099: * Returns the singleton instance of the event log controller
100: *
101: * @return the singleton instance of the event log controller
102: */
103: public static EventLogController getInstance() throws LogException {
104: if (m_instance == null) {
105: m_instance = new EventLogController();
106: }
107:
108: return m_instance;
109: }
110:
111: /* (non-Javadoc)
112: * @see org.openharmonise.rm.logging.EventLogger#logEvent(org.openharmonise.rm.logging.LogEvent)
113: */
114: public void logEvent(LogEvent event) throws LogException {
115:
116: if (m_logger != null) {
117: m_logger.logEvent(event);
118: }
119: }
120:
121: /**
122: * Resets cached singleton instance to null such that it can be
123: * reconstructed using configuration settings.
124: */
125: public static void reset() {
126: m_instance = null;
127: }
128:
129: }
|