Restructure database code.
[cfb.git] / prod / net / jaekl / cfb / xml / messages / MessageCollection.java
1 package net.jaekl.cfb.xml.messages;
2
3 import java.util.Collection;
4 import java.util.HashMap;
5
6 import net.jaekl.qd.xml.ParseResult;
7 import net.jaekl.qd.xml.XmlParseException;
8
9 public class MessageCollection extends ParseResult {
10         static final String TAG = "MessageCollection";
11         static final String[] INTERNAL = {  };
12         static final Object[][] EXTERNAL = { { BugCategory.TAG, BugCategory.class },
13                                                  { BugPattern.TAG,  BugPattern.class }   };
14
15         HashMap<String, BugCategory> m_categories;
16         HashMap<String, BugPattern> m_patterns;
17         
18         public MessageCollection() 
19         {
20                 super(TAG, INTERNAL, EXTERNAL);
21                 m_categories = new HashMap<String, BugCategory>();
22                 m_patterns   = new HashMap<String, BugPattern>();
23         }
24         
25         public Collection<BugCategory> getCategories() { return m_categories.values(); }
26         public BugCategory getCategory(String category) { return m_categories.get(category); }
27         
28         public Collection<BugPattern> getPatterns() { return m_patterns.values(); }
29         public BugPattern getPattern(String type) { return m_patterns.get(type); }
30
31         @Override
32         public void endContents(String uri, String localName, String qName, String chars) 
33                 throws XmlParseException 
34         {
35                 // Nothing to do
36         }
37
38         @Override
39         public void endExternal(String uri, String localName, String qName) throws XmlParseException 
40         {
41                 ParseResult[] prs;
42                 
43                 prs = collectParsedChildren(BugCategory.class);
44                 if (null != prs && prs.length > 0) {
45                         for (ParseResult pr : prs) {
46                                 assert(pr instanceof BugCategory);
47                                 BugCategory bc = (BugCategory)pr;
48                                 m_categories.put(bc.getCategory(), bc);
49                         }
50                 }
51                 
52                 prs = collectParsedChildren(BugPattern.class);
53                 if (null != prs && prs.length > 0) {
54                         for (ParseResult pr : prs) {
55                                 assert(pr instanceof BugPattern);
56                                 BugPattern bp = (BugPattern) pr;
57                                 m_patterns.put(bp.getType(), bp);
58                         }
59                 }
60         }
61
62 }