KickJava   Java API By Example, From Geeks To Geeks.

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


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
22 import java.util.Date JavaDoc;
23 import java.util.logging.*;
24 import java.util.logging.Level JavaDoc;
25
26 import org.openharmonise.rm.*;
27 import org.openharmonise.rm.publishing.*;
28 import org.openharmonise.rm.resources.AbstractObject;
29 import org.openharmonise.rm.resources.users.*;
30 import org.openharmonise.rm.sessions.*;
31
32
33 /**
34  *
35  * <code>LogEvent</code> objects represent an event within Harmonise
36  * that can be stored in the event log
37  *
38  * @author Michael Bell
39  * @version $Revision: 1.2 $
40  *
41  */

42 public class LogEvent {
43     
44     /**
45      * The session associated with the event.
46      */

47     protected Session m_session = null;
48     
49     /**
50      * The user associated with the event.
51      */

52     
53     protected User m_user = null;
54     /**
55      * The <code>State</code> context of the event.
56      */

57     
58     protected State m_state = null;
59     
60     /**
61      * The object associated with the event.
62      */

63     protected Object JavaDoc m_eventObj = null;
64     
65     /**
66      * The action/command/label associated with the event.
67      */

68     protected String JavaDoc m_sCommand = null;
69     
70     /**
71      * The timestamp of the event.
72      */

73     protected Date JavaDoc m_timestamp = null;
74     
75     /**
76      * Any additional comments to be added to the event
77      */

78     protected String JavaDoc m_sAdditional = null;
79     
80     /**
81      * Logger for this class
82      */

83     private static final Logger m_logger = Logger.getLogger(LogEvent.class.getName());
84     
85     /**
86      * Constructs a new log event, timestamping the creation of the event.
87      */

88     public LogEvent() {
89         super();
90         m_timestamp = new Date JavaDoc();
91     }
92     
93     /**
94      * Returns the <code>Session</code> associated with this event.
95      *
96      * @return the <code>Session</code> associated with this event.
97      */

98     public Session getSession() {
99         return m_session;
100     }
101
102     /**
103      * Returns the <code>State</code> associated with this event.
104      *
105      * @return the <code>State</code> associated with this event
106      */

107     public State getState() {
108         return m_state;
109     }
110
111     /**
112      * Sets the <code>Session</code> associated with this event.
113      *
114      * @param session the <code>Session</code> associated with this event
115      */

116     public void setSession(Session session) {
117         m_session = session;
118         try {
119             m_user = session.getUser();
120         } catch (DataAccessException e) {
121             m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
122         }
123     }
124
125     /**
126      * Sets the <code>State</code> associated with this event.
127      *
128      * @param state the <code>State</code> associated with this event
129      */

130     public void setState(State state) throws PopulateException {
131         m_state = state;
132         try {
133             m_session = state.getSession();
134         } catch (DataAccessException e) {
135             throw new PopulateException("Error getting session",e);
136         }
137         m_user = state.getLoggedInUser();
138         
139     }
140
141     /**
142      * Returns the label, description of action or command
143      * associated with this event.
144      *
145      * @return the label associated with this event
146      */

147     public String JavaDoc getLabel() {
148         return m_sCommand;
149     }
150
151     /**
152      * Returns the id of the object.
153      *
154      * @return the id of the object
155      */

156     public int getObjectId() {
157         int nObjId = -1;
158         
159         if(m_eventObj != null && m_eventObj instanceof AbstractObject) {
160             nObjId = ((AbstractObject)m_eventObj).getId();
161         }
162         
163         
164         return nObjId;
165     }
166     
167     /**
168      * Returns the object associated with this event.
169      *
170      * @return the object associated with this event
171      */

172     public Object JavaDoc getObject() {
173         return m_eventObj;
174     }
175
176     /**
177      * Sets the label associated to this event.
178      *
179      * @param string the label, description of action or command, associated to this event
180      */

181     public void setLabel(String JavaDoc string) {
182         m_sCommand = string;
183     }
184
185     /**
186      * Sets the object associated with this event.
187      *
188      * @param obj the object associated with this event
189      */

190     public void setEventObject(Object JavaDoc obj) {
191         m_eventObj = obj;
192     }
193     
194     /**
195      * Sets the user associated with this event.
196      *
197      * @param usr the user associated with this event
198      */

199     public void setUser(User usr) {
200         m_user = usr;
201     }
202
203     /**
204      * Returns the user associated with this event.
205      *
206      * @return the user associated with this event
207      */

208     public User getUser() {
209         return m_user;
210     }
211     
212     /**
213      * Returns the time this event occurred.
214      *
215      * @return the time this event occurred
216      */

217     public Date JavaDoc getTimestamp() {
218         return m_timestamp;
219     }
220     
221     /**
222      * Adds additional string data to this event.
223      *
224      * @param sAdditional the additional string data
225      */

226     public void addAdditionalInfo(String JavaDoc sAdditional) {
227         m_sAdditional = sAdditional;
228     }
229     
230     /**
231      * Returns any additional info held as a string.
232      *
233      * @return any additional info held as a string
234      */

235     public String JavaDoc getAdditionalInfo() {
236         return m_sAdditional;
237     }
238 }
239
Popular Tags