Project Report: fawkez

Packagesummary org.jcoderz.commons.logging

org.jcoderz.commons.logging.LogItem

LineHitsNoteSource
1  /*
2   * $Id: LogItem.java 1299 2009-03-23 20:06:23Z amandel $
3   *
4   * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5   *
6   * Redistribution and use in source and binary forms, with or without
7   * modification, are permitted provided that the following conditions are
8   * met:
9   *
10   *    * Redistributions of source code must retain the above copyright
11   *      notice, this list of conditions and the following disclaimer.
12   *    * Redistributions in binary form must reproduce the above
13   *      copyright notice, this list of conditions and the following
14   *      disclaimer in the documentation and/or other materials
15   *      provided with the distribution.
16   *    * Neither the name of the jCoderZ.org Project nor the names of
17   *      its contributors may be used to endorse or promote products
18   *      derived from this software without specific prior written
19   *      permission.
20   *
21   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   */
33  package org.jcoderz.commons.logging;
34  
35  import java.util.ArrayList;
36  import java.util.Collections;
37  import java.util.HashMap;
38  import java.util.List;
39  import java.util.Map;
40  import java.util.Set;
41  import java.util.logging.Level;
42  
43  import org.jcoderz.commons.BusinessImpact;
44  import org.jcoderz.commons.Category;
45  import org.jcoderz.commons.types.Date;
46  import org.jcoderz.commons.util.Assert;
47  import org.jcoderz.commons.util.Constants;
48  
49  
50  
51  /**
52   * This class is the base class of nested log information as it is used for
53   * displaying or transferring log messages.
54   *
55   */
56100(1)public abstract class LogItem
57  {
58     /** This is a prefix of an internal parameter of a log message, i.e. a
59      *  parameter, which is not defined as parameter in the xml file. */
60     public static final String INTERNAL_PARAMETER_PREFIX = "_";
61  
62100    private LogItem mNestedEntry = null;
63100    private LogItem mParentEntry = null;
64  
65100    private Date mTimestamp = null;
66100    private Level mLogLevel = null;
67     private long mThreadId;
68100    private BusinessImpact mBusinessImpact = null;
69100    private Category mCategory = null;
70100    private String mNodeId = null;
71100    private String mInstanceId = null;
72100    private String mTrackingNumber = null;
73100    private String mSymbol = null;
74100    private String mSymbolId = null;
75100    private String mMessage = null;
76100    private String mSourceClass = null;
77100    private String mSourceMethod = null;
78100    private String mSolution = null;
79100    private String mThreadName = null;
80100    private StringBuffer mMessageBuffer = null;
81  
82100    private final Map mParameters = new HashMap();
83  
84100    private final List mStackTraceLines = new ArrayList();
85  
86100    private String mType = null;
87  
88     /**
89      * Sets the business impact of this.
90      *
91      * @param businessImpact The business impact to set.
92      */
93     public void setBusinessImpact (BusinessImpact businessImpact)
94     {
95100       mBusinessImpact = businessImpact;
96100    }
97  
98     /**
99      * Sets the category of this.
100      *
101      * @param category The category to set.
102      */
103     public void setCategory (Category category)
104     {
105100       mCategory = category;
106100    }
107  
108     /**
109      * Sets the instance id.
110      *
111      * @param instanceId The instance id to set.
112      */
113     public void setInstanceId (String instanceId)
114     {
115100       mInstanceId = instanceId;
116100    }
117  
118     /**
119      * Sets the log level of this.
120      *
121      * @param logLevel The log level, which had been used for logging the
122      * message.
123      */
124     public void setLoggerLevel (Level logLevel)
125     {
126100       mLogLevel = logLevel;
127100    }
128  
129     /**
130      * Sets the message text.
131      *
132      * @param message The text of the logged message.
133      */
134     public void setMessage (String message)
135     {
136100       mMessageBuffer = new StringBuffer(String.valueOf(message));
137100       mMessage = null;
138100    }
139  
140     /**
141      * Appends a new line with supplied message text to the already stored
142      * message. If no message has been stored yet, the supplied string is set
143      * as message.
144      *
145      * @param messageLine The new line of message.
146      */
147     public void appendMessageLine (String messageLine)
148     {
1490       mMessage = null;
1500       if (mMessageBuffer == null)
151        {
1520          mMessageBuffer = new StringBuffer(String.valueOf(messageLine));
153        }
154        else
155        {
1560          mMessageBuffer.append(Constants.LINE_SEPARATOR).append(
157                 String.valueOf(messageLine));
158        }
1590    }
160  
161     /**
162      * Sets the node id.
163      *
164      * @param nodeId The node id to set.
165      */
166     public void setNodeId (String nodeId)
167     {
168100       mNodeId = nodeId;
169100    }
170  
171     /**
172      * Sets the possible solution to resolve the error indicated by the logged
173      * message.
174      *
175      * @param solution The solution for the logged message.
176      */
177     public void setSolution (String solution)
178     {
179100       mSolution = solution;
180100    }
181  
182     /**
183      * Sets the class name of the source location where the message was logged.
184      *
185      * @param sourceClass The name of the class where the message was logged,
186      */
187     public void setSourceClass (String sourceClass)
188     {
189100       mSourceClass = sourceClass;
190100    }
191  
192     /**
193      * Sets the method name of the source location where the message was logged.
194      *
195      * @param sourceMethod The name of the method where the message was logged,
196      */
197     public void setSourceMethod (String sourceMethod)
198     {
199100       mSourceMethod = sourceMethod;
200100    }
201  
202     /**
203      * Sets the message symbol.
204      *
205      * @param symbol The symbol for the logged message.
206      */
207     public void setSymbol (final String symbol)
208     {
209100       mSymbol = symbol;
210100    }
211  
212     /**
213      * Sets the message symbol code.
214      *
215      * @param symbolId The id/code for the symbol of the logged message.
216      */
217     public void setSymbolId (final String symbolId)
218     {
219100       mSymbolId = symbolId;
220100    }
221  
222     /**
223      * Sets the thread id.
224      *
225      * @param threadId The thread id to set.
226      */
227     public void setThreadId (long threadId)
228     {
229100       mThreadId = threadId;
230100    }
231  
232     /**
233      * Sets the timestamp of the message.
234      *
235      * @param timestamp The timestamp of when the message was logged.
236      */
237     public void setTimestamp (final Date timestamp)
238     {
239100       mTimestamp = timestamp;
240100    }
241  
242     /**
243      * Sets the tracking number from the parsed log line.
244      *
245      * @param trackingNumber The tracking number of the logged message.
246      */
247     public void setTrackingNumber (final String trackingNumber)
248     {
249100       mTrackingNumber = trackingNumber;
250100    }
251  
252     /**
253      * Sets the type of this.
254      *
255      * @param type The type to set.
256      */
257     public void setType (final String type)
258     {
259100       mType = type;
260100    }
261  
262     /**
263      * Sets the thread name for this LogItem.
264      *
265 (2)    * @param type The thread name to set..
266      */
267 (3)(4)   public void setThreadName (final String threadName)
268     {
269100       mThreadName = threadName;
270100    }
271  
272     /**
273      * Gets the business impact.
274      *
275      * @return BusinessImpact of the message.
276      */
277     public BusinessImpact getBusinessImpact ()
278     {
279100       return mBusinessImpact;
280     }
281  
282     /**
283      * Gets the category.
284      *
285      * @return Category of the message.
286      */
287     public Category getCategory ()
288     {
289100       return mCategory;
290     }
291  
292     /**
293      * Gets the id of the instance which logged this.
294      *
295      * @return Id of instance, which logged this.
296      */
297     public String getInstanceId ()
298     {
299100       return mInstanceId;
300     }
301  
302     /**
303      * Gets the logger level of this entry.
304      *
305      * @return log level used to log this.
306      */
307     public Level getLoggerLevel ()
308     {
309100       return mLogLevel;
310     }
311  
312     /**
313      * Gets the message of this entry.
314      *
315      * @return Message text.
316      */
317     public String getMessage ()
318     {
319100       if (mMessage == null)
320        {
32175          mMessage = (mMessageBuffer == null) ? null : mMessageBuffer.toString();
322        }
323100       return mMessage;
324     }
325  
326     /**
327      * Gets the id of the node which logged this.
328      *
329      * @return Id of the node qwhich logged this.
330      */
331     public String getNodeId ()
332     {
333100       return mNodeId;
334     }
335  
336     /**
337      * Gets the parameter names of the parameters for this as unmodifiable Set.
338      *
339      * @return Set with parameter names, migth be empty, never null.
340      */
341  
342     public Set getParameterNames ()
343     {
344100       return Collections.unmodifiableSet(mParameters.keySet());
345     }
346  
347     /**
348      * Gets the List of parameter values for the specified parameter name as
349      * unmodifiable List.
350      *
351      * @param parameterName The name of the parameter for which to return the
352      * values.
353      *
354      * @return List of parameter values, is null if <code>parameterName</code> is
355      * unknown.
356      */
357  
358     public List getParameterValues (final String parameterName)
359     {
360100       final List parameterValues = (List) mParameters.get(parameterName);
36175       final List rc = (parameterValues == null)
362              ? null : Collections.unmodifiableList(parameterValues);
363100(5)      return rc;
364     }
365  
366     /**
367      * Gets a possible solution.
368      *
369      * @return The solution for an error message;
370      */
371     public String getSolution ()
372     {
373100       return mSolution;
374     }
375  
376     /**
377      * Gets the name of the class where the message was logged.
378      *
379      * @return Name of the source class.
380      */
381     public String getSourceClass ()
382     {
383100       return mSourceClass;
384     }
385  
386     /**
387      * Gets the name of the method where this was logged.
388      *
389      * @return Name of the source method.
390      */
391     public String getSourceMethod ()
392     {
393100       return mSourceMethod;
394     }
395  
396     /**
397      * Gets the list of stack trace linesstored by this.
398      *
399      * @return List with stack trace lines, might be empty, never null.
400      */
401     public List getStackTraceLines ()
402     {
403100       return mStackTraceLines;
404     }
405  
406     /**
407      * Gets the message symbol.
408      *
409      * @return The message symbol.
410      */
411     public String getSymbol ()
412     {
413100       return mSymbol;
414     }
415  
416     /**
417      * Gets the id of the message symbol in hex representation.
418      *
419      * @return The symbol id in hex representation
420      */
421     public String getSymbolId ()
422     {
423100       return mSymbolId;
424     }
425  
426     /**
427      * Gets the id of the thread which logged this.
428      *
429      * @return Id of thread whcih logged this.
430      */
431     public long getThreadId ()
432     {
433100       return mThreadId;
434     }
435  
436     /**
437      * Gets the timestamp of when this was logged.
438      *
439      * @return Timestamp when this was logged.
440      */
441     public Date getTimestamp ()
442     {
443100       return mTimestamp;
444     }
445  
446     /**
447      * Gets the tracking number of this.
448      *
449      * @return Tracking number of this.
450      */
451     public String getTrackingNumber ()
452     {
453100       return mTrackingNumber;
454     }
455  
456     /**
457      * Returns the type of this, which is retrieved from the log line type.
458      *
459      * @return Type of this.
460      */
461     public String getType ()
462     {
463100       return mType;
464     }
465  
466     /**
467      * Gets the thread name for this LogItem.
468      *
469      * @return The thread name of this log item.
470      */
471     public String getThreadName ()
472     {
473100       return mThreadName;
474     }
475  
476     /**
477      * Gets information whether this item stores an exception + stacktrace +
478      * cause description only. Even if this is the case, there might be a nested
479      * item storing a log message.
480      *
481      * @return true, if this item only stores an exception; false, else.
482      */
483     public boolean isExceptionItem ()
484     {
485        // for all types of log messages the mType is set. So if it is not set,
486        // this entry only stores exception values.
487100       return (mType == null);
488     }
489  
490     /**
491      * Gets the item nested to this.
492      *
493      * @return nested log item, might be null if no such.
494      */
495     public LogItem getNestedItem ()
496     {
497100       return mNestedEntry;
498     }
499  
500     /**
501      * Sets the supplied item as nested item for this and this as parent for
502      * the supplied item.
503      *
504      * @param nestedItem The LogItem to set as nested item for this.
505      */
506     public void setNestedItem (LogItem nestedItem)
507     {
508100       Assert.notNull(nestedItem, "nestedItem");
509100       mNestedEntry = nestedItem;
510100       nestedItem.setParentItem(this);
511100    }
512  
513     /**
514      * Sets the log item which is parent to this.
515      *
516      * @param parentEntry The parentEntry to set.
517      */
518     public void setParentItem (LogItem parentEntry)
519     {
520100       mParentEntry = parentEntry;
521100    }
522  
523     /**
524      * Gets the log item which is parent to this.
525      *
526      * @return The parent item of this, might be null.
527      */
528     public LogItem getParentItem ()
529     {
530100       return mParentEntry;
531     }
532  
533     /**
534      * Adds a parameter with value to the stored parameters.
535      *
536      * @param name The name of the parameter.
537      * @param value The value of the parameter with this name.
538      */
539     public void addToParameters (final String name, final Object value)
540     {
541100       mParameters.put(name, value);
542100    }
543  
544     /**
545      * Used for resetting this to an initial state so that this object could be
546      * reused again.
547      *
548      * @throws LoggingException if an error occurs.
549      */
550     public void reset ()
551           throws LoggingException
552     {
553100       mNestedEntry = null;
554100       mParentEntry = null;
555100       mTimestamp = null;
556100       mLogLevel = null;
557100       mBusinessImpact = null;
558100       mCategory = null;
559100       mNodeId = null;
560100       mInstanceId = null;
561100       mTrackingNumber = null;
562100       mSymbol = null;
563100       mSymbolId = null;
564100       mMessage = null;
565100       mSourceClass = null;
566100       mSourceMethod = null;
567100       mSolution = null;
568100       mParameters.clear();
569100       mStackTraceLines.clear();
570100       mParameters.clear();
571100       mType = null;
572100    }
573  
574  }

Findings in this File

c (1) 56 : 0 Type Javadoc comment is missing an @author tag.
c (2) 265 : 7 Unused @param tag for 'type'.
c (3) 267 : 44 Expected @param tag for 'threadName'.
d (4) 267 : 0 @param argument "type" is not a parameter name.
w (5) 363 : 0 method org.jcoderz.commons.logging.LogItem.getParameterValues(String) stores return result in local before immediately returning it