KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > diagnostics > ReportGenerator


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.diagnostics;
24
25 import java.util.List JavaDoc;
26 import java.util.zip.ZipFile JavaDoc;
27 import com.sun.enterprise.diagnostics.DiagnosticException;
28 import com.sun.enterprise.diagnostics.ReportConfig;
29 import com.sun.enterprise.diagnostics.Data;
30 import com.sun.enterprise.diagnostics.collect.Collector;
31 import com.sun.enterprise.diagnostics.report.html.HTMLReportWriter;
32
33 /**
34  * Collects data, generates HTML report and archives it if mode is local
35  * @author mu125243
36  */

37 public class ReportGenerator {
38
39     protected ReportConfig config;
40     protected Collector harvester;
41     protected HTMLReportWriter reportWriter;
42
43     /** Creates a new instance of ReportGenerator */
44     public ReportGenerator(ReportConfig config, Collector harvester,
45             HTMLReportWriter reportWriter) {
46         this.config = config;
47         this.harvester = harvester;
48         this.reportWriter = reportWriter;
49     }
50     
51     /** Captures data, writes HTML report and archives it in local mode
52      * @return Data object
53      */

54     public java.util.zip.ZipFile JavaDoc generate()
55     throws DiagnosticException {
56         Data data = collectData();
57         writeReportSummary(data);
58         return archive(config.getTarget(), config.getCLIOptions().getReportFile());
59     }
60     
61     private Data collectData() throws DiagnosticException {
62         if(harvester != null) {
63             ((com.sun.enterprise.diagnostics.collect.Harvester)harvester).initialize();
64             return harvester.capture();
65         }
66         throw new DiagnosticException("Harvester null");
67     }
68     
69     protected void writeReportSummary(Data data)
70     throws DiagnosticException {
71         if(reportWriter != null)
72             reportWriter.writeReportSummary(data);
73         else
74             throw new DiagnosticException("HTML Report writer == null");
75     }
76     
77     protected ZipFile JavaDoc archive(ReportTarget target, String JavaDoc archiveName)
78     throws DiagnosticException {
79         return new Archiver().archive(config.getTarget(), archiveName);
80     }
81  }
82
Popular Tags