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