KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > logging > SessionLogEntry


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2005, Oracle. All rights reserved.
22
package oracle.toplink.essentials.logging;
23
24 import java.util.Date JavaDoc;
25 import java.io.Serializable JavaDoc;
26 import oracle.toplink.essentials.internal.sessions.AbstractSession;
27 import oracle.toplink.essentials.internal.databaseaccess.Accessor;
28
29 /**
30  * SessionLogEntry is a simple container object that holds
31  * all the information pertinent to a TopLink logging event.
32  * It has a date/time stamp indicating when the event took
33  * place. It holds the session, thread, and accessor
34  * responsible for the event. And it holds whatever message
35  * was passed through to be logged.
36  *
37  * @see SessionLog
38  * @see DefaultSessionLog
39  *
40  * @author Big Country
41  * @since TOPLink/Java 3.0
42  */

43 public class SessionLogEntry implements Serializable JavaDoc {
44     protected Date JavaDoc date;
45     protected transient AbstractSession session;
46     protected transient Thread JavaDoc thread;
47     protected transient Accessor connection;
48     protected String JavaDoc message;
49     protected Throwable JavaDoc throwable;
50     protected int level;
51     protected String JavaDoc nameSpace;
52     protected Object JavaDoc[] parameters;
53     protected boolean shouldTranslate;
54
55     /**
56      * PUBLIC:
57      * Create a new session log entry for a session
58      */

59     public SessionLogEntry(AbstractSession session) {
60         this.date = new Date JavaDoc();
61         this.thread = Thread.currentThread();
62         this.session = session;
63         this.message = "";
64         this.level = SessionLog.INFO;
65     }
66
67     /**
68      * PUBLIC:
69      * Create a new session log entry for a session and an exception
70      */

71     public SessionLogEntry(AbstractSession session, Throwable JavaDoc throwable) {
72         this(session);
73         this.throwable = throwable;
74         this.level = SessionLog.SEVERE;
75     }
76
77     /**
78      * PUBLIC:
79      * Create a new session log entry for a session and a message
80      */

81     public SessionLogEntry(AbstractSession session, String JavaDoc message) {
82         this(session);
83         this.message = message;
84     }
85
86     /**
87      * PUBLIC:
88      * Create a new session log entry for a session, a message and an accessor
89      */

90     public SessionLogEntry(AbstractSession session, String JavaDoc message, Accessor connection) {
91         this(session, message);
92         this.connection = connection;
93     }
94
95     /**
96      * PUBLIC:
97      * Create a new session log entry for a request level, a session, a message and an accessor
98      */

99     public SessionLogEntry(int level, AbstractSession session, String JavaDoc message, Object JavaDoc[] params, Accessor connection, boolean shouldTranslate) {
100         this(session, message, connection);
101         this.level = level;
102         this.parameters = params;
103         this.shouldTranslate = shouldTranslate;
104     }
105
106     /**
107      * PUBLIC:
108      * Create a new session log entry for a request level, a session, a message and an accessor
109      */

110     public SessionLogEntry(int level, String JavaDoc category, AbstractSession session, String JavaDoc message, Object JavaDoc[] params, Accessor connection, boolean shouldTranslate) {
111         this(level, session, message, params, connection, shouldTranslate);
112         this.nameSpace = category;
113     }
114
115     /**
116      * PUBLIC:
117      * Create a new session log entry for a session, a level, a category and an exception
118      */

119     public SessionLogEntry(AbstractSession session, int level, String JavaDoc category, Throwable JavaDoc throwable) {
120         this(session, throwable);
121         this.level = level;
122         this.nameSpace = category;
123     }
124
125     /**
126      * PUBLIC:
127      * Return the connection that generated the log entry.
128      */

129     public Accessor getConnection() {
130         return connection;
131     }
132
133     /**
134      * PUBLIC:
135      * Return the date of the log entry.
136      */

137     public Date JavaDoc getDate() {
138         return date;
139     }
140
141     /**
142      * PUBLIC:
143      * Return the exception that caused the log entry.
144      */

145     public Throwable JavaDoc getException() {
146         return throwable;
147     }
148
149     /**
150      * PUBLIC:
151      * Return the log entry's message.
152      */

153     public String JavaDoc getMessage() {
154         return message;
155     }
156
157     /**
158      * PUBLIC:
159      * Return the session that generated the log entry.
160      */

161     public AbstractSession getSession() {
162         return session;
163     }
164
165     /**
166      * PUBLIC:
167      * Return the thread that was active when the log entry was generated.
168      */

169     public Thread JavaDoc getThread() {
170         return thread;
171     }
172
173     /**
174      * PUBLIC:
175      * Return the request level of the log entry.
176      */

177     public int getLevel() {
178         return level;
179     }
180
181     /**
182      * PUBLIC:
183      * Return the name space of the log entry.
184      */

185     public String JavaDoc getNameSpace() {
186         return nameSpace;
187     }
188
189     /**
190      * PUBLIC:
191      * Return the array of parameters to the message.
192      */

193     public Object JavaDoc[] getParameters() {
194         return parameters;
195     }
196
197     /**
198      * PUBLIC:
199      * Return if the message should be translated.
200      */

201     public boolean shouldTranslate() {
202         return shouldTranslate;
203     }
204
205     /**
206      * PUBLIC:
207      * Return if the log entry was for an exception.
208      */

209     public boolean hasException() {
210         return getException() != null;
211     }
212
213     /**
214      * PUBLIC:
215      * Set the connection that generated the log entry.
216      */

217     public void setConnection(Accessor connection) {
218         this.connection = connection;
219     }
220
221     /**
222      * PUBLIC:
223      * Set the date of the log entry.
224      */

225     public void setDate(Date JavaDoc date) {
226         this.date = date;
227     }
228
229     /**
230      * PUBLIC:
231      * Set the exception that caused the log entry.
232      */

233     public void setException(Throwable JavaDoc throwable) {
234         this.throwable = throwable;
235     }
236
237     /**
238      * PUBLIC:
239      * Set the entry's message.
240      */

241     public void setMessage(String JavaDoc message) {
242         this.message = message;
243     }
244
245     /**
246      * PUBLIC:
247      * Set the session that generated the log entry.
248      */

249     public void setSession(AbstractSession session) {
250         this.session = session;
251     }
252
253     /**
254      * PUBLIC:
255      * Set the thread that was active when the log entry was generated.
256      */

257     public void setThread(Thread JavaDoc thread) {
258         this.thread = thread;
259     }
260
261     /**
262      * PUBLIC:
263      * Set the request level of the log entry.
264      */

265     public void setLevel(int level) {
266         this.level = level;
267     }
268
269     /**
270      * PUBLIC:
271      * Set the name space of the log entry.
272      */

273     public void setNameSpace(String JavaDoc nameSpace) {
274         this.nameSpace = nameSpace;
275     }
276
277     /**
278     * PUBLIC:
279     * Set the array of parameters to the message.
280     */

281     public void setParameters(Object JavaDoc[] params) {
282         this.parameters = params;
283     }
284
285     /**
286      * PUBLIC:
287      * Set if the message should be translated.
288      */

289     public void setShouldTranslate(boolean shouldTranslate) {
290         this.shouldTranslate = shouldTranslate;
291     }
292
293     /**
294      * PUBLIC:
295      * Print message.
296      */

297     public String JavaDoc toString() {
298         return oracle.toplink.essentials.internal.helper.Helper.getShortClassName(getClass()) + "(" + getMessage() + ")";
299     }
300 }
301
Popular Tags