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: * AuditTrail.java
20: */
21:
22: // the package path
23: package com.rift.coad.lib.audit;
24:
25: // coadunation imports
26: import com.rift.coad.lib.security.SessionManager;
27:
28: /**
29: * This object is responsible for processing the audit trail requests.
30: *
31: * @author brett chaldecott
32: */
33: public class AuditTrail {
34:
35: // private member variable
36: private Class target = null;
37:
38: /**
39: * Creates a new instance of AuditTrail
40: *
41: * @param target The target of this audit trail.
42: */
43: private AuditTrail(Class target) {
44: this .target = target;
45: }
46:
47: /**
48: * This method constructs a new audit trail entry.
49: *
50: * @return The reference to the new audit trail.
51: * @param target The target of the audit trail.
52: */
53: public static AuditTrail getAudit(Class target) {
54: return new AuditTrail(target);
55: }
56:
57: /**
58: * This method logs a succesfull audit trail entry.
59: *
60: * @param method The name of the method to log the event for.
61: */
62: public void logEvent(String method) {
63: AuditTrailManager.getInstance().addEntry(
64: new AuditTrailEntry(getUsername(), target.getName(),
65: method));
66: }
67:
68: /**
69: * This method logs an un-succesfull audit trail entry.
70: *
71: * @param method The name of the method to log the event for.
72: * @param ex The exception that cause the error on the event.
73: */
74: public void logEvent(String method, Throwable ex) {
75: AuditTrailManager.getInstance().addEntry(
76: new AuditTrailEntry(getUsername(), target.getName(),
77: method, ex));
78: }
79:
80: /**
81: * This method returns the user name of the current thread.
82: *
83: * @return The user for the current session or Unknown if not known.
84: */
85: private String getUsername() {
86: try {
87: // return the user for the current session.
88: return SessionManager.getInstance().getSession().getUser()
89: .getName();
90: } catch (Exception ex) {
91: return "Unknown";
92: }
93: }
94: }
|