Some progress toward implementing store(Analysis).
[cfb.git] / prod / net / jaekl / cfb / xml / BugClass.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 BugClass extends ParseResult {
13         
14         static final String TAG = "Class";
15         static final String[] INTERNAL = { };
16         static final Object[][] EXTERNAL = { { SourceLine.TAG, SourceLine.class} };
17
18         static final String CLASS_NAME = "classname";
19         
20         String m_className;
21         ArrayList<SourceLine> m_lines;
22         
23         public BugClass() {
24                 super(TAG, INTERNAL, EXTERNAL);
25                 m_className = "";
26                 m_lines = new ArrayList<SourceLine>();
27         }
28         
29         public String getClassName() { return m_className; }
30         public SourceLine[] getSourceLines() { return m_lines.toArray(new SourceLine[m_lines.size()]); }
31
32         @Override
33         public void handleMainAttributes(Attributes attr) throws MissingAttributeException 
34         {
35                 m_className = getRequiredAttr(TAG, attr, CLASS_NAME);
36         }
37         
38         @Override
39         public void endContents(String uri, String localName, String qName,     String chars) 
40                 throws XmlParseException 
41         {
42         }
43
44     @Override
45     public void endExternal(String uri, String localName, String qName) 
46         throws XmlParseException
47     {
48                 if (SourceLine.TAG.equals(localName)) {
49                         ParseResult[] collected = collectParsedChildren(SourceLine.class);
50                         for (ParseResult pr : collected) {
51                                 assert(pr instanceof SourceLine);
52                                 m_lines.add((SourceLine)pr);
53                         }
54                 }
55     }
56     
57         @Override
58         public void dump(PrintWriter pw, int indent) 
59         {
60                 super.dump(pw, indent);
61                 String tab = String.format("%" + (indent + 2) + "s", "");
62                 
63                 pw.println(tab + CLASS_NAME + "=" + m_className);
64                 if (null != m_lines) {
65                         for (SourceLine sl : m_lines) {
66                                 sl.dump(pw, indent + 2);
67                         }
68                 }
69         }
70 }