home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Darbas / kidoz_v1.air / kidoz.swf / scripts / mx / messaging / messages / AbstractMessage.as next >
Encoding:
Text File  |  2009-05-06  |  10.6 KB  |  391 lines

  1. package mx.messaging.messages
  2. {
  3.    import flash.utils.ByteArray;
  4.    import flash.utils.IDataInput;
  5.    import flash.utils.IDataOutput;
  6.    import flash.utils.getQualifiedClassName;
  7.    import mx.core.mx_internal;
  8.    import mx.utils.RPCObjectUtil;
  9.    import mx.utils.RPCStringUtil;
  10.    import mx.utils.RPCUIDUtil;
  11.    
  12.    use namespace mx_internal;
  13.    
  14.    public class AbstractMessage implements IMessage
  15.    {
  16.       public static const DESTINATION_CLIENT_ID_HEADER:String = "DSDstClientId";
  17.       
  18.       public static const ENDPOINT_HEADER:String = "DSEndpoint";
  19.       
  20.       public static const FLEX_CLIENT_ID_HEADER:String = "DSId";
  21.       
  22.       public static const REMOTE_CREDENTIALS_HEADER:String = "DSRemoteCredentials";
  23.       
  24.       public static const REMOTE_CREDENTIALS_CHARSET_HEADER:String = "DSRemoteCredentialsCharset";
  25.       
  26.       public static const REQUEST_TIMEOUT_HEADER:String = "DSRequestTimeout";
  27.       
  28.       public static const STATUS_CODE_HEADER:String = "DSStatusCode";
  29.       
  30.       private static const HAS_NEXT_FLAG:uint = 128;
  31.       
  32.       private static const BODY_FLAG:uint = 1;
  33.       
  34.       private static const CLIENT_ID_FLAG:uint = 2;
  35.       
  36.       private static const DESTINATION_FLAG:uint = 4;
  37.       
  38.       private static const HEADERS_FLAG:uint = 8;
  39.       
  40.       private static const MESSAGE_ID_FLAG:uint = 16;
  41.       
  42.       private static const TIMESTAMP_FLAG:uint = 32;
  43.       
  44.       private static const TIME_TO_LIVE_FLAG:uint = 64;
  45.       
  46.       private static const CLIENT_ID_BYTES_FLAG:uint = 1;
  47.       
  48.       private static const MESSAGE_ID_BYTES_FLAG:uint = 2;
  49.       
  50.       private var _body:Object = {};
  51.       
  52.       private var _messageId:String;
  53.       
  54.       private var messageIdBytes:ByteArray;
  55.       
  56.       private var _timestamp:Number = 0;
  57.       
  58.       private var _clientId:String;
  59.       
  60.       private var clientIdBytes:ByteArray;
  61.       
  62.       private var _headers:Object;
  63.       
  64.       private var _destination:String = "";
  65.       
  66.       private var _timeToLive:Number = 0;
  67.       
  68.       public function AbstractMessage()
  69.       {
  70.          super();
  71.       }
  72.       
  73.       public function set messageId(param1:String) : void
  74.       {
  75.          _messageId = param1;
  76.          messageIdBytes = null;
  77.       }
  78.       
  79.       public function get headers() : Object
  80.       {
  81.          if(_headers == null)
  82.          {
  83.             _headers = {};
  84.          }
  85.          return _headers;
  86.       }
  87.       
  88.       public function readExternal(param1:IDataInput) : void
  89.       {
  90.          var _loc4_:uint = 0;
  91.          var _loc5_:uint = 0;
  92.          var _loc6_:uint = 0;
  93.          var _loc2_:Array = readFlags(param1);
  94.          var _loc3_:uint = 0;
  95.          while(_loc3_ < _loc2_.length)
  96.          {
  97.             _loc4_ = _loc2_[_loc3_] as uint;
  98.             _loc5_ = 0;
  99.             if(_loc3_ == 0)
  100.             {
  101.                if((_loc4_ & BODY_FLAG) != 0)
  102.                {
  103.                   body = param1.readObject();
  104.                }
  105.                else
  106.                {
  107.                   body = null;
  108.                }
  109.                if((_loc4_ & CLIENT_ID_FLAG) != 0)
  110.                {
  111.                   clientId = param1.readObject();
  112.                }
  113.                if((_loc4_ & DESTINATION_FLAG) != 0)
  114.                {
  115.                   destination = param1.readObject() as String;
  116.                }
  117.                if((_loc4_ & HEADERS_FLAG) != 0)
  118.                {
  119.                   headers = param1.readObject();
  120.                }
  121.                if((_loc4_ & MESSAGE_ID_FLAG) != 0)
  122.                {
  123.                   messageId = param1.readObject() as String;
  124.                }
  125.                if((_loc4_ & TIMESTAMP_FLAG) != 0)
  126.                {
  127.                   timestamp = param1.readObject() as Number;
  128.                }
  129.                if((_loc4_ & TIME_TO_LIVE_FLAG) != 0)
  130.                {
  131.                   timeToLive = param1.readObject() as Number;
  132.                }
  133.                _loc5_ = 7;
  134.             }
  135.             else if(_loc3_ == 1)
  136.             {
  137.                if((_loc4_ & CLIENT_ID_BYTES_FLAG) != 0)
  138.                {
  139.                   clientIdBytes = param1.readObject() as ByteArray;
  140.                   clientId = RPCUIDUtil.fromByteArray(clientIdBytes);
  141.                }
  142.                if((_loc4_ & MESSAGE_ID_BYTES_FLAG) != 0)
  143.                {
  144.                   messageIdBytes = param1.readObject() as ByteArray;
  145.                   messageId = RPCUIDUtil.fromByteArray(messageIdBytes);
  146.                }
  147.                _loc5_ = 2;
  148.             }
  149.             if(_loc4_ >> _loc5_ != 0)
  150.             {
  151.                _loc6_ = _loc5_;
  152.                while(_loc6_ < 6)
  153.                {
  154.                   if((_loc4_ >> _loc6_ & 1) != 0)
  155.                   {
  156.                      param1.readObject();
  157.                   }
  158.                   _loc6_++;
  159.                }
  160.             }
  161.             _loc3_++;
  162.          }
  163.       }
  164.       
  165.       public function get messageId() : String
  166.       {
  167.          if(_messageId == null)
  168.          {
  169.             _messageId = RPCUIDUtil.createUID();
  170.          }
  171.          return _messageId;
  172.       }
  173.       
  174.       public function set clientId(param1:String) : void
  175.       {
  176.          _clientId = param1;
  177.          clientIdBytes = null;
  178.       }
  179.       
  180.       public function get destination() : String
  181.       {
  182.          return _destination;
  183.       }
  184.       
  185.       public function get timestamp() : Number
  186.       {
  187.          return _timestamp;
  188.       }
  189.       
  190.       protected function readFlags(param1:IDataInput) : Array
  191.       {
  192.          var _loc4_:uint = 0;
  193.          var _loc2_:Boolean = true;
  194.          var _loc3_:Array = [];
  195.          while(_loc2_ && param1.bytesAvailable > 0)
  196.          {
  197.             _loc4_ = uint(param1.readUnsignedByte());
  198.             _loc3_.push(_loc4_);
  199.             if((_loc4_ & HAS_NEXT_FLAG) != 0)
  200.             {
  201.                _loc2_ = true;
  202.             }
  203.             else
  204.             {
  205.                _loc2_ = false;
  206.             }
  207.          }
  208.          return _loc3_;
  209.       }
  210.       
  211.       public function set headers(param1:Object) : void
  212.       {
  213.          _headers = param1;
  214.       }
  215.       
  216.       public function get body() : Object
  217.       {
  218.          return _body;
  219.       }
  220.       
  221.       public function set destination(param1:String) : void
  222.       {
  223.          _destination = param1;
  224.       }
  225.       
  226.       public function set timestamp(param1:Number) : void
  227.       {
  228.          _timestamp = param1;
  229.       }
  230.       
  231.       protected function addDebugAttributes(param1:Object) : void
  232.       {
  233.          param1["body"] = body;
  234.          param1["clientId"] = clientId;
  235.          param1["destination"] = destination;
  236.          param1["headers"] = headers;
  237.          param1["messageId"] = messageId;
  238.          param1["timestamp"] = timestamp;
  239.          param1["timeToLive"] = timeToLive;
  240.       }
  241.       
  242.       public function get timeToLive() : Number
  243.       {
  244.          return _timeToLive;
  245.       }
  246.       
  247.       public function set body(param1:Object) : void
  248.       {
  249.          _body = param1;
  250.       }
  251.       
  252.       public function get clientId() : String
  253.       {
  254.          return _clientId;
  255.       }
  256.       
  257.       public function writeExternal(param1:IDataOutput) : void
  258.       {
  259.          var _loc2_:uint = 0;
  260.          var _loc3_:String = messageId;
  261.          if(clientIdBytes == null)
  262.          {
  263.             clientIdBytes = RPCUIDUtil.toByteArray(_clientId);
  264.          }
  265.          if(messageIdBytes == null)
  266.          {
  267.             messageIdBytes = RPCUIDUtil.toByteArray(_messageId);
  268.          }
  269.          if(body != null)
  270.          {
  271.             _loc2_ |= BODY_FLAG;
  272.          }
  273.          if(clientId != null && clientIdBytes == null)
  274.          {
  275.             _loc2_ |= CLIENT_ID_FLAG;
  276.          }
  277.          if(destination != null)
  278.          {
  279.             _loc2_ |= DESTINATION_FLAG;
  280.          }
  281.          if(headers != null)
  282.          {
  283.             _loc2_ |= HEADERS_FLAG;
  284.          }
  285.          if(messageId != null && messageIdBytes == null)
  286.          {
  287.             _loc2_ |= MESSAGE_ID_FLAG;
  288.          }
  289.          if(timestamp != 0)
  290.          {
  291.             _loc2_ |= TIMESTAMP_FLAG;
  292.          }
  293.          if(timeToLive != 0)
  294.          {
  295.             _loc2_ |= TIME_TO_LIVE_FLAG;
  296.          }
  297.          if(clientIdBytes != null || messageIdBytes != null)
  298.          {
  299.             _loc2_ |= HAS_NEXT_FLAG;
  300.          }
  301.          param1.writeByte(_loc2_);
  302.          _loc2_ = 0;
  303.          if(clientIdBytes != null)
  304.          {
  305.             _loc2_ |= CLIENT_ID_BYTES_FLAG;
  306.          }
  307.          if(messageIdBytes != null)
  308.          {
  309.             _loc2_ |= MESSAGE_ID_BYTES_FLAG;
  310.          }
  311.          if(_loc2_ != 0)
  312.          {
  313.             param1.writeByte(_loc2_);
  314.          }
  315.          if(body != null)
  316.          {
  317.             param1.writeObject(body);
  318.          }
  319.          if(clientId != null && clientIdBytes == null)
  320.          {
  321.             param1.writeObject(clientId);
  322.          }
  323.          if(destination != null)
  324.          {
  325.             param1.writeObject(destination);
  326.          }
  327.          if(headers != null)
  328.          {
  329.             param1.writeObject(headers);
  330.          }
  331.          if(messageId != null && messageIdBytes == null)
  332.          {
  333.             param1.writeObject(messageId);
  334.          }
  335.          if(timestamp != 0)
  336.          {
  337.             param1.writeObject(timestamp);
  338.          }
  339.          if(timeToLive != 0)
  340.          {
  341.             param1.writeObject(timeToLive);
  342.          }
  343.          if(clientIdBytes != null)
  344.          {
  345.             param1.writeObject(clientIdBytes);
  346.          }
  347.          if(messageIdBytes != null)
  348.          {
  349.             param1.writeObject(messageIdBytes);
  350.          }
  351.       }
  352.       
  353.       final protected function getDebugString() : String
  354.       {
  355.          var _loc4_:String = null;
  356.          var _loc5_:uint = 0;
  357.          var _loc6_:String = null;
  358.          var _loc7_:String = null;
  359.          var _loc1_:* = "(" + getQualifiedClassName(this) + ")";
  360.          var _loc2_:Object = {};
  361.          addDebugAttributes(_loc2_);
  362.          var _loc3_:Array = [];
  363.          for(_loc4_ in _loc2_)
  364.          {
  365.             _loc3_.push(_loc4_);
  366.          }
  367.          _loc3_.sort();
  368.          _loc5_ = 0;
  369.          while(_loc5_ < _loc3_.length)
  370.          {
  371.             _loc6_ = String(_loc3_[_loc5_]);
  372.             _loc7_ = RPCObjectUtil.toString(_loc2_[_loc6_]);
  373.             _loc1_ += RPCStringUtil.substitute("\n  {0}={1}",_loc6_,_loc7_);
  374.             _loc5_++;
  375.          }
  376.          return _loc1_;
  377.       }
  378.       
  379.       public function toString() : String
  380.       {
  381.          return RPCObjectUtil.toString(this);
  382.       }
  383.       
  384.       public function set timeToLive(param1:Number) : void
  385.       {
  386.          _timeToLive = param1;
  387.       }
  388.    }
  389. }
  390.  
  391.