View Javadoc
1 /*** 2 * Report.java 3 * 4 * Project: Dependency Tool 5 * 6 * WHEN WHO WHAT 7 * 06.06.2003 pko initial public release 8 * 29.10.2002 pko creation 9 * 10 * Copyright 2003 ELCA Informatique SA 11 * Av. de la Harpe 22-24, 1000 Lausanne 13, Switzerland 12 * www.elca.ch 13 * 14 * This library is free software; you can redistribute it and/or 15 * modify it under the terms of the GNU Lesser General Public License 16 * as published by the Free Software Foundation; either version 2.1 of 17 * the License, or (at your option) any later version. 18 * 19 * This library is distributed in the hope that it will be useful, but 20 * WITHOUT ANY WARRANTY; without even the implied warranty of 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 * Lesser General Public License for more details. 23 * 24 * You should have received a copy of the GNU Lesser General Public 25 * License along with this library; if not, write to the Free Software 26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 27 * USA 28 */ 29 30 package ch.elca.dependency.report; 31 32 import javax.swing.tree.DefaultMutableTreeNode; 33 34 import org.apache.log4j.Logger; 35 36 import ch.elca.dependency.core.DependencyModel; 37 import ch.elca.dependency.util.StringManager; 38 39 /*** 40 * <code>Report</code> is a façade to the ch.elca.dependency.report 41 * package. Use it to create, format and output Reports on a analyzed 42 * Project. As the constructor of this class has no public access, use 43 * the ReportManager.createReport() method to get an Instance of this 44 * class. 45 * 46 * @see ch.elca.dependency.report.ReportManager 47 * @see ch.elca.dependency.report.ReportHandler 48 * @see ch.elca.dependency.report.ReportFormatter 49 * @see ch.elca.dependency.report.ReportInfo 50 * @see ch.elca.dependency.rawmodel.RawModel 51 * @see ch.elca.dependency.core.DependencyModel 52 * 53 * @tbd write cycles ReportInfo. 54 * @tbd report needs not receiving a DependencyModel. 55 * 56 * @author Pawel Kowalski 57 * @version 1.0-beta 58 */ 59 public final class Report { 60 61 /*** 62 * Log4j Logger. 63 */ 64 private static final Logger LOG = Logger.getLogger(Report.class); 65 66 /*** 67 * A StringManager to access Strings 68 */ 69 private static final StringManager STRING_MANAGER = StringManager.getManager(Report.class); 70 71 /*** 72 * An Object identifying the indent property. 73 */ 74 static final Object INDENT = new Object(); 75 76 /*** 77 * An Object identifying the header property. 78 */ 79 static final Object IS_HEADER = new Object(); 80 81 /*** 82 * A CompositeReportInfo holding all other ReportInfos. 83 */ 84 private CompositeReportInfo m_compositeReportInfo = null; 85 86 /*** 87 * A ClassLoader to load ReportInfos dynamicly. 88 */ 89 private ClassLoader m_classLoader = null; 90 91 /*** 92 * A ReportHandler to output formatted report text. 93 */ 94 private ReportHandler m_reportHandler = new ConsoleHandler(); 95 96 /*** 97 * A ReportFormatter to format reports. 98 */ 99 private ReportFormatter m_reportFormatter = new TextFormatter(); 100 101 //****************************************************************************************/ 102 // constructor 103 //****************************************************************************************/ 104 105 /*** 106 * Creates a new <code>Report</code> instance. 107 */ 108 public Report() { 109 m_classLoader = Thread.currentThread().getContextClassLoader(); 110 m_compositeReportInfo = new CompositeReportInfo(); 111 } 112 113 /*** 114 * Creates a new <code>Report</code> instance ant initializes it 115 * with the specified <code>DependencyModel</code> and <code>RawModel</code>. 116 * 117 * @param filteredModel a <code>DependencyModel</code> value 118 * @param rawModel a <code>RawModel</code> value 119 */ 120 public Report(DependencyModel dependencyModel) { 121 this(); 122 initReport(dependencyModel); 123 } 124 125 //****************************************************************************************/ 126 // init methods 127 //****************************************************************************************/ 128 129 /*** 130 * Init this Report with a <code>DependencyModel</code> and a 131 * <code>RawModel</code>. 132 * 133 * @param filteredModel a <code>DependencyModel</code> value 134 * @param rawModel a <code>RawModel</code> value 135 */ 136 public void initReport(DependencyModel dependencyModel) { 137 m_compositeReportInfo.initReportInfo(dependencyModel); 138 report(); 139 } 140 141 /*** 142 * Reinitialize this Report. 143 */ 144 public void reinitReport() { 145 m_compositeReportInfo.reinitReportInfo(); 146 report(); 147 } 148 149 /*** 150 * Cause the underlying <code>ReportInfo</code> to report the 151 * project. 152 */ 153 private void report() { 154 m_compositeReportInfo.report(); 155 } 156 157 //****************************************************************************************/ 158 // setter methods 159 //****************************************************************************************/ 160 161 /*** 162 * Set <code>ReportFormatter</code> which will be used to format 163 * reports (use the ReportFormatter's fully Qualified class name 164 * to do so). This method will be used mainly by the jakarta 165 * Digester during the construction of this Report. 166 * 167 * @param reportFormatterClassName a <code>String</code> value 168 * 169 * @exception ReportException if an error occurs 170 */ 171 public void setReportFormatter(String reportFormatterClassName) 172 throws ReportException { 173 try { 174 Class reportFormatterClass 175 = m_classLoader.loadClass(reportFormatterClassName); 176 ReportFormatter reportFormatter 177 = (ReportFormatter)reportFormatterClass.newInstance(); 178 setReportFormatter(reportFormatter); 179 } catch (Exception ex) { 180 ReportException repEx 181 = new ReportException(ReportException.COULD_NOT_SET_FORMATTER, ex); 182 throw repEx; 183 } 184 } 185 186 /*** 187 * Set <code>ReportFormatter</code> which will be used to format 188 * reports. 189 * 190 * @param reportFormatter a <code>ReportFormatter</code> value 191 */ 192 public void setReportFormatter(ReportFormatter reportFormatter) { 193 m_reportFormatter = reportFormatter; 194 LOG.debug(STRING_MANAGER.getString("report.formatter") + ": " + reportFormatter.getClass().getName()); 195 } 196 197 /*** 198 * Set <code>ReportHandler</code> which will be used to output the 199 * formatted Report (use to ReportHandler's fully qualified name 200 * to do so). This method will be used mainly by the jakarta 201 * Digester during the construction of this Report. 202 * 203 * @param reportHandlerClassName a <code>String</code> value 204 * 205 * @exception ReportException if an error occurs 206 */ 207 public void setReportHandler(String reportHandlerClassName) 208 throws ReportException { 209 try { 210 Class reportHandlerClass 211 = m_classLoader.loadClass(reportHandlerClassName); 212 ReportHandler reportHandler 213 = (ReportHandler)reportHandlerClass.newInstance(); 214 reportHandler.setFileName(m_reportHandler.getFileName()); 215 setReportHandler(reportHandler); 216 } catch (Exception ex) { 217 ReportException repEx 218 = new ReportException(ReportException.COULD_NOT_SET_HANDLER, ex); 219 throw repEx; 220 } 221 } 222 223 /*** 224 * Set <code>ReportHandler</code> which will be used to output the 225 * formatted Report. 226 * 227 * @param reportHandler a <code>ReportHandler</code> value 228 */ 229 public void setReportHandler(ReportHandler reportHandler) { 230 m_reportHandler = reportHandler; 231 LOG.debug(STRING_MANAGER.getString("report.handler") + ": " + reportHandler.getClass().getName()); 232 } 233 234 /*** 235 * Set the filename of the File the Reportt will be written into. 236 * 237 * @param filename a <code>String</code> value 238 */ 239 public void setOutputFile(String filename) { 240 m_reportHandler.setFileName(filename); 241 LOG.debug(STRING_MANAGER.getString("report.output.file") + ": " + filename); 242 } 243 244 //****************************************************************************************/ 245 // format methods 246 //****************************************************************************************/ 247 248 /*** 249 * Format this report. 250 * 251 * @return a <code>String</code> value 252 */ 253 public String formatReport() { 254 return formatReport(m_reportFormatter); 255 } 256 257 /*** 258 * Format this report with the specified <code>ReportFormatter</code>. 259 * 260 * @param reportFormatter a <code>ReportFormatter</code> value 261 * 262 * @return a <code>String</code> value 263 */ 264 public String formatReport(ReportFormatter reportFormatter) { 265 DefaultMutableTreeNode rootNode = m_compositeReportInfo.getReportInfoTree(); 266 return reportFormatter.format(rootNode); 267 } 268 269 //****************************************************************************************/ 270 // output methods 271 //****************************************************************************************/ 272 273 /*** 274 * Output this report. 275 * 276 * @exception ReportException if an error occurs 277 */ 278 public void outputReport() throws ReportException { 279 String formattedReport = formatReport(); 280 outputReport(formattedReport, m_reportHandler); 281 } 282 283 /*** 284 * Output this report with the specified <code>ReportHandler</code>. 285 * 286 * @param reportHandler a <code>ReportHandler</code> value 287 * 288 * @exception ReportException if an error occurs 289 */ 290 public void outputReport(ReportHandler reportHandler) throws ReportException { 291 String formattedReport = formatReport(); 292 outputReport(formattedReport, reportHandler); 293 } 294 295 /*** 296 * Output the specified report. 297 * 298 * @param report a <code>String</code> value 299 * 300 * @exception ReportException if an error occurs 301 */ 302 public void outputReport(String report) throws ReportException { 303 outputReport(report, m_reportHandler); 304 } 305 306 /*** 307 * Output the specified report with the specified <code>ReportHandler</code>. 308 * 309 * @param report a <code>String</code> value 310 * @param reportHandler a <code>ReportHandler</code> value 311 * 312 * @exception ReportException if an error occurs 313 */ 314 public void outputReport(String report, ReportHandler reportHandler) 315 throws ReportException { 316 try { 317 reportHandler.output(report); 318 } catch (Exception e) { 319 ReportException repEx 320 = new ReportException(ReportException.COULD_NOT_WRITE_REPORT, e); 321 throw repEx; 322 } 323 } 324 325 //*********************************************************************************/ 326 // add a ReportInfo 327 //*********************************************************************************/ 328 329 /*** 330 * Add a <code>ReportInfo</code> Object specified by its fully 331 * qualified classname to this Report. This method will be used 332 * mainly during the creation of this <code>Report</code>. 333 * 334 * @param reportInfoClassName a <code>String</code> value 335 * 336 * @exception ReportException if an error occurs 337 */ 338 public void addReportInfo(String reportInfoClassName) throws ReportException { 339 try { 340 Class reportInfoClass = m_classLoader.loadClass(reportInfoClassName); 341 addReportInfo(reportInfoClass); 342 } catch (Exception ex) { 343 ReportException repEx 344 = new ReportException(ReportException.COULD_NOT_ADD_REPORT_INFO, ex); 345 throw repEx; 346 } 347 } 348 349 /*** 350 * Add a <code>ReportInfo</code> Object specified by its class to 351 * this Report. 352 * 353 * @param reportInfoClass a <code>Class</code> value 354 * @exception ReportException if an error occurs 355 */ 356 public void addReportInfo(Class reportInfoClass) throws ReportException { 357 try { 358 ReportInfo reportInfo = (ReportInfo)reportInfoClass.newInstance(); 359 m_compositeReportInfo.addReportInfo(reportInfo); 360 LOG.debug(STRING_MANAGER.getString("report.reportinfo.added") + ": " + reportInfoClass.getName()); 361 } catch (Exception ex) { 362 ReportException repEx 363 = new ReportException(ReportException.COULD_NOT_ADD_REPORT_INFO, ex); 364 throw repEx; 365 } 366 } 367 }

This page was automatically generated by Maven