KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > rm > logging > EventLogController


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.rm.logging;
20
21 import org.openharmonise.commons.dsi.*;
22 import org.openharmonise.rm.config.*;
23 import org.openharmonise.rm.dsi.*;
24
25
26 /**
27  * Controls the logging of events within the Harmonise framework. There are two
28  * available implementations of <code>EventLogger</code> which can be used
29  * and this class controls which is used in a particular deployment based
30  * on the configuration property 'LOG_OUTPUT', which can take a value of
31  * either 'XML' or 'DB'. This class provides a single point of access for
32  * the core classes of the framework to log events with.
33  *
34  * @author Michael Bell
35  * @version $Revision: 1.2 $
36  *
37  */

38 public class EventLogController implements EventLogger {
39     
40     /**
41      * The singleton instance of this class
42      */

43     static EventLogController m_instance = null;
44     
45     /**
46      * The event logger for the current deployment
47      */

48     private EventLogger m_logger = null;
49     
50     /**
51      * Configuration parameter name which determines the type of event
52      * logger that is used
53      */

54     private static String JavaDoc PNAME_LOG_OUTPUT = "LOG_OUTPUT";
55     
56     /**
57      * Database logging constant. Value for the <code>PNAME_LOG_OUTPUT</code>
58      * configuration parameter which specifies that events should be logged
59      * to the database
60      */

61     public static final String JavaDoc LOGTYPE_DB = "DB";
62     
63     /**
64      * XML logging constant. Value for the <code>PNAME_LOG_OUTPUT</code>
65      * configuration parameter which specifies that events should be logged
66      * to an XML file
67      */

68     public static final String JavaDoc LOGTYPE_XML = "XML";
69
70     /**
71      * Creates a new instance of a event log controller
72      */

73     protected EventLogController() throws LogException {
74         try {
75             String JavaDoc sLogType = ConfigSettings.getProperty(PNAME_LOG_OUTPUT,"DB");
76             
77             if(sLogType != null) {
78                 if(sLogType.equals(LOGTYPE_DB) == true) {
79                     m_logger = new DBEventLogger(DataStoreInterfaceFactory.getDataStoreInterface());
80                 } else if(sLogType.equals(LOGTYPE_XML) == true) {
81                     m_logger = new XMLEventLogger();
82                 }
83             } else {
84                 throw new LogException("Error getting log config setting");
85             }
86         } catch (ConfigException e) {
87             throw new LogException("Error getting log config setting",e);
88         } catch (DataStoreException e) {
89             throw new LogException("Error getting data store inteface",e);
90         }
91     }
92     
93     /**
94      * Returns the singleton instance of the event log controller
95      *
96      * @return the singleton instance of the event log controller
97      */

98     public static EventLogController getInstance() throws LogException {
99         if(m_instance == null) {
100             m_instance = new EventLogController();
101         }
102         
103         return m_instance;
104     }
105
106     /* (non-Javadoc)
107      * @see org.openharmonise.rm.logging.EventLogger#logEvent(org.openharmonise.rm.logging.LogEvent)
108      */

109     public void logEvent(LogEvent event) throws LogException {
110         
111         if(m_logger != null) {
112             m_logger.logEvent(event);
113         }
114     }
115     
116     /**
117      * Resets cached singleton instance to null such that it can be
118      * reconstructed using configuration settings.
119      */

120     public static void reset(){
121         m_instance = null;
122     }
123
124 }
125
Popular Tags