01: /*
02: * CoadunationLib: The coaduntion implementation library.
03: * Copyright (C) 2007 Rift IT Contracting
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18: *
19: * AuditTrailManager.java
20: */
21:
22: // package path
23: package com.rift.coad.lib.audit;
24:
25: // log4j import
26: import org.apache.log4j.Logger;
27:
28: // coadunation imports
29: import com.rift.coad.lib.configuration.Configuration;
30: import com.rift.coad.lib.configuration.ConfigurationFactory;
31:
32: /**
33: * This object is responsible for managing the audit trails.
34: *
35: * @author brett chaldecott
36: */
37: public class AuditTrailManager {
38:
39: // class static member variables
40: private static AuditTrailManager singleton = null;
41:
42: // private member variables
43: private Logger log = Logger.getLogger(AuditTrailManager.class
44: .getName());
45: private AuditTrailFormatter formatter = null;
46:
47: /**
48: * Creates a new instance of AuditTrailManager
49: */
50: private AuditTrailManager() {
51: try {
52: Configuration config = ConfigurationFactory.getInstance()
53: .getConfig(AuditTrailManager.class);
54: formatter = (AuditTrailFormatter) Class.forName(
55: config.getString("Formatter")).newInstance();
56: } catch (Exception ex) {
57: log.error("Failed to setup the audit trail manager : "
58: + ex.getMessage(), ex);
59: }
60: }
61:
62: /**
63: * This method returns an instance of the audit trail manager.
64: *
65: * @return The reference to the newly created audit trail.
66: */
67: public static synchronized AuditTrailManager getInstance() {
68: if (singleton == null) {
69: singleton = new AuditTrailManager();
70: }
71: return singleton;
72: }
73:
74: /**
75: * This method is used to log an audit trail entry.
76: */
77: public void addEntry(AuditTrailEntry entry) {
78: // if there is no audit trail ignore
79: try {
80: if (formatter != null) {
81: formatter.format(entry);
82: }
83: } catch (Throwable ex) {
84: log.error("Failed to log an audit trail entry : "
85: + ex.getMessage(), ex);
86: }
87: }
88: }
|