root/trunk/src/java/org/jcoderz/phoenix/report/FindingType.java

Revision 1509, 5.7 kB (checked in by amandel, 3 years ago)

Take care for findings.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1/*
2 * $Id$
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 */
33package org.jcoderz.phoenix.report;
34
35import java.util.HashMap;
36import java.util.HashSet;
37import java.util.Map;
38import java.util.Set;
39import java.util.logging.Logger;
40
41import org.jcoderz.commons.util.StringUtil;
42
43/**
44 * Base class identifies the unique type of a finding.
45 *
46 * @author Andreas Mandel
47 */
48public class FindingType
49{
50    private static final String CLASSNAME = FindingType.class.getName();
51    private static final Logger LOGGER = Logger.getLogger(CLASSNAME); 
52    private static final Map<String, FindingType> 
53        FINDING_TYPES = new HashMap<String, FindingType>();
54    private static final Set<Origin> 
55        INITIALIZED_FINDING_TYPES = new HashSet<Origin>();
56    private final String mSymbol;
57    private final String mShortText;
58    private final String mDescription;
59
60
61    protected FindingType (String symbol, String shortText, String description)
62    {
63        mSymbol = symbol.intern();
64        mShortText
65            = StringUtil.isNullOrBlank(shortText) ? mSymbol : shortText;
66        mDescription
67            = StringUtil.isNullOrBlank(description) ? mShortText : description;
68        FINDING_TYPES.put(mSymbol, this);
69    }
70
71   /**
72    * Retrieves the finding type based on it's symbol.
73    * @param symbol the symbol to look up.
74    * @return the findings type that holds the given symbol.
75    */
76   public static FindingType fromString (String symbol)
77   {
78      // touch the class to get the static initializer to be called
79      LazyInit.class.getName();
80
81      FindingType result = FINDING_TYPES.get(symbol);
82      if (result == null)
83      {
84         result = new FindingType(symbol, null, null);
85      }
86      return result;
87   }
88
89   /**
90    * Initializes the findings with the given origin.
91    * @param origin the class of findings to be initialized.
92    */
93   public static void initialize (Origin origin)
94   {
95       if (!INITIALIZED_FINDING_TYPES.contains(origin))
96       {
97           INITIALIZED_FINDING_TYPES.add(origin);
98           if (Origin.CHECKSTYLE.equals(origin))
99           {
100               CheckstyleFindingType.initialize();
101           }
102           else if (Origin.COVERAGE.equals(origin))
103           {
104               // No stuff here
105           }
106           else if (Origin.FINDBUGS.equals(origin))
107           {
108               FindBugsFindingType.initialize();
109           }
110           else if (Origin.PMD.equals(origin))
111           {
112               PmdFindingType.initialize();
113           }
114           else if (Origin.CPD.equals(origin))
115           {
116               CpdFindingType.initialize();
117           }
118           else if (Origin.SYSTEM.equals(origin))
119           {
120               SystemFindingType.initialize();
121           }
122           else
123           {
124               GenericReportReader.initialize(origin);
125           }
126       }
127   }
128   
129   /**
130    * Returns the symbol of this finding type.
131    * @return the symbol of this finding type.
132    */
133   public String getSymbol ()
134   {
135      return mSymbol;
136   }
137
138   /**
139    * Returns the short text description of this finding type.
140    * Should be a one liner.
141    * @return the short text description of this finding type.
142    */
143   public String getShortText ()
144   {
145      return mShortText;
146   }
147
148   /**
149    * Returns a long description of this finding type. Might
150    *   contain html markup.
151    * @return the long description of this finding type.
152    */
153   public String getDescription ()
154   {
155      return mDescription;
156   }
157
158   /**
159    * Returns the finding type symbol as its string representation.
160    * @return the finding type symbol as its string representation.
161    */
162   public String toString ()
163   {
164      return mSymbol;
165   }
166
167   /** {@inheritDoc} */
168   public int hashCode ()
169   {
170      return mSymbol.hashCode();
171   }
172
173   /** {@inheritDoc} */
174   public boolean equals (Object o)
175   {
176      return (o instanceof FindingType)
177              && mSymbol.equals(((FindingType) o).mSymbol);
178   }
179
180   protected static class LazyInit
181   {
182      static
183      {
184          initialize(Origin.CHECKSTYLE);
185          initialize(Origin.FINDBUGS);
186          initialize(Origin.PMD);
187          initialize(Origin.CPD);
188          initialize(Origin.SYSTEM);
189      }
190   }
191}
Note: See TracBrowser for help on using the browser.