home *** CD-ROM | disk | FTP | other *** search
- class com.data.DAO extends com.event.observable
- {
- var objXMLHM;
- static var objInstance;
- function DAO()
- {
- var _loc1_ = this;
- super();
- _loc1_.success = new Boolean(false);
- _loc1_.error = new String("");
- _loc1_.objXMLHM = new com.util.HashMap();
- _loc1_.blnBusy = new Boolean(false);
- _loc1_.strCurrentXMLID = new String("");
- _loc1_.strCurrentSource = new String("");
- }
- static function getInstance()
- {
- if(com.data.DAO.objInstance == undefined)
- {
- com.data.DAO.objInstance = new com.data.DAO();
- }
- return com.data.DAO.objInstance;
- }
- function load(_strID, _strPath)
- {
- var _loc1_ = this;
- var _loc2_ = _strPath;
- if(_loc1_.blnBusy == true)
- {
- return false;
- }
- _loc1_.blnBusy = true;
- _loc1_.strCurrentXMLID = _strID;
- _loc1_.strCurrentSource = _loc2_;
- var _loc3_ = _loc2_.substring(_loc2_.lastIndexOf("/") + 1,_loc2_.length);
- var iIndex = _loc3_.indexof(".");
- trace("iIndex: " + iIndex);
- if(iIndex > -1)
- {
- var objXML = new XML();
- objXML.ignoreWhite = true;
- objXML.onLoad = function(blnSuccess)
- {
- com.data.DAO.getInstance().onDataLoad(this,blnSuccess);
- };
- var ploader = new com.util.PreLoader(_root);
- ploader.addListener(_loc1_);
- ploader.loadMovieClip(objXML,"Loading data from :" + _loc3_);
- objXML.load(_loc1_.strCurrentSource);
- }
- else
- {
- trace(_loc3_ + " >>>>>>>>> Linux XML SO");
- var objXML = new XML(_loc2_);
- objXML.ignoreWhite = true;
- com.data.DAO.getInstance().onDataLoad(objXML,true);
- }
- return true;
- }
- function onDataLoad(_objXML, blnSuccess)
- {
- var _loc1_ = this;
- _loc1_.blnBusy = false;
- if(blnSuccess)
- {
- _loc1_.objXMLHM.put(_loc1_.strCurrentXMLID,_objXML);
- _loc1_.success = true;
- }
- else
- {
- _loc1_.success = false;
- _loc1_.error = "Error : Unable to load data from the source [" + _loc1_.strCurrentXMLID + " : " + _loc1_.strCurrentSource + "]";
- }
- _loc1_.addListener(_global.G_SHELL);
- _loc1_.broadcastEvent("DAOUpdate",_loc1_.strCurrentXMLID);
- }
- function getData(_strDataPath)
- {
- var _loc2_ = _strDataPath.split(".")[1];
- var _loc1_ = this.getDataSet(_strDataPath.split(".")[0]);
- if(_loc1_ == undefined)
- {
- return undefined;
- }
- return this.getValue(_loc1_,_loc2_);
- }
- function getDataSet(_strDataPath)
- {
- var strXMLID = _strDataPath.split(":")[0];
- var arrNodeNest = _strDataPath.split(":")[1].split("/");
- var _loc1_ = this.objXMLHM["get"](strXMLID);
- var _loc2_ = 0;
- while(_loc2_ < arrNodeNest.length)
- {
- var _loc3_ = Number(arrNodeNest[_loc2_].split("[")[1].split("]")[0]);
- var strNodeName = arrNodeNest[_loc2_].split("[")[0];
- if(strNodeName != "" && strNodeName != undefined)
- {
- _loc1_ = this.findNode(_loc1_,strNodeName);
- }
- if(_loc3_ != undefined && !isNaN(_loc3_) && _loc3_ >= 0)
- {
- _loc1_ = this.getChild(_loc1_,_loc3_);
- }
- if(_loc1_ == undefined || _loc1_ == null)
- {
- return undefined;
- }
- _loc2_ = _loc2_ + 1;
- }
- return _loc1_;
- }
- function getDataSetLength(_strDataPath)
- {
- var _loc1_ = this.getDataSet(_strDataPath);
- return _loc1_.childNodes.length;
- }
- function getChild(_objXMLNode, _iIndex)
- {
- return _objXMLNode.childNodes[_iIndex];
- }
- function getValue(objNode, strAttribute)
- {
- var _loc1_ = objNode;
- var _loc2_ = strAttribute;
- if(_loc1_ && _loc1_.firstChild && _loc1_.firstChild.nodeType == 3 && _loc2_ == undefined)
- {
- return _loc1_.firstChild.nodeValue;
- }
- if(_loc1_ && _loc2_ != undefined)
- {
- return _loc1_.attributes[_loc2_];
- }
- return undefined;
- }
- function findNode(objNode, strNodeName)
- {
- var _loc2_ = objNode;
- var _loc3_ = strNodeName;
- var _loc1_ = 0;
- while(_loc2_.childNodes && _loc1_ < _loc2_.childNodes.length)
- {
- if(_loc2_.childNodes[_loc1_].nodeName == _loc3_)
- {
- return _loc2_.childNodes[_loc1_];
- }
- _loc1_ = _loc1_ + 1;
- }
- return undefined;
- }
- function findNodeRec(objNode, strNodeName)
- {
- var _loc3_ = objNode;
- if(_loc3_.nodeName == strNodeName)
- {
- return _loc3_;
- }
- var _loc1_ = 0;
- while(_loc3_.childNodes && _loc1_ < _loc3_.childNodes.length)
- {
- var _loc2_ = this.findNode(_loc3_.childNodes[_loc1_],strNodeName);
- if(_loc2_ != null)
- {
- return _loc2_;
- }
- _loc1_ = _loc1_ + 1;
- }
- return undefined;
- }
- }
-