home *** CD-ROM | disk | FTP | other *** search
/ FCE Gold Plus / GOLD.iso / pc / shell.swf / scripts / __Packages / com / data / DAO.as next >
Text File  |  2007-10-16  |  5KB  |  169 lines

  1. class com.data.DAO extends com.event.observable
  2. {
  3.    function DAO()
  4.    {
  5.       var _loc1_ = this;
  6.       super();
  7.       _loc1_.success = new Boolean(false);
  8.       _loc1_.error = new String("");
  9.       _loc1_.objXMLHM = new com.util.HashMap();
  10.       _loc1_.blnBusy = new Boolean(false);
  11.       _loc1_.strCurrentXMLID = new String("");
  12.       _loc1_.strCurrentSource = new String("");
  13.    }
  14.    static function getInstance()
  15.    {
  16.       if(com.data.DAO.objInstance == undefined)
  17.       {
  18.          com.data.DAO.objInstance = new com.data.DAO();
  19.       }
  20.       return com.data.DAO.objInstance;
  21.    }
  22.    function load(_strID, _strPath)
  23.    {
  24.       var _loc1_ = this;
  25.       var _loc2_ = _strPath;
  26.       if(_loc1_.blnBusy == true)
  27.       {
  28.          return false;
  29.       }
  30.       _loc1_.blnBusy = true;
  31.       _loc1_.strCurrentXMLID = _strID;
  32.       _loc1_.strCurrentSource = _loc2_;
  33.       var _loc3_ = _loc2_.substring(_loc2_.lastIndexOf("/") + 1,_loc2_.length);
  34.       var iIndex = _loc3_.indexof(".");
  35.       trace("iIndex: " + iIndex);
  36.       if(iIndex > -1)
  37.       {
  38.          var objXML = new XML();
  39.          objXML.ignoreWhite = true;
  40.          objXML.onLoad = function(blnSuccess)
  41.          {
  42.             com.data.DAO.getInstance().onDataLoad(this,blnSuccess);
  43.          };
  44.          var ploader = new com.util.PreLoader(_root);
  45.          ploader.addListener(_loc1_);
  46.          ploader.loadMovieClip(objXML,"Loading data from :" + _loc3_);
  47.          objXML.load(_loc1_.strCurrentSource);
  48.       }
  49.       else
  50.       {
  51.          trace(_loc3_ + "   >>>>>>>>> Linux XML SO");
  52.          var objXML = new XML(_loc2_);
  53.          objXML.ignoreWhite = true;
  54.          com.data.DAO.getInstance().onDataLoad(objXML,true);
  55.       }
  56.       return true;
  57.    }
  58.    function onDataLoad(_objXML, blnSuccess)
  59.    {
  60.       var _loc1_ = this;
  61.       _loc1_.blnBusy = false;
  62.       if(blnSuccess)
  63.       {
  64.          _loc1_.objXMLHM.put(_loc1_.strCurrentXMLID,_objXML);
  65.          _loc1_.success = true;
  66.       }
  67.       else
  68.       {
  69.          _loc1_.success = false;
  70.          _loc1_.error = "Error : Unable to load data from the source [" + _loc1_.strCurrentXMLID + " : " + _loc1_.strCurrentSource + "]";
  71.       }
  72.       _loc1_.addListener(_global.G_SHELL);
  73.       _loc1_.broadcastEvent("DAOUpdate",_loc1_.strCurrentXMLID);
  74.    }
  75.    function getData(_strDataPath)
  76.    {
  77.       var _loc2_ = _strDataPath.split(".")[1];
  78.       var _loc1_ = this.getDataSet(_strDataPath.split(".")[0]);
  79.       if(_loc1_ == undefined)
  80.       {
  81.          return undefined;
  82.       }
  83.       return this.getValue(_loc1_,_loc2_);
  84.    }
  85.    function getDataSet(_strDataPath)
  86.    {
  87.       var strXMLID = _strDataPath.split(":")[0];
  88.       var arrNodeNest = _strDataPath.split(":")[1].split("/");
  89.       var _loc1_ = this.objXMLHM["get"](strXMLID);
  90.       var _loc2_ = 0;
  91.       while(_loc2_ < arrNodeNest.length)
  92.       {
  93.          var _loc3_ = Number(arrNodeNest[_loc2_].split("[")[1].split("]")[0]);
  94.          var strNodeName = arrNodeNest[_loc2_].split("[")[0];
  95.          if(strNodeName != "" && strNodeName != undefined)
  96.          {
  97.             _loc1_ = this.findNode(_loc1_,strNodeName);
  98.          }
  99.          if(_loc3_ != undefined && !isNaN(_loc3_) && _loc3_ >= 0)
  100.          {
  101.             _loc1_ = this.getChild(_loc1_,_loc3_);
  102.          }
  103.          if(_loc1_ == undefined || _loc1_ == null)
  104.          {
  105.             return undefined;
  106.          }
  107.          _loc2_ = _loc2_ + 1;
  108.       }
  109.       return _loc1_;
  110.    }
  111.    function getDataSetLength(_strDataPath)
  112.    {
  113.       var _loc1_ = this.getDataSet(_strDataPath);
  114.       return _loc1_.childNodes.length;
  115.    }
  116.    function getChild(_objXMLNode, _iIndex)
  117.    {
  118.       return _objXMLNode.childNodes[_iIndex];
  119.    }
  120.    function getValue(objNode, strAttribute)
  121.    {
  122.       var _loc1_ = objNode;
  123.       var _loc2_ = strAttribute;
  124.       if(_loc1_ && _loc1_.firstChild && _loc1_.firstChild.nodeType == 3 && _loc2_ == undefined)
  125.       {
  126.          return _loc1_.firstChild.nodeValue;
  127.       }
  128.       if(_loc1_ && _loc2_ != undefined)
  129.       {
  130.          return _loc1_.attributes[_loc2_];
  131.       }
  132.       return undefined;
  133.    }
  134.    function findNode(objNode, strNodeName)
  135.    {
  136.       var _loc2_ = objNode;
  137.       var _loc3_ = strNodeName;
  138.       var _loc1_ = 0;
  139.       while(_loc2_.childNodes && _loc1_ < _loc2_.childNodes.length)
  140.       {
  141.          if(_loc2_.childNodes[_loc1_].nodeName == _loc3_)
  142.          {
  143.             return _loc2_.childNodes[_loc1_];
  144.          }
  145.          _loc1_ = _loc1_ + 1;
  146.       }
  147.       return undefined;
  148.    }
  149.    function findNodeRec(objNode, strNodeName)
  150.    {
  151.       var _loc3_ = objNode;
  152.       if(_loc3_.nodeName == strNodeName)
  153.       {
  154.          return _loc3_;
  155.       }
  156.       var _loc1_ = 0;
  157.       while(_loc3_.childNodes && _loc1_ < _loc3_.childNodes.length)
  158.       {
  159.          var _loc2_ = this.findNode(_loc3_.childNodes[_loc1_],strNodeName);
  160.          if(_loc2_ != null)
  161.          {
  162.             return _loc2_;
  163.          }
  164.          _loc1_ = _loc1_ + 1;
  165.       }
  166.       return undefined;
  167.    }
  168. }
  169.