Add local variable information to DB store.
[cfb.git] / prod / net / jaekl / cfb / xml / BugInstance.java
1 package net.jaekl.cfb.xml;
2
3 import java.io.PrintWriter;
4 import java.util.ArrayList;
5 import java.util.Collections;
6 import java.util.List;
7
8 import org.xml.sax.Attributes;
9
10 import net.jaekl.qd.xml.MissingAttributeException;
11 import net.jaekl.qd.xml.ParseResult;
12 import net.jaekl.qd.xml.XmlParseException;
13
14 public class BugInstance extends ParseResult {
15
16         static final String TAG = "BugInstance";
17         static final String[] INTERNAL = {  };
18         static final Object[][] EXTERNAL = { { BugClass.TAG, BugClass.class},
19                                                  { BugMethod.TAG, BugMethod.class},
20                                                  { LocalVariable.TAG, LocalVariable.class},
21                                                  { SourceLine.TAG, SourceLine.class} };
22         static final String CATEGORY = "category";
23         static final String TYPE = "type";
24
25         String m_category;
26         String m_type;
27         ArrayList<BugClass> m_classes;
28         ArrayList<BugMethod> m_methods;
29         ArrayList<LocalVariable> m_locals;
30         ArrayList<SourceLine> m_lines;
31         
32         public BugInstance() {
33                 super(TAG, INTERNAL, EXTERNAL);
34                 
35                 m_category = m_type = null;
36                 m_classes = new ArrayList<BugClass>();
37                 m_methods = new ArrayList<BugMethod>();
38                 m_locals = new ArrayList<LocalVariable>();
39                 m_lines = new ArrayList<SourceLine>();
40         }
41         
42         public String getCategory() { return m_category; }
43         public String getType() { return m_type; }
44         public List<BugClass> getClasses() { return Collections.unmodifiableList(m_classes); }
45         public List<BugMethod> getMethods() { return Collections.unmodifiableList(m_methods); }
46         public List<SourceLine> getLines() { return Collections.unmodifiableList(m_lines); }
47         public List<LocalVariable> getVariables() { return Collections.unmodifiableList(m_locals); }
48         
49         @Override
50         public void endContents(String uri, String localName, String qName, String chars) 
51                 throws XmlParseException 
52         {
53                 // no-op
54         }
55
56         @Override
57         public void endExternal(String uri, String localName, String qName)
58                 throws XmlParseException 
59         {
60                 if (BugClass.TAG.equals(localName)) {
61                         ParseResult[] collected = collectParsedChildren(BugClass.class);
62                         for (ParseResult pr : collected) {
63                                 assert(pr instanceof BugClass);
64                                 m_classes.add((BugClass) pr);
65                         }
66                 }
67                 else if (BugMethod.TAG.equals(localName)) {
68                         ParseResult[] collected = collectParsedChildren(BugMethod.class);
69                         for (ParseResult pr : collected) {
70                                 assert(pr instanceof BugMethod);
71                                 m_methods.add((BugMethod)pr);
72                         }                       
73                 }
74                 else if (LocalVariable.TAG.equals(localName)) {
75                         ParseResult[] collected = collectParsedChildren(LocalVariable.class);
76                         for (ParseResult pr : collected) {
77                                 assert(pr instanceof LocalVariable);
78                                 m_locals.add((LocalVariable)pr);
79                         }                       
80                 }
81                 else if (SourceLine.TAG.equals(localName)) {
82                         ParseResult[] collected = collectParsedChildren(SourceLine.class);
83                         for (ParseResult pr : collected) {
84                                 assert(pr instanceof SourceLine);
85                                 m_lines.add((SourceLine)pr);
86                         }
87                 }
88         }
89         
90         @Override
91         public void handleMainAttributes(Attributes attr) throws MissingAttributeException
92         {
93                 m_type = this.getRequiredAttr(TAG, attr, TYPE);
94                 m_category = this.getRequiredAttr(TAG, attr, CATEGORY);
95         }
96
97         @Override 
98         public void dump(PrintWriter pw, int indent)
99         {
100                 int childIndent = indent + 2;
101                 String margin = String.format("%" + indent + "s", "");
102                 
103                 pw.println(margin + TAG + " (" + m_type + ")");
104                 pw.println(margin + CATEGORY + " (" + m_category + ")");
105                 for (BugClass bc : m_classes) {
106                         bc.dump(pw, childIndent);
107                 }
108                 for (BugMethod bm : m_methods) {
109                         bm.dump(pw, childIndent);
110                 }
111                 for (LocalVariable lv : m_locals) {
112                         lv.dump(pw, childIndent);
113                 }
114                 for (SourceLine sl : m_lines) {
115                         sl.dump(pw, childIndent);
116                 }
117         }
118 }