Improve XML parsing to handle attributes as well.
[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         @Override
30         public void handleMainAttributes(Attributes attr) throws MissingAttributeException 
31         {
32                 m_className = getRequiredAttr(TAG, attr, CLASS_NAME);
33         }
34         
35         @Override
36         public void endContents(String uri, String localName, String qName,     String chars) 
37                 throws XmlParseException 
38         {
39         }
40
41     @Override
42     public void endExternal(String uri, String localName, String qName) 
43         throws XmlParseException
44     {
45                 if (SourceLine.TAG.equals(localName)) {
46                         ParseResult[] collected = collectParsedChildren(SourceLine.class);
47                         for (ParseResult pr : collected) {
48                                 assert(pr instanceof SourceLine);
49                                 m_lines.add((SourceLine)pr);
50                         }
51                 }
52     }
53     
54         @Override
55         public void dump(PrintWriter pw, int indent) 
56         {
57                 super.dump(pw, indent);
58                 String tab = String.format("%" + (indent + 2) + "s", "");
59                 
60                 pw.println(tab + CLASS_NAME + "=" + m_className);
61                 if (null != m_lines) {
62                         for (SourceLine sl : m_lines) {
63                                 sl.dump(pw, indent + 2);
64                         }
65                 }
66         }
67 }