home *** CD-ROM | disk | FTP | other *** search
/ One Click 21 (Special) / OC021.iso / Interface / it.dig / scripts / __Packages / mx / data / binding / DataAccessor.as < prev    next >
Encoding:
Text File  |  2006-07-04  |  3.4 KB  |  124 lines

  1. class mx.data.binding.DataAccessor
  2. {
  3.    var dataAccessor;
  4.    var component;
  5.    var property;
  6.    var location;
  7.    var type;
  8.    function DataAccessor()
  9.    {
  10.    }
  11.    function getAnyTypedValue(suggestedTypes)
  12.    {
  13.       var _loc3_ = 0;
  14.       while(_loc3_ < suggestedTypes.length)
  15.       {
  16.          var _loc5_ = this.getTypedValue(suggestedTypes[_loc3_]);
  17.          if(_loc5_ != null)
  18.          {
  19.             return _loc5_;
  20.          }
  21.          _loc3_ = _loc3_ + 1;
  22.       }
  23.       _loc5_ = this.getTypedValue();
  24.       _loc3_ = 0;
  25.       while(_loc3_ < suggestedTypes.length)
  26.       {
  27.          var _loc2_ = suggestedTypes[_loc3_];
  28.          if(_loc2_ == "String")
  29.          {
  30.             return new mx.data.binding.TypedValue(String(_loc5_.value),_loc2_);
  31.          }
  32.          if(_loc2_ == "Number")
  33.          {
  34.             return new mx.data.binding.TypedValue(Number(_loc5_.value),_loc2_);
  35.          }
  36.          if(_loc2_ == "Boolean")
  37.          {
  38.             return new mx.data.binding.TypedValue(Boolean(_loc5_.value),_loc2_);
  39.          }
  40.          _loc3_ = _loc3_ + 1;
  41.       }
  42.       return _loc5_;
  43.    }
  44.    function setAnyTypedValue(newValue)
  45.    {
  46.       var _loc7_ = this.getSettableTypes();
  47.       if(_loc7_ == null || -1 != mx.data.binding.DataAccessor.findString(newValue.typeName,_loc7_))
  48.       {
  49.          return this.setTypedValue(newValue);
  50.       }
  51.       var _loc3_ = 0;
  52.       while(_loc3_ < _loc7_.length)
  53.       {
  54.          var _loc2_ = _loc7_[_loc3_];
  55.          if(_loc2_ == "String")
  56.          {
  57.             return this.setTypedValue(new mx.data.binding.TypedValue(String(newValue.value),_loc2_));
  58.          }
  59.          if(_loc2_ == "Number")
  60.          {
  61.             var _loc5_ = Number(newValue.value);
  62.             var _loc6_ = this.setTypedValue(new mx.data.binding.TypedValue(_loc5_,_loc2_));
  63.             if(_loc5_.toString() == "NaN")
  64.             {
  65.                return ["Failed to convert \'" + newValue.value + "\' to a number"];
  66.             }
  67.             return _loc6_;
  68.          }
  69.          if(_loc2_ == "Boolean")
  70.          {
  71.             return this.setTypedValue(new mx.data.binding.TypedValue(Boolean(newValue.value),_loc2_));
  72.          }
  73.          _loc3_ = _loc3_ + 1;
  74.       }
  75.       return this.dataAccessor.setTypedValue(newValue);
  76.    }
  77.    function getTypedValue(requestedType)
  78.    {
  79.       var _loc2_ = this.dataAccessor.getTypedValue(requestedType);
  80.       return _loc2_;
  81.    }
  82.    function getGettableTypes()
  83.    {
  84.       return null;
  85.    }
  86.    function setTypedValue(newValue)
  87.    {
  88.       return this.dataAccessor.setTypedValue(newValue);
  89.    }
  90.    function getSettableTypes()
  91.    {
  92.       return null;
  93.    }
  94.    function findLastAccessor()
  95.    {
  96.       return this.dataAccessor != null ? this.dataAccessor.findLastAccessor() : this;
  97.    }
  98.    function setupDataAccessor(component, property, location)
  99.    {
  100.       this.component = component;
  101.       this.property = property;
  102.       this.location = location;
  103.       this.type = component.findSchema(property,location);
  104.    }
  105.    static function findString(str, arr)
  106.    {
  107.       var _loc3_ = str.toLowerCase();
  108.       var _loc1_ = 0;
  109.       while(_loc1_ < arr.length)
  110.       {
  111.          if(arr[_loc1_].toLowerCase() == _loc3_)
  112.          {
  113.             return _loc1_;
  114.          }
  115.          _loc1_ = _loc1_ + 1;
  116.       }
  117.       return -1;
  118.    }
  119.    static function conversionFailed(newValue, target)
  120.    {
  121.       return "Failed to convert to " + target + ": \'" + newValue.value + "\'";
  122.    }
  123. }
  124.