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