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

📄 bssrefersoconfig.java

📁 电信的网厅的整站代码
💻 JAVA
字号:
package com.doone.fj1w.fjmgr.order;

import java.util.List;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.Node;

import com.doone.util.ExtString;
import com.doone.util.FileLogger;
import com.doone.util.XmlParse;

public class BssReferSoConfig {
	private static Document xmlConfig = null; // 存放整个ReferSoConfig文件。
	private static final String xmlConfigFileName = "com/doone/fj1w/fjmgr/order/referso_config.xml";
	private List tables = null; // 存放Dom4j的Element对象列表。
	private int index = -1; // 存放访问tables的索引。
	private TableElement currNode = null;

	private BssReferSoConfig() {
	}

	public static BssReferSoConfig getConfig(String sType) {
		BssReferSoConfig result = null;
		try {
			//if (xmlConfig == null) {
				xmlConfig = XmlParse.loadXMLFile(xmlConfigFileName);
			//}

			result = new BssReferSoConfig();
			if (xmlConfig != null) {
				result.tables = xmlConfig.selectNodes("//root/" + sType + "/table");
				result.index = 0;
			}
		} catch (Exception ex) {
			FileLogger.getLogger().info(ex.getMessage(), ex);

			throw new RuntimeException(ex);
		}

		return result;
	}

	public TableElement nextTable() {
		if (index < tables.size()) {
			currNode = new TableElement((Element) tables.get(index++));
			return currNode;
		}

		return null;
	}

	public TableElement currTable() {
		if (currNode == null && index >= 0 && index < tables.size()) {
			currNode = new TableElement((Element) tables.get(index));
		}

		return currNode;
	}

	public int size() {
		return tables.size();
	}

	public static final String SO_TYPE_MOVEADSL = "moveadsl";
	public static final String SO_TYPE_MOVEPHONE = "movephone";

	class TableElement {
		private Element _table = null;
		private List _fields = null;
		private int tbidx = -1;
		private FieldElement _currField = null;

		TableElement(Element table) {
			if (table == null)
				throw new NullPointerException("table元素不能为空。");
			_table = table;
			_fields = _table.selectNodes("field");
			tbidx = 0;
		}

		public String getName() {
			return _table.attributeValue("name");
		}

		public boolean getMulti() {
			return ExtString.getBoolean(_table.attributeValue("multi"));
		}

		public String getSrcTable() {
			String st = _table.attributeValue("srctable");
			return st;
		}

		public String querySrcTable() {
			String st = _table.attributeValue("srctable");
			Element node = _table.getParent();
			while (ExtString.isEmpty(st) && node != null && !node.isRootElement()) {
				st = node.attributeValue("srctable");
				node = node.getParent();
			}

			return st;
		}

		public boolean isNoSet() {
			return ExtString.getBoolean(_table.attributeValue("noset"));
		}

		public int size() {
			return _fields.size();
		}

		public FieldElement nextField() {
			if (this.tbidx < _fields.size()) {
				_currField = new FieldElement((Element) _fields.get(this.tbidx++));

				return _currField;
			}

			return null;
		}

		public FieldElement currField() {
			if (_currField == null && this.tbidx >= 0 && this.tbidx < this._fields.size()) {
				_currField = new FieldElement((Element) this._fields.get(this.tbidx));
			}

			return _currField;
		}
	}

	class FieldElement {
		private Element _field = null;
		private List _cases = null;
		private int caseIdx = -1;
		private CaseElement _currCase = null;

		FieldElement(Element field) {
			if (field == null)
				throw new NullPointerException("table元素不能为空。");
			_field = field;
			_cases = _field.selectNodes("case");
			caseIdx = 0;
		}

		public String getName() {
			return _field.attributeValue("name");
		}

		public int getSrcType() {
			String sType = _field.attributeValue("srctype");
			try {
				if (!ExtString.isEmpty(sType)) {
					return Integer.parseInt(sType);
				}
			} catch (Exception ex) {
				FileLogger.getLogger().info(ex.getMessage(), ex);
			}

			return -1;
		}

		public boolean checkNull() {
			if (_field.attributeValue("checknull") != null)
				return ExtString.getBoolean(_field.attributeValue("checknull"));
			else
				return true;
		}

		public String getDefaultValue() {
			return _field.attributeValue("defaultvalue");
		}

		public String getSrcTable() {
			String st = _field.attributeValue("srctable");
			Element node = _field.getParent();
			while (ExtString.isEmpty(st) && node != null && !node.isRootElement()) {
				st = node.attributeValue("srctable");
				node = node.getParent();
			}

			return st;
		}

		public String schSrcTable() {
			String st = _field.attributeValue("srctable");
			Element node = _field.getParent();
			while (ExtString.isEmpty(st) && node != null && !node.isRootElement()) {
				st = node.attributeValue("srctable");
				node = node.getParent();
			}

			return st;
		}

		public String getSrcField() {
			return _field.attributeValue("srcfield");
		}

		public int size() {
			return _cases.size();
		}

		public CaseElement getCase(String sValue) {
			if (size() > 0) {
				Node node = _field.selectSingleNode("case[@condition=\"" + sValue + "\"]");
				if (node == null) {
					node = _field.selectSingleNode("case[not(@condition) or @condition=\"\"]");
				}

				if (node != null) {
					return new CaseElement((Element) node);
				}
			}

			return null;
		}

		public CaseElement nextCase() {
			if (this.caseIdx < _cases.size()) {
				_currCase = new CaseElement((Element) _cases.get(this.caseIdx++));

				return _currCase;
			}

			return null;
		}

		public CaseElement currCase() {
			if (_currCase == null && this.caseIdx >= 0 && this.caseIdx < this._cases.size()) {
				_currCase = new CaseElement((Element) this._cases.get(this.caseIdx));
			}

			return _currCase;
		}
	}

	class CaseElement {
		private Element _case = null;

		public CaseElement(Element element) {
			if (element == null)
				throw new NullPointerException("table元素不能为空。");
			_case = element;
		}

		public String getCondition() {
			return _case.attributeValue("condition");
		}

		public int getSrcType() {
			String sType = _case.attributeValue("srctype");
			try {
				if (!ExtString.isEmpty(sType)) {
					return Integer.parseInt(sType);
				}
			} catch (Exception ex) {
				FileLogger.getLogger().info(ex.getMessage(), ex);
			}

			return -1;
		}

		public String getDefaultValue() {
			return _case.attributeValue("defaultvalue");
		}

		public String getSrcTable() {
			String st = _case.attributeValue("srctable");
			return st;
		}

		public String schSrcTable() {
			String st = _case.attributeValue("srctable");
			Element node = _case.getParent();
			while (ExtString.isEmpty(st) && node != null && !node.isRootElement()) {
				st = node.attributeValue("srctable");
				node = node.getParent();
			}

			return st;
		}

		public String getSrcField() {
			return _case.attributeValue("srcfield");
		}
	}
}

⌨️ 快捷键说明

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