KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Date JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import org.openharmonise.rm.sessions.Session;
25
26
27 /**
28  * This class provides the base functionality, and specifies the interface,
29  * for storing logging events in a repository.
30  *
31  * @author Michael Bell
32  * @version $Revision: 1.2 $
33  *
34  */

35 public abstract class AbstractEventLogger implements EventLogger {
36
37     /**
38      * Constructs an <code>AbstractEventLogger</code>.
39      */

40     public AbstractEventLogger() {
41         super();
42     }
43     
44
45     /* (non-Javadoc)
46      * @see org.openharmonise.rm.logging.EventLogger#logEvent(org.openharmonise.rm.logging.LogEvent)
47      */

48     public void logEvent(LogEvent event) throws LogException {
49         int nUserId = -1;
50         String JavaDoc sSessId = null;
51         int nObjectId = -1;
52         String JavaDoc sObjectType = null;
53         String JavaDoc sAction = null;
54         Date JavaDoc timestamp = null;
55         String JavaDoc sIP = null;
56         String JavaDoc sUserAgent = null;
57         String JavaDoc sReferer = null;
58         String JavaDoc sHeaderInfo = null;
59         
60         timestamp = event.getTimestamp();
61         
62         if(event.getUser() != null) {
63             nUserId = event.getUser().getId();
64         }
65         
66         Session sess = event.getSession();
67         if(sess != null) {
68             sSessId = sess.getSessionId();
69         }
70         
71         if(event.getObject() != null) {
72             sObjectType = event.getObject().getClass().getName();
73             nObjectId = event.getObjectId();
74         }
75         
76         sAction = event.getLabel();
77         
78         Map JavaDoc headers = null;
79         
80         if(event.getState() != null) {
81             headers = event.getState().getHeaders();
82
83             sIP = event.getState().getRemoteAddress();
84         }
85         
86         if(headers == null) {
87             String JavaDoc sAdditional = event.getAdditionalInfo();
88             
89             saveData(nUserId,sSessId,nObjectId,sObjectType,sAction,timestamp,sIP,sAdditional);
90
91         } else {
92             saveData(nUserId,sSessId,nObjectId,sObjectType,sAction,timestamp,sIP,headers);
93         }
94         
95         
96     }
97
98     /**
99      * Saves event data to a repository.
100      *
101      * @param nUserId the user identifier
102      * @param sSessionId the session identifier
103      * @param nObjectId the object identifier
104      * @param sObjectType the object type/class name
105      * @param sAction the event description
106      * @param timestamp the timestamp of the event
107      * @param sIP the IP address of the user agent which initiated the event
108      * @param headers the header data associated with the remote request which initiated this event
109      * @throws LogException if an error occurs saving the data
110      */

111     abstract protected void saveData(
112             int nUserId,
113             String JavaDoc sSessionId,
114             int nObjectId,
115             String JavaDoc sObjectType,
116             String JavaDoc sAction,
117             Date JavaDoc timestamp,
118             String JavaDoc sIP,
119             Map JavaDoc headers)
120             throws LogException;
121     
122     /**
123      * Saves event data to a repository.
124      *
125      * @param nUserId the user identifier
126      * @param sSessionId the session identifier
127      * @param nObjectId the object identifier
128      * @param sObjectType the object type/class name
129      * @param sAction the event description
130      * @param timestamp the timestamp of the event
131      * @param sIP the IP address of the user agent which initiated the event
132      * @param sAdditional additional data to be stored with event
133      * @throws LogException if an error occurs saving the data
134      */

135     abstract protected void saveData(
136             int nUserId,
137             String JavaDoc sSessionId,
138             int nObjectId,
139             String JavaDoc sObjectType,
140             String JavaDoc sAction,
141             Date JavaDoc timestamp,
142             String JavaDoc sIP,
143             String JavaDoc sAdditional)
144             throws LogException;
145
146 }
147
Popular Tags