1 | package test.appProfConverter; |
---|
2 | import java.io.File; |
---|
3 | |
---|
4 | import javax.xml.parsers.DocumentBuilder; |
---|
5 | import javax.xml.parsers.DocumentBuilderFactory; |
---|
6 | |
---|
7 | import org.w3c.dom.Document; |
---|
8 | import org.w3c.dom.Element; |
---|
9 | import org.xml.sax.SAXException; |
---|
10 | import org.xml.sax.SAXParseException; |
---|
11 | |
---|
12 | public class HardwareProfile { |
---|
13 | |
---|
14 | public HardwareProfile(String fileName) { |
---|
15 | this.LoadFromXml(fileName); |
---|
16 | } |
---|
17 | |
---|
18 | public String ToString() { |
---|
19 | String str = ""; |
---|
20 | |
---|
21 | str += "Componend Id: " + this.ComponentId + "\n"; |
---|
22 | str += proc.ToString(); |
---|
23 | str += mem.ToString(); |
---|
24 | str += nic.ToString(); |
---|
25 | |
---|
26 | return str; |
---|
27 | } |
---|
28 | |
---|
29 | public void LoadFromXml(String fileName) { |
---|
30 | try { |
---|
31 | DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory |
---|
32 | .newInstance(); |
---|
33 | DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); |
---|
34 | Document doc = docBuilder.parse(new File(fileName)); |
---|
35 | |
---|
36 | Element e; |
---|
37 | |
---|
38 | e = (Element) doc.getElementsByTagName("ComponentId").item(0); |
---|
39 | this.ComponentId = e.getChildNodes().item(0).getNodeValue(); |
---|
40 | |
---|
41 | e = (Element) doc.getElementsByTagName("Processor").item(0); |
---|
42 | this.proc = new Processor(e); |
---|
43 | |
---|
44 | e = (Element) doc.getElementsByTagName("Memory").item(0); |
---|
45 | this.mem = new Memory(e); |
---|
46 | |
---|
47 | e = (Element) doc.getElementsByTagName("Network").item(0); |
---|
48 | this.nic = new Network(e); |
---|
49 | |
---|
50 | } catch (SAXParseException err) { |
---|
51 | System.out.println("** Parsing error" + ", line " |
---|
52 | + err.getLineNumber() + ", uri " + err.getSystemId()); |
---|
53 | System.out.println(" " + err.getMessage()); |
---|
54 | |
---|
55 | } catch (SAXException e) { |
---|
56 | Exception x = e.getException(); |
---|
57 | ((x == null) ? e : x).printStackTrace(); |
---|
58 | |
---|
59 | } catch (Throwable t) { |
---|
60 | t.printStackTrace(); |
---|
61 | } |
---|
62 | } |
---|
63 | |
---|
64 | public String ComponentId; |
---|
65 | public Processor proc; |
---|
66 | public Memory mem; |
---|
67 | public Network nic; |
---|
68 | |
---|
69 | } |
---|