home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Multimedija / shufflr.air / ShufflrClient.swf / scripts / mx / rpc / AbstractService.as < prev    next >
Encoding:
Text File  |  2010-06-23  |  8.4 KB  |  288 lines

  1. package mx.rpc
  2. {
  3.    import flash.events.Event;
  4.    import flash.events.EventDispatcher;
  5.    import flash.events.IEventDispatcher;
  6.    import flash.utils.Proxy;
  7.    import flash.utils.flash_proxy;
  8.    import mx.core.mx_internal;
  9.    import mx.messaging.ChannelSet;
  10.    import mx.resources.IResourceManager;
  11.    import mx.resources.ResourceManager;
  12.    import mx.rpc.events.AbstractEvent;
  13.    
  14.    use namespace mx_internal;
  15.    use namespace flash_proxy;
  16.    
  17.    [Bindable(event="operationsChange")]
  18.    public dynamic class AbstractService extends Proxy implements IEventDispatcher
  19.    {
  20.       mx_internal var _operations:Object;
  21.       
  22.       private var _initialized:Boolean = false;
  23.       
  24.       mx_internal var _availableChannelIds:Array;
  25.       
  26.       private var resourceManager:IResourceManager = ResourceManager.getInstance();
  27.       
  28.       private var _managers:Array;
  29.       
  30.       private var nextNameArray:Array;
  31.       
  32.       private var eventDispatcher:EventDispatcher;
  33.       
  34.       mx_internal var asyncRequest:AsyncRequest;
  35.       
  36.       public function AbstractService(param1:String = null)
  37.       {
  38.          super();
  39.          eventDispatcher = new EventDispatcher(this);
  40.          mx_internal::asyncRequest = new AsyncRequest();
  41.          if(param1)
  42.          {
  43.             this.destination = param1;
  44.             mx_internal::asyncRequest.destination = param1;
  45.          }
  46.          mx_internal::_operations = {};
  47.       }
  48.       
  49.       public function willTrigger(param1:String) : Boolean
  50.       {
  51.          return eventDispatcher.willTrigger(param1);
  52.       }
  53.       
  54.       public function get destination() : String
  55.       {
  56.          return mx_internal::asyncRequest.destination;
  57.       }
  58.       
  59.       public function initialize() : void
  60.       {
  61.          var _loc1_:int = 0;
  62.          var _loc2_:Object = null;
  63.          if(!_initialized && _managers != null)
  64.          {
  65.             _loc1_ = 0;
  66.             while(_loc1_ < _managers.length)
  67.             {
  68.                _loc2_ = _managers[_loc1_];
  69.                if(_loc2_.hasOwnProperty("initialize"))
  70.                {
  71.                   _loc2_.initialize();
  72.                }
  73.                _loc1_++;
  74.             }
  75.             _initialized = true;
  76.          }
  77.       }
  78.       
  79.       public function logout() : void
  80.       {
  81.          mx_internal::asyncRequest.logout();
  82.       }
  83.       
  84.       public function setRemoteCredentials(param1:String, param2:String, param3:String = null) : void
  85.       {
  86.          mx_internal::asyncRequest.setRemoteCredentials(param1,param2,param3);
  87.       }
  88.       
  89.       mx_internal function hasTokenResponders(param1:Event) : Boolean
  90.       {
  91.          var _loc2_:AbstractEvent = null;
  92.          if(param1 is AbstractEvent)
  93.          {
  94.             _loc2_ = param1 as AbstractEvent;
  95.             if(_loc2_.token != null && _loc2_.token.hasResponder())
  96.             {
  97.                return true;
  98.             }
  99.          }
  100.          return false;
  101.       }
  102.       
  103.       public function disconnect() : void
  104.       {
  105.          mx_internal::asyncRequest.disconnect();
  106.       }
  107.       
  108.       override flash_proxy function nextName(param1:int) : String
  109.       {
  110.          return nextNameArray[param1 - 1];
  111.       }
  112.       
  113.       public function set destination(param1:String) : void
  114.       {
  115.          mx_internal::asyncRequest.destination = param1;
  116.       }
  117.       
  118.       public function set requestTimeout(param1:int) : void
  119.       {
  120.          if(requestTimeout != param1)
  121.          {
  122.             mx_internal::asyncRequest.requestTimeout = param1;
  123.          }
  124.       }
  125.       
  126.       public function valueOf() : Object
  127.       {
  128.          return this;
  129.       }
  130.       
  131.       public function getOperation(param1:String) : AbstractOperation
  132.       {
  133.          var _loc2_:Object = mx_internal::_operations[param1];
  134.          return _loc2_ is AbstractOperation ? AbstractOperation(_loc2_) : null;
  135.       }
  136.       
  137.       public function setCredentials(param1:String, param2:String, param3:String = null) : void
  138.       {
  139.          mx_internal::asyncRequest.setCredentials(param1,param2,param3);
  140.       }
  141.       
  142.       public function set channelSet(param1:ChannelSet) : void
  143.       {
  144.          if(channelSet != param1)
  145.          {
  146.             mx_internal::asyncRequest.channelSet = param1;
  147.          }
  148.       }
  149.       
  150.       public function dispatchEvent(param1:Event) : Boolean
  151.       {
  152.          return eventDispatcher.dispatchEvent(param1);
  153.       }
  154.       
  155.       public function removeEventListener(param1:String, param2:Function, param3:Boolean = false) : void
  156.       {
  157.          eventDispatcher.removeEventListener(param1,param2,param3);
  158.       }
  159.       
  160.       override flash_proxy function getProperty(param1:*) : *
  161.       {
  162.          return getOperation(mx_internal::getLocalName(param1));
  163.       }
  164.       
  165.       public function set managers(param1:Array) : void
  166.       {
  167.          var _loc2_:int = 0;
  168.          var _loc3_:Object = null;
  169.          if(_managers != null)
  170.          {
  171.             _loc2_ = 0;
  172.             while(_loc2_ < _managers.length)
  173.             {
  174.                _loc3_ = _managers[_loc2_];
  175.                if(_loc3_.hasOwnProperty("service"))
  176.                {
  177.                   _loc3_.service = null;
  178.                }
  179.                _loc2_++;
  180.             }
  181.          }
  182.          _managers = param1;
  183.          _loc2_ = 0;
  184.          while(_loc2_ < param1.length)
  185.          {
  186.             _loc3_ = _managers[_loc2_];
  187.             if(_loc3_.hasOwnProperty("service"))
  188.             {
  189.                _loc3_.service = this;
  190.             }
  191.             if(_initialized && Boolean(_loc3_.hasOwnProperty("initialize")))
  192.             {
  193.                _loc3_.initialize();
  194.             }
  195.             _loc2_++;
  196.          }
  197.       }
  198.       
  199.       public function get requestTimeout() : int
  200.       {
  201.          return mx_internal::asyncRequest.requestTimeout;
  202.       }
  203.       
  204.       override flash_proxy function callProperty(param1:*, ... rest) : *
  205.       {
  206.          return getOperation(mx_internal::getLocalName(param1)).send.apply(null,rest);
  207.       }
  208.       
  209.       public function addEventListener(param1:String, param2:Function, param3:Boolean = false, param4:int = 0, param5:Boolean = false) : void
  210.       {
  211.          eventDispatcher.addEventListener(param1,param2,param3,param4,param5);
  212.       }
  213.       
  214.       override flash_proxy function nextValue(param1:int) : *
  215.       {
  216.          return mx_internal::_operations[nextNameArray[param1 - 1]];
  217.       }
  218.       
  219.       override flash_proxy function setProperty(param1:*, param2:*) : void
  220.       {
  221.          var _loc3_:String = resourceManager.getString("rpc","operationsNotAllowedInService",[mx_internal::getLocalName(param1)]);
  222.          throw new Error(_loc3_);
  223.       }
  224.       
  225.       public function set operations(param1:Object) : void
  226.       {
  227.          var _loc2_:AbstractOperation = null;
  228.          var _loc3_:String = null;
  229.          for(_loc3_ in param1)
  230.          {
  231.             _loc2_ = AbstractOperation(param1[_loc3_]);
  232.             _loc2_.mx_internal::setService(this);
  233.             if(!_loc2_.name)
  234.             {
  235.                _loc2_.name = _loc3_;
  236.             }
  237.             _loc2_.mx_internal::asyncRequest = mx_internal::asyncRequest;
  238.          }
  239.          mx_internal::_operations = param1;
  240.          dispatchEvent(new Event("operationsChange"));
  241.       }
  242.       
  243.       public function get channelSet() : ChannelSet
  244.       {
  245.          return mx_internal::asyncRequest.channelSet;
  246.       }
  247.       
  248.       mx_internal function getLocalName(param1:Object) : String
  249.       {
  250.          if(param1 is QName)
  251.          {
  252.             return QName(param1).localName;
  253.          }
  254.          return String(param1);
  255.       }
  256.       
  257.       override flash_proxy function nextNameIndex(param1:int) : int
  258.       {
  259.          var _loc2_:String = null;
  260.          if(param1 == 0)
  261.          {
  262.             nextNameArray = [];
  263.             for(_loc2_ in mx_internal::_operations)
  264.             {
  265.                nextNameArray.push(_loc2_);
  266.             }
  267.          }
  268.          return param1 < nextNameArray.length ? param1 + 1 : 0;
  269.       }
  270.       
  271.       public function get managers() : Array
  272.       {
  273.          return _managers;
  274.       }
  275.       
  276.       public function get operations() : Object
  277.       {
  278.          return mx_internal::_operations;
  279.       }
  280.       
  281.       public function hasEventListener(param1:String) : Boolean
  282.       {
  283.          return eventDispatcher.hasEventListener(param1);
  284.       }
  285.    }
  286. }
  287.  
  288.