package test.appProfConverter; import java.io.File; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; public class HardwareProfile { public HardwareProfile(String fileName) { this.LoadFromXml(fileName); } public String ToString() { String str = ""; str += "Componend Id: " + this.ComponentId + "\n"; str += proc.ToString(); str += mem.ToString(); str += nic.ToString(); return str; } public void LoadFromXml(String fileName) { try { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory .newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.parse(new File(fileName)); Element e; e = (Element) doc.getElementsByTagName("ComponentId").item(0); this.ComponentId = e.getChildNodes().item(0).getNodeValue(); e = (Element) doc.getElementsByTagName("Processor").item(0); this.proc = new Processor(e); e = (Element) doc.getElementsByTagName("Memory").item(0); this.mem = new Memory(e); e = (Element) doc.getElementsByTagName("Network").item(0); this.nic = new Network(e); } catch (SAXParseException err) { System.out.println("** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId()); System.out.println(" " + err.getMessage()); } catch (SAXException e) { Exception x = e.getException(); ((x == null) ? e : x).printStackTrace(); } catch (Throwable t) { t.printStackTrace(); } } public String ComponentId; public Processor proc; public Memory mem; public Network nic; }