001: /*
002: * Created on Jul 9, 2004
003: *
004: * TODO To change the template for this generated file go to
005: * Window - Preferences - Java - Code Style - Code Templates
006: */
007: package org.hammurapi.inspectors.metrics;
008:
009: import java.io.File;
010: import java.io.FileInputStream;
011: import java.io.FileNotFoundException;
012: import java.io.IOException;
013: import java.io.InputStream;
014:
015: import javax.xml.parsers.DocumentBuilderFactory;
016: import javax.xml.parsers.ParserConfigurationException;
017: import javax.xml.transform.TransformerException;
018:
019: import org.apache.xpath.XPathAPI;
020: import org.hammurapi.HammurapiException;
021: import org.w3c.dom.Document;
022: import org.w3c.dom.Element;
023: import org.w3c.dom.Node;
024: import org.w3c.dom.traversal.NodeIterator;
025: import org.xml.sax.SAXException;
026:
027: /**
028: * @author MUCBJ0
029: *
030: * TODO To change the template for this generated type comment go to
031: * Window - Preferences - Java - Code Style - Code Templates
032: */
033: public class DomArchitecturalMappingSource {
034: private Element holder;
035:
036: public DomArchitecturalMappingSource(InputStream in)
037: throws HammurapiException {
038: load(in);
039: }
040:
041: public DomArchitecturalMappingSource(File f)
042: throws HammurapiException {
043: try {
044: load(new FileInputStream(f));
045: } catch (FileNotFoundException e) {
046: throw new HammurapiException("File not found: "
047: + f.getAbsolutePath(), e);
048: }
049: }
050:
051: private void load(InputStream in) throws HammurapiException {
052: try {
053: Document document = DocumentBuilderFactory.newInstance()
054: .newDocumentBuilder().parse(in);
055: holder = document.getDocumentElement();
056: } catch (ParserConfigurationException e) {
057: throw new HammurapiException(e.toString(), e);
058: } catch (SAXException e) {
059: throw new HammurapiException(e.toString(), e);
060: } catch (IOException e) {
061: throw new HammurapiException(e.toString(), e);
062: }
063: }
064:
065: public ArchitecturalLayerMappingTable loadLayerMappings()
066: throws HammurapiException {
067: ArchitecturalLayerMappingTable architecturalLayerMappingSet = new ArchitecturalLayerMappingTable();
068:
069: try {
070: NodeIterator inspectorsIterator = XPathAPI
071: .selectNodeIterator(holder,
072: "ArchitecturalLayerMapping");
073: Element inspectorElement;
074: while ((inspectorElement = (Element) inspectorsIterator
075: .nextNode()) != null) {
076: ArchitecturalLayerMapping te = new ArchitecturalLayerMapping(
077: inspectorElement);
078: architecturalLayerMappingSet.put(te.getName(), te);
079: }
080:
081: } catch (TransformerException e) {
082: new HammurapiException(e);
083:
084: }
085: return architecturalLayerMappingSet;
086: }
087:
088: public ArchitecturalComplexityMappingTable loadComplexityMapping() {
089:
090: ArchitecturalComplexityMappingTable aComplexityMappingTable = null;
091: try {
092: NodeIterator it = XPathAPI.selectNodeIterator(holder,
093: "ComplexityMappingTable");
094: Node teNode;
095: while ((teNode = it.nextNode()) != null) {
096: if (teNode instanceof Element) {
097: aComplexityMappingTable = new ArchitecturalComplexityMappingTable(
098: (Element) teNode);
099: }
100: }
101:
102: } catch (Exception e) {
103: new HammurapiException(e);
104: }
105: return aComplexityMappingTable;
106: }
107:
108: }
|