KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > japex > report > ReportDataParser


1 /*
2  * ReportData.java
3  *
4  * Created on April 9, 2005, 9:08 PM
5  */

6
7 package com.sun.japex.report;
8 import org.xml.sax.*;
9 import org.xml.sax.helpers.DefaultHandler JavaDoc;
10
11 import javax.xml.parsers.SAXParserFactory JavaDoc;
12 import javax.xml.parsers.ParserConfigurationException JavaDoc;
13 import javax.xml.parsers.SAXParser JavaDoc;
14
15 import java.io.*;
16 import java.util.ArrayList JavaDoc;
17 import java.util.Map JavaDoc;
18 import java.util.HashMap JavaDoc;
19 /**
20  * parse report
21  *
22  */

23 public class ReportDataParser extends DefaultHandler JavaDoc {
24     static final String JavaDoc DRIVER = "driver";
25     static final String JavaDoc TESTCASE = "testCase";
26     
27     StringBuffer JavaDoc textBuffer;
28     Map JavaDoc _reports;
29     TrendReportParams _params;
30
31     ResultPerDriver _resultPerDriver = null;
32     boolean _driverStart = false;
33     boolean _testStart = false;
34     String JavaDoc _currentDriverName = null;
35     String JavaDoc _currentTestName = null;
36     
37     
38     /** Creates a new instance of ReportData */
39     public ReportDataParser(TrendReportParams params) {
40         _params = params;
41     }
42     public Map JavaDoc getReports() {
43         return _reports;
44     }
45     //===========================================================
46
// SAX DocumentHandler methods
47
//===========================================================
48

49     public void startDocument()
50     throws SAXException
51     {
52         //do nothing
53
}
54
55     public void endDocument()
56     throws SAXException
57     {
58         //do nothing
59
}
60
61     public void startElement(String JavaDoc namespaceURI,
62                              String JavaDoc sName, // simple name
63
String JavaDoc qName, // qualified name
64
Attributes attrs)
65     throws SAXException
66     {
67         String JavaDoc eName = sName; // element name
68
if ("".equals(eName)) eName = qName; // not namespaceAware
69

70         if (eName.equals(DRIVER)) {
71 // System.out.println("Start: " + eName);
72
if (attrs != null) {
73                 for (int i = 0; i < attrs.getLength(); i++) {
74                     String JavaDoc aName = attrs.getLocalName(i); // Attr name
75
if ("".equals(aName)) aName = attrs.getQName(i);
76 // System.out.println("att: " + aName + "=" +attrs.getValue(i) + "param.driver="+_params.driver());
77

78                     if (_params.isDriverSpecified()) {
79                         if (aName.equals("name") && attrs.getValue(i).equals(_params.driver())) {
80 //System.out.println("**Driver STart *");
81
_driverStart = true;
82                             _resultPerDriver = new ResultPerDriver();
83                             _currentDriverName = attrs.getValue(i);
84                         }
85                     }
86                 }
87             }
88         } else if (_driverStart) {
89             if (eName.equals(TESTCASE)) {
90                 if (attrs != null) {
91                     for (int i = 0; i < attrs.getLength(); i++) {
92                         String JavaDoc aName = attrs.getLocalName(i); // Attr name
93
if ("".equals(aName)) aName = attrs.getQName(i);
94                         if (aName.equals("name")) {
95                             _currentTestName = attrs.getValue(i);
96                         }
97                     }
98                 }
99                 _testStart = true;
100             }
101         }
102     }
103
104     public void endElement(String JavaDoc namespaceURI,
105                            String JavaDoc sName, // simple name
106
String JavaDoc qName // qualified name
107
)
108     throws SAXException
109     {
110         String JavaDoc eName = sName; // element name
111
if ("".equals(eName)) eName = qName; // not namespaceAware
112
// System.out.println("end element:"+eName);
113
if(eName.equals(DRIVER)) {
114             if (_driverStart) {
115                 if (_reports == null) {
116                     _reports = new HashMap JavaDoc();
117                 }
118                 _reports.put(_currentDriverName, _resultPerDriver);
119                 _resultPerDriver = null;
120                 //ResultPerDriver test = (ResultPerDriver)_reports.get(_currentDriverName);
121
//System.out.println(test.getAritMean());
122
}
123 // System.out.println("end driver: " + eName);
124
_driverStart = false;
125         } else if (_driverStart) {
126             if (_testStart) {
127                 if (eName.equals("resultValue")) {
128                     _resultPerDriver.addResult(_currentTestName, textBuffer.toString());
129                 } else if (eName.equals(TESTCASE)) {
130                     _testStart = false;
131                 }
132             } else {
133                 if (eName.equals("resultHarmMean")) {
134 // System.out.println("resultHarmMean: " + textBuffer.toString());
135

136                     _resultPerDriver.setHarmMean(textBuffer.toString());
137 // System.out.println("resultHarmMean: " + _resultPerDriver.getHarmMean());
138
} else if (eName.equals("resultGeomMean")) {
139                     _resultPerDriver.setGeomMean(textBuffer.toString());
140                 } else if (eName.equals("resultAritMean")) {
141                     _resultPerDriver.setAritMean(textBuffer.toString());
142                 }
143             }
144         }
145         textBuffer = null;
146     }
147
148     public void characters(char buf[], int offset, int len)
149     throws SAXException
150     {
151         String JavaDoc s = new String JavaDoc(buf, offset, len);
152         if (textBuffer == null) {
153            textBuffer = new StringBuffer JavaDoc(s);
154         } else {
155            textBuffer.append(s);
156         }
157     }
158     
159 }
160
Popular Tags