1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package org.jrobin.core;
27
28 import org.w3c.dom.Element;
29 import org.w3c.dom.Node;
30
31 import java.io.File;
32 import java.io.IOException;
33
34 class XmlReader extends DataImporter {
35
36 private Element root;
37 private Node[] dsNodes, arcNodes;
38
39 XmlReader(String xmlFilePath) throws IOException, RrdException {
40 root = Util.Xml.getRootElement(new File(xmlFilePath));
41 dsNodes = Util.Xml.getChildNodes(root, "ds");
42 arcNodes = Util.Xml.getChildNodes(root, "rra");
43 }
44
45 String getVersion() throws RrdException {
46 return Util.Xml.getChildValue(root, "version");
47 }
48
49 long getLastUpdateTime() throws RrdException {
50 return Util.Xml.getChildValueAsLong(root, "lastupdate");
51 }
52
53 long getStep() throws RrdException {
54 return Util.Xml.getChildValueAsLong(root, "step");
55 }
56
57 int getDsCount() {
58 return dsNodes.length;
59 }
60
61 int getArcCount() {
62 return arcNodes.length;
63 }
64
65 String getDsName(int dsIndex) throws RrdException {
66 return Util.Xml.getChildValue(dsNodes[dsIndex], "name");
67 }
68
69 String getDsType(int dsIndex) throws RrdException {
70 return Util.Xml.getChildValue(dsNodes[dsIndex], "type");
71 }
72
73 long getHeartbeat(int dsIndex) throws RrdException {
74 return Util.Xml.getChildValueAsLong(dsNodes[dsIndex], "minimal_heartbeat");
75 }
76
77 double getMinValue(int dsIndex) throws RrdException {
78 return Util.Xml.getChildValueAsDouble(dsNodes[dsIndex], "min");
79 }
80
81 double getMaxValue(int dsIndex) throws RrdException {
82 return Util.Xml.getChildValueAsDouble(dsNodes[dsIndex], "max");
83 }
84
85 double getLastValue(int dsIndex) throws RrdException {
86 return Util.Xml.getChildValueAsDouble(dsNodes[dsIndex], "last_ds");
87 }
88
89 double getAccumValue(int dsIndex) throws RrdException {
90 return Util.Xml.getChildValueAsDouble(dsNodes[dsIndex], "value");
91 }
92
93 long getNanSeconds(int dsIndex) throws RrdException {
94 return Util.Xml.getChildValueAsLong(dsNodes[dsIndex], "unknown_sec");
95 }
96
97 String getConsolFun(int arcIndex) throws RrdException {
98 return Util.Xml.getChildValue(arcNodes[arcIndex], "cf");
99 }
100
101 double getXff(int arcIndex) throws RrdException {
102 return Util.Xml.getChildValueAsDouble(arcNodes[arcIndex], "xff");
103 }
104
105 int getSteps(int arcIndex) throws RrdException {
106 return Util.Xml.getChildValueAsInt(arcNodes[arcIndex], "pdp_per_row");
107 }
108
109 double getStateAccumValue(int arcIndex, int dsIndex) throws RrdException {
110 Node cdpNode = Util.Xml.getFirstChildNode(arcNodes[arcIndex], "cdp_prep");
111 Node[] dsNodes = Util.Xml.getChildNodes(cdpNode, "ds");
112 return Util.Xml.getChildValueAsDouble(dsNodes[dsIndex], "value");
113 }
114
115 int getStateNanSteps(int arcIndex, int dsIndex) throws RrdException {
116 Node cdpNode = Util.Xml.getFirstChildNode(arcNodes[arcIndex], "cdp_prep");
117 Node[] dsNodes = Util.Xml.getChildNodes(cdpNode, "ds");
118 return Util.Xml.getChildValueAsInt(dsNodes[dsIndex], "unknown_datapoints");
119 }
120
121 int getRows(int arcIndex) throws RrdException {
122 Node dbNode = Util.Xml.getFirstChildNode(arcNodes[arcIndex], "database");
123 Node[] rows = Util.Xml.getChildNodes(dbNode, "row");
124 return rows.length;
125 }
126
127 double[] getValues(int arcIndex, int dsIndex) throws RrdException {
128 Node dbNode = Util.Xml.getFirstChildNode(arcNodes[arcIndex], "database");
129 Node[] rows = Util.Xml.getChildNodes(dbNode, "row");
130 double[] values = new double[rows.length];
131 for (int i = 0; i < rows.length; i++) {
132 Node[] vNodes = Util.Xml.getChildNodes(rows[i], "v");
133 Node vNode = vNodes[dsIndex];
134 values[i] = Util.parseDouble(vNode.getFirstChild().getNodeValue().trim());
135 }
136 return values;
137 }
138 }