1 2 package SOFA.SOFAnode.TR.Impl; 3 4 import org.w3c.dom.*; 5 6 import javax.xml.parsers.*; 7 8 import org.xml.sax.*; 9 10 import java.util.*; 11 import java.io.IOException ; 12 import java.io.File ; 13 14 21 class AssemblyDescriptorImpl { 22 23 26 private Element element; 27 28 31 private Document document; 32 33 36 private String version; 37 38 46 public AssemblyDescriptorImpl (File file) throws IOException , ParserConfigurationException, SAXException { 47 if (!file.exists()) { 48 throw new IOException ("File \"" + file.getName() + "\" doesn't exist."); 49 } 50 51 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 52 DocumentBuilder builder = factory.newDocumentBuilder(); 53 document = builder.parse(file); 54 element = document.getDocumentElement(); 55 element.normalize(); 56 initialize(); 57 } 58 59 62 private void initialize () { 63 NodeList nl = element.getChildNodes(); 64 for (int i = 0; i < nl.getLength(); i++) { 65 Node n = nl.item(i); 66 if ((n.getNodeType() == Node.ELEMENT_NODE) && (n.getNodeName().compareTo("version") == 0)) { 67 version = n.getFirstChild().getNodeValue(); 68 break; 69 } 70 } 71 } 72 73 77 public String getImplementationVersion () { 78 return version; 79 } 80 81 88 public Map getCDLEntities () { 89 NodeList nl = element.getChildNodes(); 90 for (int i = 0; i < nl.getLength(); i++) { 91 Node n = nl.item(i); 92 if ((n.getNodeType() == Node.ELEMENT_NODE) && (n.getNodeName().compareTo("cdl_entities") == 0)) { 93 NodeList nl1 = n.getChildNodes(); 94 HashMap ret = new HashMap(); 95 for (int j = 0; j < nl1.getLength(); j++) { 96 Node n1 = nl1.item(j); 97 if ((n1.getNodeType() == Node.ELEMENT_NODE) && (n1.getNodeName().compareTo("entity") == 0)) { 98 ret.put(((Element) n1).getAttribute("javaname"), ((Element) n1).getAttribute("cdlname")); 99 } 100 } 101 return ret; 102 } 103 } 104 return null; 105 } 106 107 112 public Set getSubComponents () { 113 Set set = new HashSet(); 114 NodeList nl = document.getElementsByTagName("component_ref"); 115 int length = nl.getLength(); 116 for (int i = 0; i < length; i++) { 117 assert(!(nl.item(i) instanceof Element)); 118 Element el = (Element) nl.item(i); 119 set.add(el.getAttribute("arch") + "[" + el.getAttribute("version") + "]"); 120 } 121 return set; 122 } 123 124 } 125 | Popular Tags |