KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dspace > app > statistics > LogLine


1 /*
2  * LogLine.java
3  *
4  * Version: $Revision: 1.2 $
5  *
6  * Date: $Date: 2005/04/20 14:22:41 $
7  *
8  * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
9  * Institute of Technology. All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are
13  * met:
14  *
15  * - Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  *
18  * - Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution.
21  *
22  * - Neither the name of the Hewlett-Packard Company nor the name of the
23  * Massachusetts Institute of Technology nor the names of their
24  * contributors may be used to endorse or promote products derived from
25  * this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
38  * DAMAGE.
39  */

40
41 package org.dspace.app.statistics;
42
43 import java.util.Date JavaDoc;
44
45 /**
46  * This class represents a single log file line and the operations that can be
47  * performed on it
48  *
49  * The components that it represents are: Date, Level, User, Action, and additional
50  * Params
51  *
52  * @author Richard Jones
53  */

54 public class LogLine
55 {
56     /** the date of the log file line */
57     private Date JavaDoc date = null;
58     
59     /** the level of the log line type */
60     private String JavaDoc level = null;
61     
62     /** the user performing the logged action */
63     private String JavaDoc user = null;
64     
65     /** the action being performed */
66     private String JavaDoc action = null;
67     
68     /** the parameters associated with the line */
69     private String JavaDoc params = null;
70     
71     /**
72      * constructor to create new statistic
73      *
74      * @param key the key for the statistic
75      * @param value the value for the statistic
76      */

77     LogLine(Date JavaDoc date, String JavaDoc level, String JavaDoc user, String JavaDoc action, String JavaDoc params)
78     {
79         this.date = date;
80         this.level = level;
81     this.user = user;
82         this.action = action;
83         this.params = params;
84     }
85     
86     /**
87      * get the date of the log line
88      *
89      * @return the date of this log line
90      */

91     public Date JavaDoc getDate()
92     {
93         return this.date;
94     }
95     
96     
97     /**
98      * get the level of this log line
99      *
100      * @return the level of the log line
101      */

102     public String JavaDoc getLevel()
103     {
104         return this.level;
105     }
106     
107     
108     /**
109      * get the user performing the logged action
110      *
111      * @return the user performing the logged action
112      */

113     public String JavaDoc getUser()
114     {
115         return this.user;
116     }
117     
118     
119     /**
120      * get the action being performed
121      *
122      * @return the logged action
123      */

124     public String JavaDoc getAction()
125     {
126         return this.action;
127     }
128     
129     
130     /**
131      * get the parameters associated with the action
132      *
133      * @return the parameters associated with the action
134      */

135     public String JavaDoc getParams()
136     {
137         return this.params;
138     }
139     
140     
141     /**
142      * find out if this log file line is before the given date
143      *
144      * @param date the date to be compared to
145      *
146      * @return true if the line is before the given date, false if not
147      */

148     public boolean beforeDate(Date JavaDoc date)
149     {
150         if (date != null)
151         {
152             if (date.compareTo(this.getDate()) >= 0)
153             {
154                 return true;
155             }
156             else
157             {
158                 return false;
159             }
160         }
161         return false;
162     }
163     
164     
165     /**
166      * find out if this log file line is after the given date
167      *
168      * @param date the date to be compared to
169      *
170      * @return true if the line is after the given date, false if not
171      */

172     public boolean afterDate(Date JavaDoc date)
173     {
174         if (date != null)
175         {
176             if (date.compareTo(this.getDate()) <= 0)
177             {
178                 return true;
179             }
180             else
181             {
182                 return false;
183             }
184         }
185         return false;
186     }
187     
188     
189     /**
190      * find out if the log line is of the given level. Levels are either
191      * INFO, WARN or ERROR
192      *
193      * @param level the level we want to test for
194      *
195      * @return true if the line is of the specified level, false if not
196      */

197     public boolean isLevel(String JavaDoc level)
198     {
199         if (this.getLevel().equals(level))
200         {
201             return true;
202         }
203         return false;
204     }
205     
206     
207     /**
208      * find out if the log line is of the given action. Actions are not
209      * directly constrained by the vocabulary, and any system module may define
210      * any action name for its behaviour
211      *
212      * @param action the action we want to test for
213      *
214      * @return true if the line is of the specified action, false if not
215      */

216     public boolean isAction(String JavaDoc action)
217     {
218         if (this.getAction().equals(action))
219         {
220             return true;
221         }
222         return false;
223     }
224  
225 }
226
Popular Tags