Add ability to load previously found bugs back out of the database.
[cfb.git] / prod / net / jaekl / cfb / xml / BugMethod.java
index 2e001b23abe93116f71c47782bc1f21b428308e6..f05c510af39ddd412df0744439cb3edcb445b032 100644 (file)
@@ -1,9 +1,11 @@
 package net.jaekl.cfb.xml;
 
+import java.io.PrintWriter;
 import java.util.ArrayList;
 
 import org.xml.sax.Attributes;
 
+import net.jaekl.qd.xml.MissingAttributeException;
 import net.jaekl.qd.xml.ParseResult;
 import net.jaekl.qd.xml.XmlParseException;
 
@@ -34,16 +36,36 @@ public class BugMethod extends ParseResult {
                m_isStatic = false;
                m_sourceLines = new ArrayList<SourceLine>();
        }
-
+       
+       public BugMethod(Long id, String methodName, String methodRole) {
+               super(TAG, INTERNAL, EXTERNAL);
+               m_className = null;
+               m_methodName = methodName;
+               m_role = methodRole;
+               m_isStatic = false;
+               m_sourceLines = new ArrayList<SourceLine>();
+       }
+       
+       public String getClassName() { return m_className; }
+       public String getMethodName() { return m_methodName; }
+       public String getRole() { return m_role; }
+       public SourceLine[] getSourceLines() { return m_sourceLines.toArray(new SourceLine[m_sourceLines.size()]); }
+       
        @Override
-       public void endContents(String uri, String localName, String qName, String chars, Attributes attr) 
-               throws XmlParseException 
+       public void handleMainAttributes(Attributes attr) throws MissingAttributeException 
        {
                m_className = getRequiredAttr(TAG, attr, CLASS_NAME);
                m_methodName = getRequiredAttr(TAG, attr, METHOD_NAME);
                m_signature = getRequiredAttr(TAG, attr, SIGNATURE);
                m_isStatic = getRequiredAttr(TAG, attr, IS_STATIC).equals(TRUE);
-               m_role = getOptionalAttr(attr, ROLE, null);
+               m_role = getOptionalAttr(attr, ROLE, null);             
+       }
+
+       @Override
+       public void endContents(String uri, String localName, String qName, String chars) 
+               throws XmlParseException 
+       {
+               // no-op
        }
 
        @Override
@@ -58,5 +80,27 @@ public class BugMethod extends ParseResult {
                        }
                }
        }
+       
+       @Override
+       public void dump(PrintWriter pw, int indent) 
+       {
+               super.dump(pw, indent);
+               String tab = String.format("%" + (indent + 2) + "s", "");
+               
+               pw.println(tab 
+                               + (m_isStatic ? "static" : "")
+                               + m_className 
+                               + "."
+                               + m_methodName 
+                               + m_signature);
+               if (null != m_role) {
+                       pw.println(tab + ROLE + "=" + m_role);
+               }
+               if (null != m_sourceLines) {
+                       for (SourceLine sl : m_sourceLines) {
+                               sl.dump(pw, indent + 2);
+                       }
+               }
+       }
 
 }