Add code to load bug categories and patterns from the FindBugs messages.xml file.
[cfb.git] / prod / net / jaekl / cfb / xml / messages / MessageCollection.java
diff --git a/prod/net/jaekl/cfb/xml/messages/MessageCollection.java b/prod/net/jaekl/cfb/xml/messages/MessageCollection.java
new file mode 100644 (file)
index 0000000..cf16e23
--- /dev/null
@@ -0,0 +1,55 @@
+package net.jaekl.cfb.xml.messages;
+
+import java.util.HashMap;
+
+import net.jaekl.qd.xml.ParseResult;
+import net.jaekl.qd.xml.XmlParseException;
+
+public class MessageCollection extends ParseResult {
+       static final String TAG = "MessageCollection";
+       static final String[] INTERNAL = {  };
+       static final Object[][] EXTERNAL = { { BugCategory.TAG, BugCategory.class },
+                                                { BugPattern.TAG,  BugPattern.class }   };
+
+       HashMap<String, BugCategory> m_categories;
+       HashMap<String, BugPattern> m_patterns;
+       
+       public MessageCollection() 
+       {
+               super(TAG, INTERNAL, EXTERNAL);
+               m_categories = new HashMap<String, BugCategory>();
+               m_patterns   = new HashMap<String, BugPattern>();
+       }
+
+       @Override
+       public void endContents(String uri, String localName, String qName, String chars) 
+               throws XmlParseException 
+       {
+               // Nothing to do
+       }
+
+       @Override
+       public void endExternal(String uri, String localName, String qName) throws XmlParseException 
+       {
+               ParseResult[] prs;
+               
+               prs = collectParsedChildren(BugCategory.class);
+               if (null != prs && prs.length > 0) {
+                       for (ParseResult pr : prs) {
+                               assert(pr instanceof BugCategory);
+                               BugCategory bc = (BugCategory)pr;
+                               m_categories.put(bc.getCategory(), bc);
+                       }
+               }
+               
+               prs = collectParsedChildren(BugPattern.class);
+               if (null != prs && prs.length > 0) {
+                       for (ParseResult pr : prs) {
+                               assert(pr instanceof BugPattern);
+                               BugPattern bp = (BugPattern) pr;
+                               m_patterns.put(bp.getType(), bp);
+                       }
+               }
+       }
+
+}