900cd1cfd37c1f9fa6fa5643b624dbf635d5fb38
[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
6 import org.xml.sax.Attributes;
7
8 import net.jaekl.qd.xml.MissingAttributeException;
9 import net.jaekl.qd.xml.ParseResult;
10 import net.jaekl.qd.xml.XmlParseException;
11
12 public class BugInstance extends ParseResult {
13
14         static final String TAG = "BugInstance";
15         static final String[] INTERNAL = {  };
16         static final Object[][] EXTERNAL = { { BugClass.TAG, BugClass.class},
17                                                  { BugMethod.TAG, BugMethod.class},
18                                                  { LocalVariable.TAG, LocalVariable.class},
19                                                  { SourceLine.TAG, SourceLine.class} };
20         static final String TYPE = "type";
21
22         String m_type;
23         ArrayList<BugClass> m_classes;
24         ArrayList<BugMethod> m_methods;
25         ArrayList<LocalVariable> m_locals;
26         ArrayList<SourceLine> m_lines;
27         
28         public BugInstance() {
29                 super(TAG, INTERNAL, EXTERNAL);
30                 
31                 m_type = null;
32                 m_classes = new ArrayList<BugClass>();
33                 m_methods = new ArrayList<BugMethod>();
34                 m_locals = new ArrayList<LocalVariable>();
35                 m_lines = new ArrayList<SourceLine>();
36         }
37         
38         @Override
39         public void endContents(String uri, String localName, String qName, String chars) 
40                 throws XmlParseException 
41         {
42                 // no-op
43         }
44
45         @Override
46         public void endExternal(String uri, String localName, String qName)
47                 throws XmlParseException 
48         {
49                 if (BugClass.TAG.equals(localName)) {
50                         ParseResult[] collected = collectParsedChildren(BugClass.class);
51                         for (ParseResult pr : collected) {
52                                 assert(pr instanceof BugClass);
53                                 m_classes.add((BugClass) pr);
54                         }
55                 }
56                 else if (BugMethod.TAG.equals(localName)) {
57                         ParseResult[] collected = collectParsedChildren(BugMethod.class);
58                         for (ParseResult pr : collected) {
59                                 assert(pr instanceof BugMethod);
60                                 m_methods.add((BugMethod)pr);
61                         }                       
62                 }
63                 else if (LocalVariable.TAG.equals(localName)) {
64                         ParseResult[] collected = collectParsedChildren(LocalVariable.class);
65                         for (ParseResult pr : collected) {
66                                 assert(pr instanceof LocalVariable);
67                                 m_locals.add((LocalVariable)pr);
68                         }                       
69                 }
70                 else if (SourceLine.TAG.equals(localName)) {
71                         ParseResult[] collected = collectParsedChildren(SourceLine.class);
72                         for (ParseResult pr : collected) {
73                                 assert(pr instanceof SourceLine);
74                                 m_lines.add((SourceLine)pr);
75                         }
76                 }
77         }
78         
79         @Override
80         public void handleMainAttributes(Attributes attr) throws MissingAttributeException
81         {
82                 m_type = this.getRequiredAttr(TAG, attr, TYPE);
83         }
84
85         @Override 
86         public void dump(PrintWriter pw, int indent)
87         {
88                 int childIndent = indent + 2;
89                 String margin = String.format("%" + indent + "s", "");
90                 
91                 pw.println(margin + TAG + " (" + m_type + ")");
92                 for (BugClass bc : m_classes) {
93                         bc.dump(pw, childIndent);
94                 }
95                 for (BugMethod bm : m_methods) {
96                         bm.dump(pw, childIndent);
97                 }
98                 for (LocalVariable lv : m_locals) {
99                         lv.dump(pw, childIndent);
100                 }
101                 for (SourceLine sl : m_lines) {
102                         sl.dump(pw, childIndent);
103                 }
104         }
105 }