1 25 package org.jrobin.core; 26 27 import org.xml.sax.InputSource ; 28 import org.w3c.dom.Node ; 29 30 import java.io.IOException ; 31 import java.io.File ; 32 import java.util.GregorianCalendar ; 33 34 131 public class RrdDefTemplate extends XmlTemplate { 132 139 public RrdDefTemplate(InputSource xmlInputSource) throws IOException , RrdException { 140 super(xmlInputSource); 141 } 142 143 150 public RrdDefTemplate(String xmlString) throws IOException , RrdException { 151 super(xmlString); 152 } 153 154 161 public RrdDefTemplate(File xmlFile) throws IOException , RrdException { 162 super(xmlFile); 163 } 164 165 180 public RrdDef getRrdDef() throws RrdException { 181 if (!root.getTagName().equals("rrd_def")) { 182 throw new RrdException("XML definition must start with <rrd_def>"); 183 } 184 validateTagsOnlyOnce(root, new String [] { 185 "path", "start", "step", "datasource*", "archive*" 186 }); 187 String path = getChildValue(root, "path"); 189 RrdDef rrdDef = new RrdDef(path); 190 try { 191 String startStr = getChildValue(root, "start"); 192 GregorianCalendar startGc = Util.getGregorianCalendar(startStr); 193 rrdDef.setStartTime(startGc); 194 } catch (RrdException e) { 195 } 197 try { 198 long step = getChildValueAsLong(root, "step"); 199 rrdDef.setStep(step); 200 } catch (RrdException e) { 201 } 203 Node [] dsNodes = getChildNodes(root, "datasource"); 205 for (int i = 0; i < dsNodes.length; i++) { 206 validateTagsOnlyOnce(dsNodes[i], new String [] { 207 "name", "type", "heartbeat", "min", "max" 208 }); 209 String name = getChildValue(dsNodes[i], "name"); 210 String type = getChildValue(dsNodes[i], "type"); 211 long heartbeat = getChildValueAsLong(dsNodes[i], "heartbeat"); 212 double min = getChildValueAsDouble(dsNodes[i], "min"); 213 double max = getChildValueAsDouble(dsNodes[i], "max"); 214 rrdDef.addDatasource(name, type, heartbeat, min, max); 215 } 216 Node [] arcNodes = getChildNodes(root, "archive"); 218 for (int i = 0; i < arcNodes.length; i++) { 219 validateTagsOnlyOnce(arcNodes[i], new String [] { 220 "cf", "xff", "steps", "rows" 221 }); 222 String consolFun = getChildValue(arcNodes[i], "cf"); 223 double xff = getChildValueAsDouble(arcNodes[i], "xff"); 224 int steps = getChildValueAsInt(arcNodes[i], "steps"); 225 int rows = getChildValueAsInt(arcNodes[i], "rows"); 226 rrdDef.addArchive(consolFun, xff, steps, rows); 227 } 228 return rrdDef; 229 } 230 } 231 | Popular Tags |