JSVM核心类库,收集了JAVA进行JSVM开发必用技术进行归纳,在实际项目应用中直接引用相关类库即可现实JSVM相关功能!

源代码在线查看: userdata.js

软件大小: 44 K
上传用户: ac3698
关键词: JSVM JAVA 核心
下载地址: 免注册下载 普通下载 VIP

相关代码

				// Description: js.io.UserData 客户端的数据存储对象
				// Author:	Changhua.Wan
				// Version:	2004.03.06.01
				
				
				_package("js.io");
				
				_import("js.io.DataContext");
				
				function js.io.UserData(name) {
					js.io.UserData._base.call(this);
					this.name = js.io.UserData.formatName(name);
					this.expires = new Date(2077, 12, 4).toUTCString();
					this.element = null;
					this.isLoaded = false;
					this.isSaved = false;
				};
				
				var _p = js.io.UserData._implements("js.io.DataContext");
				var _c = js.io.UserData;
				
				// UserData 池
				_c.pool = new function() {
					var freeUDSources = new Array();
					this.getUDSource = function() {
						var _uds = null;
						if (freeUDSources.length > 0) {
							var l = freeUDSources.length;
							_uds = freeUDSources[l - 1];
							freeUDSources.length = l - 1;
						} else {
							_uds = document.createElement("meta");
							_uds.addBehavior("#default#userdata");
							document.getElementsByTagName("head")[0].appendChild(_uds);
						}
						return _uds;
					}
					this.freeUDSource = function(_uds) {
						var l = freeUDSources.length;
						freeUDSources[l] = _uds;
						freeUDSources.length = l + 1;
					}
				}
				_c.map = new ActiveXObject("Scripting.Dictionary");
				
				_c.formatName = function(_name) {
					if (_name == null) return "NULL";
					return _name.replace(/(\/)|(\\)|@|&|%|(\.)|,|(\")|'|:/gi, "_");
				
				};
				
				_c.getInstance = function(name) {
					try {
						var map = js.io.UserData.map;
						if (!map.Exists(name)) map.Add(name, new js.io.UserData(name));
						var ud = map.Item(name);
						return ud;
					} catch(ex) {
						_throw(0x1101, "js.io.UserData/getInstance():异常{" + ex.description + "}");
					} 
				};
				_p.setStringValue = function(_name, _value) {
					try {
						_name = js.io.UserData.formatName(_name);
						if (null != _value)
							this.element.setAttribute(_name, _value);
						else
							this.remove(_name);
						this.isSaved = false;
					} catch(ex) {
						_throw(0x1102, "js.io.UserData/setStringValue():异常{" + ex.description + "}");
					}
				};
				_p.getStringValue = function(_name) {
					if (this.element == null) _throw(0x1103, "js.io.UserData/getStringValue():异常{UserData 资源尚未打开!}");
					_name = js.io.UserData.formatName(_name);
					return this.element.getAttribute(_name);
				};
				_p.remove = function(_name) {
					if (this.element == null) _throw(0x1104, "js.io.UserData/remove():异常{UserData 资源尚未打开!}");
					_name = js.io.UserData.formatName(_name);
					this.element.removeAttribute(_name);
				};
				_p.removeAll = function() {
					if (this.element == null) _throw(0x1105, "js.io.UserData/removeAll():异常{UserData 资源尚未打开!}");
					var root = this.getXMLDocument().documentElement;
					var atts = root.attributes;
					for (var i = 0; i < atts.length; i++) {
						this.remove(atts.item(i).nodeName);
					}
				};
				_p.open = function() {
					if (this.element == null) {
						this.element = js.io.UserData.pool.getUDSource();
					}	
				}
				_p.close = function() {
					if (this.element != null) {
						js.io.UserData.pool.freeUDSource(this.element);
						this.element = null;
					}
				}
				_p.load = function() {
					try {
						if (this.element == null) _throw(0x1106, "js.io.UserData/load():异常{UserData 资源尚未打开!}");
						this.element.load(this.name);
						this.isLoaded = true;
					} catch(ex) {
						//ex.printStackTrace();
					}
				};
				_p.save = function() {
					try {
						if (this.element == null) _throw(0x1107, "js.io.UserData/load():异常{UserData 资源尚未打开!}");
						this.element.expires = this.expires;
						this.element.save(this.name);
						this.isSaved = true;
					} catch(ex) {
						//ex.printStackTrace();
					}
				};
				_p.getXMLDocument = function() {
					if (this.element != null)
						return this.element.XMLDocument;
					else
						return null;
				};
				
							

相关资源