1 7 package org.hammurapi.inspectors.metrics; 8 9 import java.io.File ; 10 import java.io.FileInputStream ; 11 import java.io.FileNotFoundException ; 12 import java.io.IOException ; 13 import java.io.InputStream ; 14 15 import javax.xml.parsers.DocumentBuilderFactory ; 16 import javax.xml.parsers.ParserConfigurationException ; 17 import javax.xml.transform.TransformerException ; 18 19 import org.apache.xpath.XPathAPI; 20 import org.hammurapi.HammurapiException; 21 import org.w3c.dom.Document ; 22 import org.w3c.dom.Element ; 23 import org.w3c.dom.Node ; 24 import org.w3c.dom.traversal.NodeIterator; 25 import org.xml.sax.SAXException ; 26 27 33 public class DomArchitecturalMappingSource { 34 private Element holder; 35 36 public DomArchitecturalMappingSource(InputStream in) throws HammurapiException { 37 load(in); 38 } 39 40 public DomArchitecturalMappingSource(File f) throws HammurapiException { 41 try { 42 load(new FileInputStream (f)); 43 } catch (FileNotFoundException e) { 44 throw new HammurapiException("File not found: "+f.getAbsolutePath(), e); 45 } 46 } 47 48 private void load(InputStream in) throws HammurapiException { 49 try { 50 Document document=DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in); 51 holder=document.getDocumentElement(); 52 } catch (ParserConfigurationException e) { 53 throw new HammurapiException(e.toString(), e); 54 } catch (SAXException e) { 55 throw new HammurapiException(e.toString(), e); 56 } catch (IOException 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 inspectorElement; 67 while ((inspectorElement=(Element ) inspectorsIterator.nextNode())!=null) { 68 ArchitecturalLayerMapping te = new ArchitecturalLayerMapping(inspectorElement); 69 architecturalLayerMappingSet.put( te.getName(), te); 70 } 71 72 } catch (TransformerException 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 teNode; 85 while ((teNode = it.nextNode()) != null) { 86 if (teNode instanceof Element ) { 87 aComplexityMappingTable = new ArchitecturalComplexityMappingTable( 88 (Element ) teNode); 89 } 90 } 91 92 } catch (Exception e) { 93 new HammurapiException(e); 94 } 95 return aComplexityMappingTable; 96 } 97 98 } 99 | Popular Tags |