convert this as3 into typescript

package com.playsaurus.model
{
   import by.blooddy.crypto.Base64;
   import com.adobe.serialization.json.JSONDecoder;
   import com.adobe.serialization.json.JSONEncoder;
   import com.bigDecimal.com.BigDecimal;
   import com.doogog.utils.MiscUtils;
   import com.maccherone.json.JSONEncoder;
   import com.playsaurus.numbers.BigNumber;
   import com.playsaurus.staticData.StaticData;
   import flash.utils.ByteArray;
   import flash.utils.getQualifiedClassName;
   
   public class Model
   {
      
      private static var _cache:Object = new Object();
      
      private static var _enableCaching:Boolean = true;
      
      private static var _reusableByteArray:ByteArray = new ByteArray();
      
      public static const DYNAMIC_STRING:int = 0;
      
      public static const DYNAMIC_NUMBER:int = 1;
      
      public static const DYNAMIC_BOOLEAN:int = 2;
      
      public static const DYNAMIC_OBJECT:int = 3;
      
      public static const DYNAMIC_CHILD:int = 4;
      
      public static const DYNAMIC_COLLECTION:int = 5;
      
      public static const DYNAMIC_BIG_DECIMAL:int = 6;
      
      public static const DYNAMIC_BIG_NUMBER:int = 7;
      
      public static const DYNAMIC_BYTE_ARRAY:int = 8;
      
      public static const STATIC_STRING:int = 10;
      
      public static const STATIC_INTEGER:int = 11;
      
      public static const STATIC_FLOAT:int = 12;
      
      public static const STATIC_FOREIGN_KEY:int = 13;
      
      public static const STATIC_COLLECTION:int = 14;
      
      public static const STATIC_M2M_COLLECTION:int = 15;
      
      public static const STATIC_BIG_DECIMAL:int = 16;
      
      public static const STATIC_BIG_NUMBER:int = 17;
      
      protected static const PARENT:int = 0;
      
      protected static const VAR_NAME:int = 1;
      
      protected static const COLLECTION_KEY:int = 2;
       
      
      private var _staticFields:Array;
      
      private var _dynamicFields:Object;
      
      private var _childClasses:Array;
      
      private var _staticTable:String = null;
      
      private var _staticPrimaryKey:String = null;
      
      private var _staticForeignKeys:Array;
      
      private var _staticCollections:Array;
      
      private var _staticM2MCollections:Array;
      
      protected var _dynamicParentReference:Array;
      
      private var _dynamicRoot:Model = null;
      
      public function Model()
      {
         this._staticFields = new Array();
         this._dynamicFields = new Object();
         this._childClasses = new Array();
         this._staticForeignKeys = new Array();
         this._staticCollections = new Array();
         this._staticM2MCollections = new Array();
         this._dynamicParentReference = new Array();
         super();
      }
      
      public function get staticTable() : String
      {
         return this._staticTable;
      }
      
      public function get staticPrimaryKey() : String
      {
         return this._staticPrimaryKey;
      }
      
      public function rowsInTable() : int
      {
         return MiscUtils.lengthOfObject(StaticData.instance.getAll(Object(this).constructor as Class));
      }
      
      public function sizeOfTable() : int
      {
         return this.rowsInTable();
      }
      
      public function dispose() : void
      {
      }
      
      protected function getStatic(param1:String) : *
      {
         var _loc2_:Class = null;
         var _loc3_:String = null;
         var _loc4_:String = null;
         var _loc5_:Model = null;
         var _loc6_:Object = null;
         var _loc7_:String = null;
         var _loc8_:String = null;
         var _loc9_:Object = null;
         var _loc10_:String = null;
         var _loc11_:String = null;
         var _loc12_:String = null;
         var _loc13_:Array = null;
         var _loc14_:BigDecimal = null;
         var _loc15_:BigNumber = null;
         var _loc16_:Object = null;
         if(!this._staticFields.hasOwnProperty(param1))
         {
            throw new Error("Unregistered static property \'" + param1 + "\' in \'" + this + "\' model");
         }
         if(this._staticTable)
         {
            if(!(_loc9_ = StaticData.instance.getTable(this._staticTable)).hasOwnProperty(this[this._staticPrimaryKey]))
            {
               throw new Error("Key \'" + this[this._staticPrimaryKey] + "\' does not exist in table \'" + this._staticTable + "\'.");
            }
         }
         switch(this._staticFields[param1])
         {
            case Model.STATIC_STRING:
               return _loc9_[this[this._staticPrimaryKey]][param1];
            case Model.STATIC_INTEGER:
            case Model.STATIC_FLOAT:
               return Number(_loc9_[this[this._staticPrimaryKey]][param1]);
            case Model.STATIC_FOREIGN_KEY:
               _loc2_ = this._staticForeignKeys[param1][0];
               _loc3_ = String(this._staticForeignKeys[param1][1]);
               if(!this[_loc3_])
               {
                  return null;
               }
               _loc5_ = new _loc2_();
               _loc5_[_loc5_._staticPrimaryKey] = this[_loc3_];
               return _loc5_;
               break;
            case Model.STATIC_COLLECTION:
               _loc2_ = this._staticCollections[param1][0];
               _loc4_ = String(this._staticCollections[param1][1]);
               _loc7_ = "1:M:" + _loc4_ + ":" + this[this._staticPrimaryKey];
               if(_cache.hasOwnProperty(_loc2_) && _cache[_loc2_].hasOwnProperty(_loc7_) && _enableCaching)
               {
                  return _cache[_loc2_][_loc7_];
               }
               _loc5_ = new _loc2_();
               _loc6_ = new Object();
               if(_loc9_[this[this._staticPrimaryKey]].hasOwnProperty("_" + param1 + "Index"))
               {
                  for each(_loc8_ in _loc9_[this[this._staticPrimaryKey]]["_" + param1 + "Index"])
                  {
                     _loc5_ = new _loc2_();
                     _loc5_[_loc5_._staticPrimaryKey] = _loc8_;
                     _loc6_[_loc8_] = _loc5_;
                  }
               }
               else
               {
                  _loc9_ = StaticData.instance.getTable(_loc5_._staticTable);
                  for(_loc8_ in _loc9_)
                  {
                     if(_loc9_[_loc8_][_loc4_] == this[this._staticPrimaryKey])
                     {
                        _loc5_ = new _loc2_();
                        _loc5_[_loc5_._staticPrimaryKey] = _loc8_;
                        _loc6_[_loc8_] = _loc5_;
                     }
                  }
               }
               if(_enableCaching)
               {
                  if(!_cache.hasOwnProperty(_loc2_))
                  {
                     _cache[_loc2_] = new Object();
                  }
                  _cache[_loc2_][_loc7_] = _loc6_;
               }
               return _loc6_;
               break;
            case Model.STATIC_M2M_COLLECTION:
               _loc2_ = this._staticM2MCollections[param1][0];
               _loc10_ = String(this._staticM2MCollections[param1][1]);
               _loc11_ = String(this._staticM2MCollections[param1][2]);
               _loc12_ = String(this._staticM2MCollections[param1][3]);
               _loc7_ = "M:M:" + _loc10_ + "-" + _loc11_ + "-" + _loc12_ + ":" + this[this._staticPrimaryKey];
               _loc5_ = new _loc2_();
               _loc13_ = [];
               if(_loc9_[this[this._staticPrimaryKey]].hasOwnProperty("_" + param1 + "Index"))
               {
                  _loc13_ = _loc9_[this[this._staticPrimaryKey]]["_" + param1 + "Index"];
               }
               else
               {
                  _loc16_ = StaticData.instance.getTable(_loc11_);
                  for(_loc8_ in _loc16_)
                  {
                     if(_loc16_[_loc8_][_loc10_] == this[this._staticPrimaryKey])
                     {
                        _loc13_.push(_loc16_[_loc8_][_loc12_]);
                     }
                  }
               }
               _loc6_ = new Object();
               for each(_loc8_ in _loc13_)
               {
                  _loc5_ = new _loc2_();
                  _loc5_[_loc5_._staticPrimaryKey] = _loc8_;
                  _loc6_[_loc8_] = _loc5_;
               }
               return _loc6_;
            case Model.STATIC_BIG_DECIMAL:
               return new BigDecimal(_loc9_[this[this._staticPrimaryKey]][param1]);
            case Model.STATIC_BIG_NUMBER:
               return new BigNumber(_loc9_[this[this._staticPrimaryKey]][param1]);
            default:
               throw new ModelException("Unknown static data type.");
         }
      }
      
      public function setStatic(param1:String, param2:*) : void
      {
         var _loc4_:String = null;
         var _loc5_:Class = null;
         var _loc6_:BigDecimal = null;
         var _loc7_:BigNumber = null;
         trace("Warning: Setting static data fields will disable internal model caching.");
         trace("This should never be executed by users.");
         _enableCaching = false;
         var _loc3_:Object = StaticData.instance.getTable(this._staticTable);
         if(!_loc3_.hasOwnProperty(this[this._staticPrimaryKey]))
         {
            throw new Error("Key \'" + this[this._staticPrimaryKey] + "\' does not exist in table \'" + this._staticTable + "\'.");
         }
         if(!this._staticFields.hasOwnProperty(param1))
         {
            throw new Error("Undefined static property \'" + param1 + "\'");
         }
         switch(this._staticFields[param1])
         {
            case Model.STATIC_STRING:
            case Model.STATIC_INTEGER:
            case Model.STATIC_FLOAT:
               _loc3_[this[this._staticPrimaryKey]][param1] = param2;
               break;
            case Model.STATIC_FOREIGN_KEY:
               _loc4_ = String(this._staticForeignKeys[param1][1]);
               this[_loc4_] = param2[param2._staticPrimaryKey];
               break;
            case Model.STATIC_COLLECTION:
               throw new ModelException("Collection setting needs to be implemented");
            case Model.STATIC_M2M_COLLECTION:
               throw new ModelException("M2M Collection setting needs to be implemented");
            case Model.STATIC_BIG_DECIMAL:
               _loc6_ = new BigDecimal(param2);
               _loc3_[this[this._staticPrimaryKey]][param1] = _loc6_;
               break;
            case Model.STATIC_BIG_NUMBER:
               _loc7_ = new BigNumber(param2);
               _loc3_[this[this._staticPrimaryKey]][param1] = _loc7_;
               break;
            default:
               throw new ModelException("Unknown static data type.");
         }
      }
      
      protected function registerStaticString(param1:String) : void
      {
         this._staticFields[param1] = Model.STATIC_STRING;
      }
      
      protected function registerStaticInteger(param1:String) : void
      {
         this._staticFields[param1] = Model.STATIC_INTEGER;
      }
      
      protected function registerStaticFloat(param1:String) : void
      {
         this._staticFields[param1] = Model.STATIC_FLOAT;
      }
      
      protected function registerStaticBigDecimal(param1:String) : void
      {
         this._staticFields[param1] = Model.STATIC_BIG_DECIMAL;
      }
      
      protected function registerStaticBigNumber(param1:String) : void
      {
         this._staticFields[param1] = Model.STATIC_BIG_NUMBER;
      }
      
      protected function registerStaticForeignKey(param1:String, param2:Class, param3:String) : void
      {
         this._staticFields[param1] = Model.STATIC_FOREIGN_KEY;
         this._staticForeignKeys[param1] = [param2,param3];
      }
      
      public function registerStaticCollection(param1:String, param2:Class, param3:String) : void
      {
         this._staticFields[param1] = Model.STATIC_COLLECTION;
         this._staticCollections[param1] = [param2,param3];
      }
      
      protected function registerStaticM2MCollection(param1:String, param2:Class, param3:String, param4:String, param5:String) : void
      {
         this._staticFields[param1] = Model.STATIC_M2M_COLLECTION;
         this._staticM2MCollections[param1] = [param2,param3,param4,param5];
      }
      
      protected function registerStaticTable(param1:String) : void
      {
         this._staticTable = param1;
      }
      
      protected function registerStaticPrimaryKey(param1:String) : void
      {
         this._staticPrimaryKey = param1;
         this._dynamicFields[param1] = Model.DYNAMIC_NUMBER;
      }
      
      protected function registerDynamicBoolean(param1:String) : void
      {
         this._dynamicFields[param1] = Model.DYNAMIC_BOOLEAN;
      }
      
      protected function registerDynamicNumber(param1:String) : void
      {
         this._dynamicFields[param1] = Model.DYNAMIC_NUMBER;
      }
      
      protected function registerDynamicString(param1:String) : void
      {
         this._dynamicFields[param1] = Model.DYNAMIC_STRING;
      }
      
      protected function registerDynamicObject(param1:String) : void
      {
         this._dynamicFields[param1] = Model.DYNAMIC_OBJECT;
      }
      
      protected function registerDynamicChild(param1:String, param2:Class) : void
      {
         this._dynamicFields[param1] = Model.DYNAMIC_CHILD;
         this._childClasses[param1] = param2;
      }
      
      protected function registerDynamicCollection(param1:String, param2:Class) : void
      {
         this._dynamicFields[param1] = Model.DYNAMIC_COLLECTION;
         this._childClasses[param1] = param2;
      }
      
      protected function registerDynamicBigDecimal(param1:String) : void
      {
         this._dynamicFields[param1] = Model.DYNAMIC_BIG_DECIMAL;
      }
      
      protected function registerDynamicBigNumber(param1:String) : void
      {
         this._dynamicFields[param1] = Model.DYNAMIC_BIG_NUMBER;
      }
      
      protected function registerDynamicByteArray(param1:String) : void
      {
         this._dynamicFields[param1] = Model.DYNAMIC_BYTE_ARRAY;
      }
      
      public function fromJson(param1:String) : void
      {
         var _loc2_:Object = new JSONDecoder(param1,true).getValue();
         this.fromJsonObject(_loc2_);
      }
      
      public function fromJsonObject(param1:Object) : void
      {
         var _loc2_:Class = null;
         var _loc3_:String = null;
         var _loc4_:String = null;
         for(_loc3_ in this._dynamicFields)
         {
            switch(this._dynamicFields[_loc3_])
            {
               case Model.DYNAMIC_BOOLEAN:
               case Model.DYNAMIC_NUMBER:
               case Model.DYNAMIC_STRING:
                  if(param1.hasOwnProperty(_loc3_))
                  {
                     this[_loc3_] = param1[_loc3_];
                  }
                  break;
               case Model.DYNAMIC_BIG_DECIMAL:
                  if(param1.hasOwnProperty(_loc3_))
                  {
                     if(param1[_loc3_] is Number)
                     {
                        this[_loc3_] = new BigDecimal(param1[_loc3_]);
                     }
                     else
                     {
                        this[_loc3_] = new BigDecimal(param1[_loc3_]);
                     }
                  }
                  break;
               case Model.DYNAMIC_BIG_NUMBER:
                  if(param1.hasOwnProperty(_loc3_))
                  {
                     if(param1[_loc3_] is Number)
                     {
                        this[_loc3_] = new BigNumber(param1[_loc3_]);
                     }
                     else
                     {
                        this[_loc3_] = new BigNumber(param1[_loc3_]);
                     }
                  }
                  break;
               case Model.DYNAMIC_BYTE_ARRAY:
                  if(param1.hasOwnProperty(_loc3_))
                  {
                     this[_loc3_] = new ByteArray();
                     this[_loc3_] = Base64.decode(param1[_loc3_]);
                     this[_loc3_].inflate();
                  }
                  break;
               case Model.DYNAMIC_OBJECT:
                  if(param1.hasOwnProperty(_loc3_))
                  {
                     this[_loc3_] = MiscUtils.clone(param1[_loc3_]);
                  }
                  break;
               case Model.DYNAMIC_CHILD:
                  if(param1[_loc3_])
                  {
                     _loc2_ = this._childClasses[_loc3_];
                     this[_loc3_] = new _loc2_();
                     this[_loc3_].fromJsonObject(param1[_loc3_]);
                     this[_loc3_].setDynamicParentInfo(this,_loc3_);
                  }
                  break;
               case Model.DYNAMIC_COLLECTION:
                  _loc2_ = this._childClasses[_loc3_];
                  if(this[_loc3_] == null)
                  {
                     this[_loc3_] = new Object();
                  }
                  for(_loc4_ in param1[_loc3_])
                  {
                     this[_loc3_][_loc4_] = new _loc2_();
                     this[_loc3_][_loc4_].fromJsonObject(param1[_loc3_][_loc4_]);
                     this[_loc3_][_loc4_].setDynamicParentInfo(this,_loc3_,_loc4_);
                  }
                  break;
               default:
                  throw new ModelException("Unknown dynamic data type");
            }
         }
      }
      
      public function setDynamicParentInfo(param1:Model, param2:String, param3:* = null) : void
      {
         this._dynamicParentReference[PARENT] = param1;
         this._dynamicParentReference[VAR_NAME] = param2;
         if(param3)
         {
            this._dynamicParentReference[COLLECTION_KEY] = param3;
         }
         this._dynamicRoot = param1.getDynamicRoot();
      }
      
      public function getDynamicRoot() : Model
      {
         if(!this._dynamicRoot)
         {
            return this;
         }
         return this._dynamicRoot.getDynamicRoot();
      }
      
      public function toJson(param1:Boolean = false) : String
      {
         return new com.adobe.serialization.json.JSONEncoder(this.toJsonObject(param1)).getString();
      }
      
      public function toJsonObject(param1:Boolean = false) : Object
      {
         var _loc3_:String = null;
         var _loc4_:Array = null;
         var _loc5_:BigDecimal = null;
         var _loc6_:BigNumber = null;
         var _loc7_:String = null;
         var _loc2_:Object = new Object();
         for(_loc3_ in this._dynamicFields)
         {
            switch(this._dynamicFields[_loc3_])
            {
               case Model.DYNAMIC_BOOLEAN:
               case Model.DYNAMIC_NUMBER:
               case Model.DYNAMIC_STRING:
                  _loc2_[_loc3_] = this[_loc3_];
                  break;
               case Model.DYNAMIC_BIG_DECIMAL:
                  if(this[_loc3_] is BigDecimal && this[_loc3_].mant == null || this[_loc3_] == "null" || this[_loc3_] == null)
                  {
                     this[_loc3_] = new BigDecimal(0);
                  }
                  _loc5_ = this[_loc3_];
                  _loc2_[_loc3_] = _loc5_.toScientific(_loc5_);
                  break;
               case Model.DYNAMIC_BIG_NUMBER:
                  if(this[_loc3_] == "null" || this[_loc3_] == null)
                  {
                     this[_loc3_] = new BigNumber(0);
                  }
                  _loc6_ = this[_loc3_];
                  _loc2_[_loc3_] = _loc6_.toScientific(_loc6_);
                  break;
               case Model.DYNAMIC_OBJECT:
                  if(param1)
                  {
                     _loc2_[_loc3_] = new Object();
                     _loc4_ = new Array();
                     for(_loc7_ in this[_loc3_])
                     {
                        _loc4_.push(_loc7_);
                     }
                     _loc4_.sort();
                     for each(_loc7_ in _loc4_)
                     {
                        _loc2_[_loc3_][_loc7_] = this[_loc3_][_loc7_];
                     }
                  }
                  else
                  {
                     _loc2_[_loc3_] = this[_loc3_];
                  }
                  break;
               case Model.DYNAMIC_BYTE_ARRAY:
                  this[_loc3_].position = 0;
                  _reusableByteArray.position = 0;
                  this[_loc3_].readBytes(_reusableByteArray,0,this[_loc3_].length);
                  _reusableByteArray.length = this[_loc3_].length;
                  _reusableByteArray.deflate();
                  _loc2_[_loc3_] = Base64.encode(_reusableByteArray);
                  _reusableByteArray.clear();
                  break;
               case Model.DYNAMIC_CHILD:
                  if(this[_loc3_])
                  {
                     _loc2_[_loc3_] = this[_loc3_].toJsonObject(param1);
                  }
                  else
                  {
                     _loc2_[_loc3_] = null;
                  }
                  break;
               case Model.DYNAMIC_COLLECTION:
                  _loc2_[_loc3_] = new Object();
                  _loc4_ = new Array();
                  for(_loc7_ in this[_loc3_])
                  {
                     _loc4_.push(_loc7_);
                  }
                  if(param1)
                  {
                     _loc4_.sort();
                  }
                  for each(_loc7_ in _loc4_)
                  {
                     _loc2_[_loc3_][_loc7_] = this[_loc3_][_loc7_].toJsonObject(param1);
                  }
                  break;
               default:
                  throw new ModelException("Unknown dynamic data type");
            }
         }
         return _loc2_;
      }
      
      public function toStaticObject(param1:Object = null) : Object
      {
         var _loc5_:String = null;
         var _loc6_:BigDecimal = null;
         var _loc7_:BigNumber = null;
         var _loc8_:Model = null;
         var _loc9_:Object = null;
         var _loc10_:* = undefined;
         if(param1 == null)
         {
            param1 = new Object();
         }
         var _loc2_:Object = new Object();
         var _loc3_:String = this._staticPrimaryKey;
         var _loc4_:Object = this[_loc3_];
         _loc2_[_loc3_] = _loc4_;
         if(!param1.hasOwnProperty(this._staticTable))
         {
            param1[this._staticTable] = new Object();
         }
         if(param1[this._staticTable].hasOwnProperty(_loc4_))
         {
            return param1;
         }
         param1[this._staticTable][_loc4_] = _loc2_;
         for(_loc5_ in this._staticFields)
         {
            switch(this._staticFields[_loc5_])
            {
               case Model.STATIC_INTEGER:
                  _loc2_[_loc5_] = this[_loc5_];
                  break;
               case Model.STATIC_STRING:
                  _loc2_[_loc5_] = this[_loc5_];
                  break;
               case Model.STATIC_FLOAT:
                  _loc2_[_loc5_] = this[_loc5_];
                  break;
               case Model.STATIC_BIG_DECIMAL:
                  if(this[_loc5_] is BigDecimal && this[_loc5_].mant == null || this[_loc5_] == "null" || this[_loc5_] == null)
                  {
                     this[_loc5_] = new BigDecimal(0);
                  }
                  _loc6_ = this[_loc5_];
                  _loc2_[_loc5_] = _loc6_.toScientific(_loc6_);
                  break;
               case Model.STATIC_BIG_NUMBER:
                  if(this[_loc5_] == "null" || this[_loc5_] == null)
                  {
                     this[_loc5_] = new BigNumber(0);
                  }
                  _loc7_ = this[_loc5_];
                  _loc2_[_loc5_] = _loc7_.toScientific(_loc7_);
                  break;
               case Model.STATIC_FOREIGN_KEY:
                  if(_loc8_ = this[_loc5_])
                  {
                     _loc8_.toStaticObject(param1);
                  }
                  break;
               case Model.STATIC_COLLECTION:
                  _loc9_ = this[_loc5_];
                  for(_loc10_ in _loc9_)
                  {
                     _loc9_[_loc10_].toStaticObject(param1);
                  }
                  break;
               case Model.STATIC_M2M_COLLECTION:
                  throw new Error("This has not been tested at all");
               default:
                  throw new ModelException("Unknown static data type");
            }
         }
         return param1;
      }
      
      public function getParent() : Model
      {
         return this._dynamicParentReference[PARENT];
      }
      
      public function getTreePath() : String
      {
         var _loc3_:String = null;
         var _loc4_:String = null;
         var _loc5_:* = null;
         var _loc1_:Model = this;
         var _loc2_:String = "";
         while(_loc1_.getParent())
         {
            _loc3_ = String(_loc1_._dynamicParentReference[VAR_NAME]);
            _loc4_ = String(_loc1_._dynamicParentReference[COLLECTION_KEY]);
            _loc5_ = "";
            if(_loc4_)
            {
               _loc5_ = _loc3_ + "[" + _loc4_ + "]";
            }
            else
            {
               _loc5_ = _loc3_;
            }
            if(_loc2_ != "")
            {
               _loc2_ = _loc5_ + "." + _loc2_;
            }
            else
            {
               _loc2_ = _loc5_;
            }
            _loc1_ = _loc1_.getParent();
         }
         return _loc2_;
      }
      
      public function getFromPath(param1:String) : *
      {
         var _loc4_:String = null;
         var _loc5_:* = undefined;
         var _loc6_:* = null;
         var _loc7_:Array = null;
         var _loc8_:Object = null;
         var _loc9_:* = null;
         var _loc10_:String = null;
         var _loc11_:String = null;
         var _loc12_:Array = null;
         var _loc13_:* = undefined;
         var _loc2_:* = this;
         var _loc3_:Array = new Array();
         if(param1)
         {
            _loc7_ = param1.split(".");
            for each(_loc9_ in _loc7_)
            {
               _loc3_ = _loc9_.match(/([\w]+)\(([-+=\/\w\d"', ]*)\)/);
               if(_loc3_)
               {
                  _loc10_ = String(_loc3_[1]);
                  if(_loc11_ = String(_loc3_[2]))
                  {
                     _loc12_ = _loc11_.split(",");
                     for(_loc13_ in _loc12_)
                     {
                        _loc12_[_loc13_] = _loc12_[_loc13_].replace(/^[\s]+|[\s]+$/gs,"");
                        _loc12_[_loc13_] = _loc12_[_loc13_].replace(/^['"]+|['"]+$/gs,"");
                        if(_loc12_[_loc13_] == "true")
                        {
                           _loc12_[_loc13_] = true;
                        }
                        if(_loc12_[_loc13_] == "false")
                        {
                           _loc12_[_loc13_] = false;
                        }
                        if(_loc12_[_loc13_] == Number(_loc12_[_loc13_]).toString())
                        {
                           _loc12_[_loc13_] = Number(_loc12_[_loc13_]);
                        }
                     }
                     _loc2_ = (_loc2_[_loc10_] as Function).apply(_loc2_,_loc12_);
                  }
                  else
                  {
                     _loc2_ = _loc2_[_loc10_]();
                  }
               }
               else
               {
                  _loc3_ = _loc9_.match(/^([\w]+)(\[([-\w\d]+)\])?$/);
                  if(!_loc3_)
                  {
                     throw new Error("Unknown tree path syntax \'" + _loc9_ + "\' in \'" + _loc7_ + "\'");
                  }
                  _loc4_ = String(_loc3_[1]);
                  if(_loc3_.length >= 4 && Boolean(_loc3_[3]))
                  {
                     if(isNaN(Number(_loc3_[3])))
                     {
                        _loc5_ = _loc3_[3];
                     }
                     else
                     {
                        _loc5_ = Number(_loc3_[3]);
                     }
                     _loc2_ = (_loc8_ = _loc2_[_loc4_])[_loc5_];
                  }
                  else
                  {
                     _loc2_ = _loc2_[_loc4_];
                  }
                  if(!_loc2_)
                  {
                     throw new ModelPathException("\'" + _loc9_ + "." + _loc4_ + "\' returned no object, so the path \'" + _loc7_ + "\' cannot be completed");
                  }
               }
            }
         }
         return _loc2_;
      }
      
      public function getFields() : Object
      {
         return this._dynamicFields;
      }
      
      public function getModelDefinition() : Object
      {
         return {
            "dynamicFields":this._dynamicFields,
            "staticFields":this._staticFields,
            "staticForeignKeys":this._staticForeignKeys,
            "staticTable":this._staticTable,
            "staticM2MCollections":this._staticM2MCollections,
            "staticPrimaryKey":this._staticPrimaryKey,
            "staticCollections":this._staticCollections
         };
      }
      
      public function jsonPrettyPrint(param1:Array) : String
      {
         var _loc6_:* = null;
         var _loc7_:Object = null;
         var _loc8_:String = null;
         var _loc9_:com.maccherone.json.JSONEncoder = null;
         var _loc10_:String = null;
         var _loc2_:* = this;
         var _loc3_:* = this;
         var _loc4_:String = getQualifiedClassName(this);
         var _loc5_:String = "";
         for each(_loc6_ in param1)
         {
            if(_loc6_ == "*")
            {
               _loc5_ += "Fields in " + _loc4_ + ":" + "\n";
               if(_loc3_ is Model)
               {
                  for(_loc8_ in (_loc3_ as Model).getFields())
                  {
                     _loc5_ += _loc8_ + "\n";
                  }
                  return _loc5_;
               }
               _loc5_ += "dunno what\'s wrong with that object, it\'s not a model\n";
            }
            if(_loc2_.hasOwnProperty(_loc6_))
            {
               _loc2_ = _loc2_[_loc6_];
            }
            else
            {
               _loc5_ += "\'" + _loc4_ + "\' does not have property \'" + _loc6_ + "\'" + "\n";
            }
            _loc4_ = _loc6_;
            _loc3_ = _loc2_;
         }
         if(_loc2_ is Model)
         {
            _loc7_ = new JSONDecoder(_loc2_.toJson(),true).getValue();
            _loc10_ = (_loc9_ = new com.maccherone.json.JSONEncoder(_loc7_,true,30)).getString();
            _loc5_ += _loc10_;
         }
         else
         {
            _loc5_ += _loc2_;
         }
         return _loc5_;
      }
   }
}