KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > inspectors > metrics > DomArchitecturalMappingSource


1 /*
2  * Created on Jul 9, 2004
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */

7 package org.hammurapi.inspectors.metrics;
8
9 import java.io.File JavaDoc;
10 import java.io.FileInputStream JavaDoc;
11 import java.io.FileNotFoundException JavaDoc;
12 import java.io.IOException JavaDoc;
13 import java.io.InputStream JavaDoc;
14
15 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
16 import javax.xml.parsers.ParserConfigurationException JavaDoc;
17 import javax.xml.transform.TransformerException JavaDoc;
18
19 import org.apache.xpath.XPathAPI;
20 import org.hammurapi.HammurapiException;
21 import org.w3c.dom.Document JavaDoc;
22 import org.w3c.dom.Element JavaDoc;
23 import org.w3c.dom.Node JavaDoc;
24 import org.w3c.dom.traversal.NodeIterator;
25 import org.xml.sax.SAXException JavaDoc;
26
27 /**
28  * @author MUCBJ0
29  *
30  * TODO To change the template for this generated type comment go to
31  * Window - Preferences - Java - Code Style - Code Templates
32  */

33 public class DomArchitecturalMappingSource {
34       private Element JavaDoc holder;
35         
36         public DomArchitecturalMappingSource(InputStream JavaDoc in) throws HammurapiException {
37             load(in);
38         }
39         
40         public DomArchitecturalMappingSource(File JavaDoc f) throws HammurapiException {
41             try {
42                 load(new FileInputStream JavaDoc(f));
43             } catch (FileNotFoundException JavaDoc e) {
44                 throw new HammurapiException("File not found: "+f.getAbsolutePath(), e);
45             }
46         }
47         
48         private void load(InputStream JavaDoc in) throws HammurapiException {
49             try {
50                 Document JavaDoc document=DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in);
51                 holder=document.getDocumentElement();
52             } catch (ParserConfigurationException JavaDoc e) {
53                 throw new HammurapiException(e.toString(), e);
54             } catch (SAXException JavaDoc e) {
55                 throw new HammurapiException(e.toString(), e);
56             } catch (IOException JavaDoc e) {
57                 throw new HammurapiException(e.toString(), e);
58             }
59         }
60         
61         public ArchitecturalLayerMappingTable loadLayerMappings() throws HammurapiException {
62             ArchitecturalLayerMappingTable architecturalLayerMappingSet = new ArchitecturalLayerMappingTable();
63             
64             try {
65                 NodeIterator inspectorsIterator=XPathAPI.selectNodeIterator(holder, "ArchitecturalLayerMapping");
66                 Element JavaDoc inspectorElement;
67                 while ((inspectorElement=(Element JavaDoc) inspectorsIterator.nextNode())!=null) {
68                     ArchitecturalLayerMapping te = new ArchitecturalLayerMapping(inspectorElement);
69                     architecturalLayerMappingSet.put( te.getName(), te);
70                 }
71         
72             } catch (TransformerException JavaDoc e) {
73                 new HammurapiException(e);
74           
75             }
76             return architecturalLayerMappingSet;
77         }
78         public ArchitecturalComplexityMappingTable loadComplexityMapping() {
79
80         ArchitecturalComplexityMappingTable aComplexityMappingTable = null;
81         try {
82             NodeIterator it = XPathAPI.selectNodeIterator(holder,
83                     "ComplexityMappingTable");
84             Node JavaDoc teNode;
85             while ((teNode = it.nextNode()) != null) {
86                 if (teNode instanceof Element JavaDoc) {
87                     aComplexityMappingTable = new ArchitecturalComplexityMappingTable(
88                             (Element JavaDoc) teNode);
89                 }
90             }
91
92         } catch (Exception JavaDoc e) {
93             new HammurapiException(e);
94         }
95         return aComplexityMappingTable;
96     }
97
98 }
99
Popular Tags