Partial implementation of XML parse for FindBugs output
[cfb.git] / prod / net / jaekl / cfb / xml / SourceLine.java
1 package net.jaekl.cfb.xml;
2
3 import org.xml.sax.Attributes;
4
5 import net.jaekl.qd.xml.MissingAttributeException;
6 import net.jaekl.qd.xml.ParseResult;
7 import net.jaekl.qd.xml.XmlParseException;
8
9 public class SourceLine extends ParseResult {
10
11         static final String ROOT_TAG = "SourceLine";
12         static final String[] INTERNAL = { };
13         static final Object[][] EXTERNAL = { };
14         
15         static final String ATTR_CLASS_NAME = "classname";
16         static final String ATTR_START = "start";
17         static final String ATTR_END = "end";
18         
19         String m_className;
20         int m_start;
21         int m_end;
22
23         public SourceLine() {
24                 super(ROOT_TAG, INTERNAL, EXTERNAL);
25                 m_className = null;
26                 m_start = m_end = (-1);
27         }       
28         
29         @Override
30         public void endContents(String uri, String localName, String qName,     String chars, Attributes attr) 
31                 throws XmlParseException 
32         {
33                 String scratch;
34                 
35                 m_className = getRequiredAttr(localName, attr, ATTR_CLASS_NAME);
36                 
37                 scratch = getRequiredAttr(localName, attr, ATTR_START);
38                 m_start = Integer.parseInt(scratch);
39                 
40                 scratch = getRequiredAttr(localName, attr, ATTR_END);
41                 m_end = Integer.parseInt(scratch);
42         }
43         
44         String getRequiredAttr(String tagName, Attributes attr, String attrName)
45                 throws MissingAttributeException
46         {
47                 String result = attr.getValue(attrName);
48                 if (null == result) {
49                         throw new MissingAttributeException(tagName, attrName);
50                 }
51                 return result;
52         }
53
54         @Override
55         public void endExternal(String uri, String localName, String qName)
56                 throws XmlParseException 
57         {
58                 // no-op
59         }
60
61 }