⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rrdgraphdeftemplate.java

📁 jrobin,使用纯java实现的RRD数据库,使用RRD数据库来统计数据.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			if (nodeName.equals("filename")) {
				resolveFilename(childNode);
			}
			// SPAN
			else if (nodeName.equals("span")) {
				resolveSpan(childNode);
			}
			// OPTIONS
			else if (nodeName.equals("options")) {
				resolveOptions(childNode);
			}
			// DATASOURCES
			else if (nodeName.equals("datasources")) {
				resolveDatasources(childNode);
			}
			// GRAPH ELEMENTS
			else if (nodeName.equals("graph")) {
				resolveGraphElements(childNode);
			}
		}
		return rrdGraphDef;
	}

	private void resolveGraphElements(Node graphNode) throws RrdException {
		validateTagsOnlyOnce(graphNode, new String[] {"area*", "line*", "stack*",
				"print*", "gprint*", "hrule*", "vrule*", "comment*"});
		Node[] childNodes = getChildNodes(graphNode);
		for (Node childNode : childNodes) {
			String nodeName = childNode.getNodeName();
			if (nodeName.equals("area")) {
				resolveArea(childNode);
			}
			else if (nodeName.equals("line")) {
				resolveLine(childNode);
			}
			else if (nodeName.equals("stack")) {
				resolveStack(childNode);
			}
			else if (nodeName.equals("print")) {
				resolvePrint(childNode, false);
			}
			else if (nodeName.equals("gprint")) {
				resolvePrint(childNode, true);
			}
			else if (nodeName.equals("hrule")) {
				resolveHRule(childNode);
			}
			else if (nodeName.equals("vrule")) {
				resolveVRule(childNode);
			}
			else if (nodeName.equals("comment")) {
				rrdGraphDef.comment(getValue(childNode));
			}
		}
	}

	private void resolveVRule(Node parentNode) throws RrdException {
		validateTagsOnlyOnce(parentNode, new String[] {"time", "color", "legend"});
		long timestamp = Long.MIN_VALUE;
		Paint color = null;
		String legend = null;
		Node[] childNodes = getChildNodes(parentNode);
		for (Node childNode : childNodes) {
			String nodeName = childNode.getNodeName();
			if (nodeName.equals("time")) {
				timestamp = Util.getTimestamp(getValue(childNode));
			}
			else if (nodeName.equals("color")) {
				color = getValueAsColor(childNode);
			}
			else if (nodeName.equals("legend")) {
				legend = getValue(childNode);
			}
		}
		if (timestamp != Long.MIN_VALUE && color != null) {
			rrdGraphDef.vrule(timestamp, color, legend);
		}
		else {
			throw new RrdException("Incomplete VRULE settings");
		}
	}

	private void resolveHRule(Node parentNode) throws RrdException {
		validateTagsOnlyOnce(parentNode, new String[] {"value", "color", "legend"});
		double value = Double.NaN;
		Paint color = null;
		String legend = null;
		Node[] childNodes = getChildNodes(parentNode);
		for (Node childNode : childNodes) {
			String nodeName = childNode.getNodeName();
			if (nodeName.equals("value")) {
				value = getValueAsDouble(childNode);
			}
			else if (nodeName.equals("color")) {
				color = getValueAsColor(childNode);
			}
			else if (nodeName.equals("legend")) {
				legend = getValue(childNode);
			}
		}
		if (!Double.isNaN(value) && color != null) {
			rrdGraphDef.hrule(value, color, legend);
		}
		else {
			throw new RrdException("Incomplete HRULE settings");
		}
	}

	private void resolvePrint(Node parentNode, boolean isInGraph) throws RrdException {
		validateTagsOnlyOnce(parentNode, new String[] {"datasource", "cf", "format"});
		String datasource = null, cf = null, format = null;
		Node[] childNodes = getChildNodes(parentNode);
		for (Node childNode : childNodes) {
			String nodeName = childNode.getNodeName();
			if (nodeName.equals("datasource")) {
				datasource = getValue(childNode);
			}
			else if (nodeName.equals("cf")) {
				cf = getValue(childNode);
			}
			else if (nodeName.equals("format")) {
				format = getValue(childNode);
			}
		}
		if (datasource != null && cf != null && format != null) {
			if (isInGraph) {
				rrdGraphDef.gprint(datasource, cf, format);
			}
			else {
				rrdGraphDef.print(datasource, cf, format);
			}
		}
		else {
			throw new RrdException("Incomplete " + (isInGraph ? "GRPINT" : "PRINT") + " settings");
		}
	}

	private void resolveStack(Node parentNode) throws RrdException {
		validateTagsOnlyOnce(parentNode, new String[] {"datasource", "color", "legend"});
		String datasource = null, legend = null;
		Paint color = null;
		Node[] childNodes = getChildNodes(parentNode);
		for (Node childNode : childNodes) {
			String nodeName = childNode.getNodeName();
			if (nodeName.equals("datasource")) {
				datasource = getValue(childNode);
			}
			else if (nodeName.equals("color")) {
				color = getValueAsColor(childNode);
			}
			else if (nodeName.equals("legend")) {
				legend = getValue(childNode);
			}
		}
		if (datasource != null) {
			if (color != null) {
				rrdGraphDef.stack(datasource, color, legend);
			}
			else {
				rrdGraphDef.stack(datasource, BLIND_COLOR, legend);
			}
		}
		else {
			throw new RrdException("Incomplete STACK settings");
		}
	}

	private void resolveLine(Node parentNode) throws RrdException {
		validateTagsOnlyOnce(parentNode, new String[] {"datasource", "color", "legend", "width"});
		String datasource = null, legend = null;
		Paint color = null;
		float width = 1.0F;
		Node[] childNodes = getChildNodes(parentNode);
		for (Node childNode : childNodes) {
			String nodeName = childNode.getNodeName();
			if (nodeName.equals("datasource")) {
				datasource = getValue(childNode);
			}
			else if (nodeName.equals("color")) {
				color = getValueAsColor(childNode);
			}
			else if (nodeName.equals("legend")) {
				legend = getValue(childNode);
			}
			else if (nodeName.equals("width")) {
				width = (float) getValueAsDouble(childNode);
			}
		}
		if (datasource != null) {
			if (color != null) {
				rrdGraphDef.line(datasource, color, legend, width);
			}
			else {
				rrdGraphDef.line(datasource, BLIND_COLOR, legend, width);
			}
		}
		else {
			throw new RrdException("Incomplete LINE settings");
		}
	}

	private void resolveArea(Node parentNode) throws RrdException {
		validateTagsOnlyOnce(parentNode, new String[] {"datasource", "color", "legend"});
		String datasource = null, legend = null;
		Paint color = null;
		Node[] childNodes = getChildNodes(parentNode);
		for (Node childNode : childNodes) {
			String nodeName = childNode.getNodeName();
			if (nodeName.equals("datasource")) {
				datasource = getValue(childNode);
			}
			else if (nodeName.equals("color")) {
				color = getValueAsColor(childNode);
			}
			else if (nodeName.equals("legend")) {
				legend = getValue(childNode);
			}
		}
		if (datasource != null) {
			if (color != null) {
				rrdGraphDef.area(datasource, color, legend);
			}
			else {
				rrdGraphDef.area(datasource, BLIND_COLOR, legend);
			}
		}
		else {
			throw new RrdException("Incomplete AREA settings");
		}
	}

	private void resolveDatasources(Node datasourcesNode) throws RrdException {
		validateTagsOnlyOnce(datasourcesNode, new String[] {"def*", "cdef*", "sdef*"});
		Node[] childNodes = getChildNodes(datasourcesNode);
		for (Node childNode : childNodes) {
			String nodeName = childNode.getNodeName();
			if (nodeName.equals("def")) {
				resolveDef(childNode);
			}
			else if (nodeName.equals("cdef")) {
				resolveCDef(childNode);
			}
			else if (nodeName.equals("sdef")) {
				resolveSDef(childNode);
			}
		}
	}

	private void resolveSDef(Node parentNode) throws RrdException {
		validateTagsOnlyOnce(parentNode, new String[] {"name", "source", "cf"});
		String name = null, source = null, cf = null;
		Node[] childNodes = getChildNodes(parentNode);
		for (Node childNode : childNodes) {
			String nodeName = childNode.getNodeName();
			if (nodeName.equals("name")) {
				name = getValue(childNode);
			}
			else if (nodeName.equals("source")) {
				source = getValue(childNode);
			}
			else if (nodeName.equals("cf")) {
				cf = getValue(childNode);
			}
		}
		if (name != null && source != null && cf != null) {
			rrdGraphDef.datasource(name, source, cf);
		}
		else {
			throw new RrdException("Incomplete SDEF settings");
		}
	}

	private void resolveCDef(Node parentNode) throws RrdException {
		validateTagsOnlyOnce(parentNode, new String[] {"name", "rpn"});
		String name = null, rpn = null;
		Node[] childNodes = getChildNodes(parentNode);
		for (Node childNode : childNodes) {
			String nodeName = childNode.getNodeName();
			if (nodeName.equals("name")) {
				name = getValue(childNode);
			}
			else if (nodeName.equals("rpn")) {
				rpn = getValue(childNode);
			}
		}
		if (name != null && rpn != null) {
			rrdGraphDef.datasource(name, rpn);
		}
		else {
			throw new RrdException("Incomplete CDEF settings");
		}
	}

	private void resolveDef(Node parentNode) throws RrdException {
		validateTagsOnlyOnce(parentNode, new String[] {"name", "rrd", "source", "cf", "backend"});
		String name = null, rrd = null, source = null, cf = null, backend = null;
		Node[] childNodes = getChildNodes(parentNode);
		for (Node childNode : childNodes) {
			String nodeName = childNode.getNodeName();
			if (nodeName.equals("name")) {
				name = getValue(childNode);
			}
			else if (nodeName.equals("rrd")) {
				rrd = getValue(childNode);
			}
			else if (nodeName.equals("source")) {
				source = getValue(childNode);
			}
			else if (nodeName.equals("cf")) {
				cf = getValue(childNode);
			}
			else if (nodeName.equals("backend")) {
				backend = getValue(childNode);
			}
		}
		if (name != null && rrd != null && source != null && cf != null) {
			rrdGraphDef.datasource(name, rrd, source, cf, backend);
		}
		else {
			throw new RrdException("Incomplete DEF settings");
		}
	}

	private void resolveFilename(Node filenameNode) {
		String filename = getValue(filenameNode);
		rrdGraphDef.setFilename(filename);
	}

	private void resolveSpan(Node spanNode) throws RrdException {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -