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 java.util.Date;
022: import java.util.Map;
023:
024: import org.openharmonise.rm.sessions.Session;
025:
026: /**
027: * This class provides the base functionality, and specifies the interface,
028: * for storing logging events in a repository.
029: *
030: * @author Michael Bell
031: * @version $Revision: 1.2 $
032: *
033: */
034: public abstract class AbstractEventLogger implements EventLogger {
035:
036: /**
037: * Constructs an <code>AbstractEventLogger</code>.
038: */
039: public AbstractEventLogger() {
040: super ();
041: }
042:
043: /* (non-Javadoc)
044: * @see org.openharmonise.rm.logging.EventLogger#logEvent(org.openharmonise.rm.logging.LogEvent)
045: */
046: public void logEvent(LogEvent event) throws LogException {
047: int nUserId = -1;
048: String sSessId = null;
049: int nObjectId = -1;
050: String sObjectType = null;
051: String sAction = null;
052: Date timestamp = null;
053: String sIP = null;
054: String sUserAgent = null;
055: String sReferer = null;
056: String sHeaderInfo = null;
057:
058: timestamp = event.getTimestamp();
059:
060: if (event.getUser() != null) {
061: nUserId = event.getUser().getId();
062: }
063:
064: Session sess = event.getSession();
065: if (sess != null) {
066: sSessId = sess.getSessionId();
067: }
068:
069: if (event.getObject() != null) {
070: sObjectType = event.getObject().getClass().getName();
071: nObjectId = event.getObjectId();
072: }
073:
074: sAction = event.getLabel();
075:
076: Map headers = null;
077:
078: if (event.getState() != null) {
079: headers = event.getState().getHeaders();
080:
081: sIP = event.getState().getRemoteAddress();
082: }
083:
084: if (headers == null) {
085: String sAdditional = event.getAdditionalInfo();
086:
087: saveData(nUserId, sSessId, nObjectId, sObjectType, sAction,
088: timestamp, sIP, sAdditional);
089:
090: } else {
091: saveData(nUserId, sSessId, nObjectId, sObjectType, sAction,
092: timestamp, sIP, headers);
093: }
094:
095: }
096:
097: /**
098: * Saves event data to a repository.
099: *
100: * @param nUserId the user identifier
101: * @param sSessionId the session identifier
102: * @param nObjectId the object identifier
103: * @param sObjectType the object type/class name
104: * @param sAction the event description
105: * @param timestamp the timestamp of the event
106: * @param sIP the IP address of the user agent which initiated the event
107: * @param headers the header data associated with the remote request which initiated this event
108: * @throws LogException if an error occurs saving the data
109: */
110: abstract protected void saveData(int nUserId, String sSessionId,
111: int nObjectId, String sObjectType, String sAction,
112: Date timestamp, String sIP, Map headers)
113: throws LogException;
114:
115: /**
116: * Saves event data to a repository.
117: *
118: * @param nUserId the user identifier
119: * @param sSessionId the session identifier
120: * @param nObjectId the object identifier
121: * @param sObjectType the object type/class name
122: * @param sAction the event description
123: * @param timestamp the timestamp of the event
124: * @param sIP the IP address of the user agent which initiated the event
125: * @param sAdditional additional data to be stored with event
126: * @throws LogException if an error occurs saving the data
127: */
128: abstract protected void saveData(int nUserId, String sSessionId,
129: int nObjectId, String sObjectType, String sAction,
130: Date timestamp, String sIP, String sAdditional)
131: throws LogException;
132:
133: }
|