70bad863e00d6b858a625a7019cffa5b40de781d
[cfb.git] / prod / net / jaekl / cfb / analyze / Analysis.java
1 package net.jaekl.cfb.analyze;
2
3 // Copyright (C) 2015 Christian Jaekl
4
5 import java.io.FileNotFoundException;
6 import java.io.IOException;
7 import java.io.PrintWriter;
8 import java.util.Date;
9
10 import net.jaekl.cfb.xml.BugCollection;
11 import net.jaekl.qd.xml.ParseErrorHandler;
12 import net.jaekl.qd.xml.ParseHandler;
13
14 import org.xml.sax.InputSource;
15 import org.xml.sax.SAXException;
16 import org.xml.sax.XMLReader;
17 import org.xml.sax.helpers.XMLReaderFactory;
18
19 public class Analysis {
20         long m_id;
21         BugCollection m_bugCollection;
22         String m_buildNumber;
23         long m_start;   // Date.getTime() when analysis was started
24         long m_end;
25         
26         public Analysis(String buildNumber) {
27                 m_id = (-1);
28                 m_bugCollection = null;
29                 m_buildNumber = buildNumber;
30                 m_start = new Date().getTime();
31                 m_end = 0;
32         }
33         
34         public BugCollection getBugCollection() { return m_bugCollection; }
35         public long getId() { return m_id; }
36         public String getBuildNumber() { return m_buildNumber; }
37         public Date getStart() { return new Date(m_start); }
38         public Date getEnd() { return (0 == m_end ? null : new Date(m_end)); }  // the end time (when FindBugs was done analyzing)
39
40         public void setBugCollection(BugCollection bugs) { m_bugCollection = bugs; }
41         public void setId(long id) { m_id = id; }
42         public void setStart(Date start) { m_start = start.getTime(); }
43         public void setEnd(Date date) { m_end = date.getTime(); }
44         
45         public void parse(InputSource xml) throws FileNotFoundException, IOException, SAXException 
46         {
47                 m_bugCollection = new BugCollection();
48                 
49             XMLReader reader = XMLReaderFactory.createXMLReader();
50             ParseHandler ph = new ParseHandler(m_bugCollection);
51             ParseErrorHandler peh = new ParseErrorHandler();
52             reader.setContentHandler(ph);
53             reader.setErrorHandler(peh);
54             reader.parse(xml);
55         }
56         
57         
58         public void dump(PrintWriter pw)
59         {
60                 if (null != m_bugCollection) {
61                         m_bugCollection.dump(pw, 2);
62                 }
63         }
64 }