Unit testing: confirm that Analyzer can parse some sample XML
[cfb.git] / prod / net / jaekl / cfb / xml / SourceLine.java
1 package net.jaekl.cfb.xml;
2
3 import java.io.PrintWriter;
4
5 import net.jaekl.qd.xml.MissingAttributeException;
6 import net.jaekl.qd.xml.ParseResult;
7 import net.jaekl.qd.xml.XmlParseException;
8
9 import org.xml.sax.Attributes;
10
11 public class SourceLine extends ParseResult {
12
13         static final String TAG = "SourceLine";
14         static final String[] INTERNAL = { };
15         static final Object[][] EXTERNAL = { };
16         
17         static final String ATTR_CLASS_NAME = "classname";
18         static final String ATTR_START = "start";
19         static final String ATTR_END = "end";
20         
21         String m_className;
22         int m_start;
23         int m_end;
24
25         public SourceLine() {
26                 super(TAG, INTERNAL, EXTERNAL);
27                 m_className = null;
28                 m_start = m_end = (-1);
29         }       
30         
31         @Override
32         public void handleMainAttributes(Attributes attr) throws MissingAttributeException {
33                 String scratch;
34                 
35                 m_className = getRequiredAttr(TAG, attr, ATTR_CLASS_NAME);
36                 
37                 scratch = getOptionalAttr(attr, ATTR_START, "-1");
38                 m_start = Integer.parseInt(scratch);
39                 
40                 scratch = getOptionalAttr(attr, ATTR_END, "-1");
41                 m_end = Integer.parseInt(scratch);
42         }
43         
44         @Override
45         public void endContents(String uri, String localName, String qName,     String chars) 
46                 throws XmlParseException 
47         {
48                 // no-op
49         }
50         
51         @Override
52         public void endExternal(String uri, String localName, String qName)
53                 throws XmlParseException 
54         {
55                 // no-op
56         }
57         
58         @Override
59         public void dump(PrintWriter pw, int indent) 
60         {
61                 super.dump(pw, indent);
62                 String tab = String.format("%" + (indent + 2) + "s", "");
63                 
64                 pw.println(tab + m_className + " (" + m_start + " .. " + m_end + ")");
65         }
66 }