Project Report: fawkez

Packagesummary org.jcoderz.commons

org.jcoderz.commons.LogMessageInfoImpl

LineHitsNoteSource
1  /*
2   * $Id: LogMessageInfoImpl.java 1247 2008-11-04 20:00:09Z 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;
34  
35  import java.text.MessageFormat;
36  import java.util.ArrayList;
37  import java.util.Arrays;
38  import java.util.Collections;
39  import java.util.Iterator;
40  import java.util.List;
41  import java.util.Map;
42  import java.util.logging.Level;
43  
44  
45  /**
46   * This abstract class implements the interface
47   * {@link org.jcoderz.commons.LogMessageInfo}.
48   * <p>
49   * All parameters are stored as immutable fields.
50   * Besides the parameters from the interface, an (unique) error
51   * id must be supplied during construction.
52   *
53   * @author Michael Griffel
54   */
55  public abstract class LogMessageInfoImpl
56        implements LogMessageInfo
57  {
58     /** use this serialVersionUID for serialization. */
59     static final long serialVersionUID = 1L;
60  
61     private final String mErrorSymbol;
62     private final int mErrorId;
63     private final Level mLogLevel;
64     private final String mMessagePattern;
65     private final String mSolution;
66     private final List mParameters;
67     private final BusinessImpact mBusinessImpact;
68     private final Category mCategory;
69     private final String mApplicationName;
70     private final String mApplicationNameAbbreviation;
71     private final String mGroupName;
72     private final String mGroupNameAbbreviation;
73  
74 (1)   protected LogMessageInfoImpl (String symbol, int id, Level level,
75           String text, String solution, BusinessImpact businessImpact,
76           Category category, String[] params, String appName,
77           String appNameAbbr, String groupName, String groupNameAbbr)
78100    {
79100       mErrorSymbol = symbol;
80100       mErrorId = id;
81100       mLogLevel = level;
82100       mMessagePattern = text;
83100       mSolution = solution;
84100       mBusinessImpact = businessImpact;
85100       mCategory = category;
86100       mParameters = Collections.unmodifiableList(Arrays.asList(params));
87100       mApplicationName = appName;
88100       mApplicationNameAbbreviation = appNameAbbr;
89100       mGroupName = groupName;
90100       mGroupNameAbbreviation = groupNameAbbr;
91100    }
92  
93     /**
94      * Returns the (unique) integer representation of the log message info.
95      * This integer representation is also called the <b>error identifier</b>
96      * an is constructed as defined below:
97      * <pre>
98      *               +=========+=========+=========+=========+
99      * ID (32 bit) : |0XXX XXXX|YYYY YYYY|ZZZZ ZZZZ|ZZZZ ZZZZ|
100      *               +=========+=========+=========+=========+
101      *
102      *               XXX (7 bit)  -> application @id
103      *               YYY (8 bit)  -> group @id
104      *               ZZZ (16 bit) -> message @id
105      * </pre>
106      * <b>Note:</b>
107      * This value should also be printed in its hexadecimal string
108      * representation since it could then be easily <i>masked</i> by
109      * human readers.
110      * @return the integer representation of the log message info.
111      */
112     public final int toInt ()
113     {
114100       return mErrorId;
115     }
116  
117     /**
118      * Returns the string representation of the log message info. This is the
119      * symbolic string representation as defined in the parameter
120      * <code>symbol</code> during construction.
121      * @see java.lang.Object#toString()
122      * @return the string representation of the log message info.
123      */
124     public final String toString ()
125     {
126100       return mErrorSymbol;
127     }
128  
129     // LogMessageInfo interface
130  
131     /** {@inheritDoc} */
132     public final String getSymbol ()
133     {
134100       return mErrorSymbol;
135     }
136  
137     /** {@inheritDoc} */
138     public final Level getLogLevel ()
139     {
140100       return mLogLevel;
141     }
142  
143     /** {@inheritDoc} */
144     public final String getMessagePattern ()
145     {
146100       return mMessagePattern;
147     }
148  
149     /** {@inheritDoc} */
150     public final StringBuffer formatMessage (Map parameters, StringBuffer buffer)
151     {
152100        final StringBuffer result
153             = buffer != null ? buffer : new StringBuffer();
154         try
155         {
156100(2)          final MessageFormat formatter = new MessageFormat(getMessagePattern());
157  
158100           final List parameter = new ArrayList();
159  
160100           if (parameters != null && !getParameterList().isEmpty())
161            {
162100              final Iterator i = getParameterList().iterator();
163100              while (i.hasNext())
164               {
165100                 final String parameterName = (String) i.next();
166100(3)                final List parameterValues = (List) parameters.get(parameterName);
167100                 if (parameterValues == null || parameterValues.isEmpty())
168                  {
169100                    parameter.add(null);
170                  }
171                  else
172                  {
173100                    parameter.add(parameterValues.get(0));
174                  }
175100              }
176            }
177100           formatter.format(parameter.toArray(), result, null);
178         }
179         // could be caused by invalid message format!
1800        catch (Exception ex)
181         {
1820            result.append(parameters);
1830            result.append(' ');
1840            result.append(getMessagePattern());
185100        }
186100       return result;
187     }
188  
189     /** {@inheritDoc} */
190     public final String getSolution ()
191     {
192100       return mSolution;
193     }
194  
195     /** {@inheritDoc} */
196     public final BusinessImpact getBusinessImpact ()
197     {
198100       return mBusinessImpact;
199     }
200  
201     /** {@inheritDoc} */
202     public final Category getCategory ()
203     {
204100       return mCategory;
205     }
206  
207     /** {@inheritDoc} */
208     public final List getParameterList ()
209     {
210100       return mParameters;
211     }
212  
213     /** {@inheritDoc} */
214     public String getAppName ()
215     {
216100       return mApplicationName;
217     }
218  
219     /** {@inheritDoc} */
220     public String getAppNameAbbreviation ()
221     {
2220       return mApplicationNameAbbreviation;
223     }
224  
225     /** {@inheritDoc} */
226     public String getGroupName ()
227     {
228100       return mGroupName;
229     }
230  
231     /** {@inheritDoc} */
232     public String getGroupNameAbbreviation ()
233     {
2340       return mGroupNameAbbreviation;
235     }
236  }

Findings in this File

d (1) 74 : 14 More than 10 parameters.
c (2) 156 : 0 Line is longer than 80 characters.
c (3) 166 : 0 Line is longer than 80 characters.