home *** CD-ROM | disk | FTP | other *** search
/ FCE Gold Plus / GOLD.iso / pc / fscommand / linux / main.swf / scripts / __Packages / com / data / DAO.as next >
Encoding:
Text File  |  2007-09-06  |  5.0 KB  |  171 lines

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