01: /*
02: * Created on Jul 16, 2004
03: *
04: * TODO To change the template for this generated file go to
05: * Window - Preferences - Java - Code Style - Code Templates
06: */
07: package org.hammurapi.inspectors.metrics;
08:
09: import java.util.Enumeration;
10: import java.util.Hashtable;
11:
12: import org.apache.xpath.CachedXPathAPI;
13: import org.apache.xpath.XPathAPI;
14: import org.hammurapi.HammurapiException;
15: import org.w3c.dom.Document;
16: import org.w3c.dom.Element;
17: import org.w3c.dom.Node;
18: import org.w3c.dom.traversal.NodeIterator;
19:
20: /**
21: * @author MUCBJ0
22: *
23: * TODO To change the template for this generated type comment go to
24: * Window - Preferences - Java - Code Style - Code Templates
25: */
26: public class ArchitecturalComplexityMappingTable extends Hashtable {
27:
28: public ArchitecturalComplexityMappingTable(Element holder)
29: throws HammurapiException {
30: super ();
31: try {
32: CachedXPathAPI cxpa = new CachedXPathAPI();
33: NodeIterator it = XPathAPI.selectNodeIterator(holder,
34: "ComplexityMapping");
35:
36: Node teNode;
37: while ((teNode = it.nextNode()) != null) {
38: if (teNode instanceof Element) {
39: ArchitecturalComplexityMapping acm = new ArchitecturalComplexityMapping(
40: (Element) teNode);
41: this .put(acm.getName(), acm);
42: }
43: }
44: } catch (Exception e) {
45: throw new HammurapiException(e);
46: }
47: }
48:
49: public Element toDom(Document document){
50:
51: Element ret=document.createElement("ComplexityMappingTable");
52: ret.setAttribute("size", String.valueOf(this.size()));
53: Enumeration enum = this.keys();
54: while (enum.hasMoreElements()) {
55: String key = (String) enum.nextElement();
56: Element cmcat=document.createElement("ComplexityMapping");
57: ArchitecturalComplexityMapping cat = (ArchitecturalComplexityMapping)get(key);
58: cmcat.setAttribute("name", cat.getName() );
59: cmcat.setAttribute("rate", String.valueOf(cat.getRate()) );
60: ret.appendChild(cmcat);
61: }
62: return ret;
63:
64: }
65:
66: }
|