1 /*----------------------------------------------------------------------------
   2 Name:      Qos.cs
   3 Project:   xmlBlaster.org
   4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
   5 Comment:   Access QoS informations
   6            Please consult the javadoc of the Java client library for API usage
   7 Author:    "Marcel Ruff" <xmlBlaster@marcelruff.info>
   8 Date:      12/2006
   9 See:       http://www.xmlblaster.org/xmlBlaster/doc/requirements/interface.html
  10 -----------------------------------------------------------------------------*/
  11 using System;
  12 using System.Xml;
  13 using System.IO;
  14 using System.Text;
  15 using System.Collections;
  16 using System.Runtime.InteropServices;
  17 
  18 namespace org.xmlBlaster.client
  19 {
  20    public class ClientProperty
  21    {
  22       public const string ENCODING_BASE64 = "base64";
  23       public const string ENCODING_FORCE_PLAIN = "forcePlain";
  24       public const string ENCODING_QUOTED_PRINTABLE = "quoted-printable";
  25       public const string ENCODING_NONE = null;
  26       public const string TYPE_STRING = "string"; // is default, same as ""

  27       public const string TYPE_BLOB = "byte[]";
  28       public const string TYPE_BOOLEAN = "boolean";
  29       public const string TYPE_BYTE = "byte";
  30       public const string TYPE_DOUBLE = "double";
  31       public const string TYPE_FLOAT = "float";
  32       public const string TYPE_INT = "int";
  33       public const string TYPE_SHORT = "short";
  34       public const string TYPE_LONG = "long";
  35       /** used to tell that the entry is really null (not just empty) */
  36       public const string TYPE_NULL = "null";
  37 
  38       private string name;
  39       private string type;
  40       /** The value encoded as specified with encoding */
  41       private string value;
  42       private string encoding;
  43       /** Mark the charset for a base64 encoded string */
  44       private string charset = "";
  45       /** Needed for Base64 encoding */
  46       //public static readonly bool isChunked = false;

  47       protected string tagName;
  48       //private long size = -1L;

  49       //private bool forceCdata = false;

  50 
  51       public ClientProperty(string tagName, string name, string type, string encoding, string value)
  52       {
  53          this.name = name;
  54          this.tagName = (tagName == null) ? "clientProperty" : tagName;
  55          this.type = type;
  56          this.encoding = encoding;
  57          SetValue(value);
  58       }
  59 
  60       private void SetValue(string value)
  61       {
  62          this.value = value;
  63       }
  64 
  65       public void SetCharset(string charset)
  66       {
  67          this.charset = charset;
  68       }
  69 
  70       public string GetName()
  71       {
  72          return this.name;
  73       }
  74 
  75       public string GetValueType()
  76       {
  77          if (this.type == null || this.type.Length < 1)
  78             return TYPE_STRING;
  79          return this.type;
  80       }
  81 
  82       public bool IsBase64()
  83       {
  84 #        if CF1

  85          return ENCODING_BASE64.Equals(this.encoding);
  86 #        else

  87          return ENCODING_BASE64.Equals(this.encoding, StringComparison.OrdinalIgnoreCase);
  88 #        endif

  89       }
  90 
  91       /**
  92        * The raw still encoded value
  93        */
  94       public string GetValueRaw()
  95       {
  96          return this.value;
  97       }
  98 
  99       /// <summary>

 100       /// The string representation of the value.

 101       /// If the string is base64 encoded with a given charset, it is decoded

 102       /// and transformed to the default charset, typically "UTF-16" on Windows

 103       /// </summary>

 104       /// <returns>The value which is decoded (readable) in case it was base64 encoded, can be null</returns>

 105       public string GetStringValue()
 106       {
 107          if (this.value == null) return null;
 108          if (IsBase64())
 109          {
 110             byte[] content = GetBlobValue();
 111             try
 112             {
 113                Encoding enc = Encoding.GetEncoding(GetCharset());//, Encoding.UTF8, Encoding.UTF8); //EncoderFallback, DecoderFallback);

 114                if (enc != null)
 115                   return enc.GetString(content, 0, content.Length);
 116                return System.Text.Encoding.UTF8.GetString(content, 0, content.Length);
 117             }
 118             catch (Exception ex)
 119             {
 120                Console.WriteLine("Decode failed: " + ex.ToString());
 121             }
 122             return "";
 123          }
 124          return this.value;
 125       }
 126 
 127       /// <summary>

 128       /// 

 129       /// </summary>

 130       /// <returns>If was a string, it is encoded with UNICODE</returns>

 131       public byte[] GetBlobValue()
 132       {
 133          if (this.value == null) return null;
 134          if (IsBase64())
 135          {
 136             try
 137             {
 138                return System.Convert.FromBase64String(this.value);
 139             }
 140             catch (System.FormatException)
 141             {
 142                System.Console.WriteLine("Base 64 string length is not " +
 143                    "4 or is not an even multiple of 4.");
 144                return new byte[0];
 145             }
 146          }
 147          return System.Text.Encoding.Unicode.GetBytes(this.value);
 148       }
 149 
 150       public int GetIntValue()
 151       {
 152          return int.Parse(GetStringValue());
 153       }
 154 
 155       public long GetLongValue()
 156       {
 157          return long.Parse(GetStringValue());
 158       }
 159 
 160       public float GetFloatValue()
 161       {
 162          return float.Parse(GetStringValue());
 163       }
 164 
 165       public double GetDoubleValue()
 166       {
 167          return double.Parse(GetStringValue());
 168       }
 169 
 170       public bool GetBoolValue()
 171       {
 172          return bool.Parse(GetStringValue());
 173       }
 174 
 175       /// For example "int" or "byte[]"

 176       public string GetEncoding()
 177       {
 178          return this.encoding;
 179       }
 180 
 181       /// Returns the charset, for example "cp1252" or "UTF-8", helpful if base64 encoded

 182       public string GetCharset()
 183       {
 184          return this.charset;
 185       }
 186    }
 187 
 188 
 189    public class SessionName
 190    {
 191       public const string ROOT_MARKER_TAG = "/node";
 192       public const string SUBJECT_MARKER_TAG = "client";
 193       public const string SESSION_MARKER_TAG = "session";
 194       private string absoluteName;
 195       private string relativeName;
 196       private string nodeId;
 197       private string subjectId; // == loginName

 198       private long pubSessionId;
 199       public SessionName(string name)
 200       {
 201 
 202          if (name == null)
 203          {
 204             throw new Exception("Your given name is null");
 205          }
 206 
 207          name = name.Trim();
 208 
 209          char[] splitter = { '/' };
 210 
 211          string relative = name;
 212 
 213          // parse absolute part

 214          if (name.StartsWith("/"))
 215          {
 216             string strip = name.Substring(1);
 217             string[] arr = strip.Split(splitter); // not in CF2: StringSplitOptions

 218             if (arr.Length == 0)
 219             {
 220                throw new Exception("'" + name + "': The root tag must be '/node'.");
 221             }
 222             if (arr.Length > 0)
 223             {
 224                if (!"node".Equals(arr[0]))
 225                   throw new Exception("'" + name + "': The root tag must be '/node'.");
 226             }
 227             if (arr.Length > 1)
 228             {
 229                this.nodeId = arr[1]; // the parsed nodeId

 230             }
 231             if (arr.Length > 2)
 232             {
 233                if (!SUBJECT_MARKER_TAG.Equals(arr[2]))
 234                   throw new Exception("'" + name + "': 'client' tag is missing.");
 235             }
 236 
 237             relative = "";
 238             for (int i = 3; i < arr.Length; i++)
 239             {
 240                relative += arr[i];
 241                if (i < (arr.Length - 1))
 242                   relative += "/";
 243             }
 244          }
 245 
 246          // parse relative part

 247          if (relative.Length < 1)
 248          {
 249             throw new Exception("'" + name + "': No relative information found.");
 250          }
 251 
 252          int ii = 0;
 253          string[] arr2 = relative.Split(splitter);
 254          if (arr2.Length > ii)
 255          {
 256             string tmp = arr2[ii++];
 257             if (SUBJECT_MARKER_TAG.Equals(tmp))
 258             { // "client"

 259                if (arr2.Length > ii)
 260                {
 261                   this.subjectId = arr2[ii++];
 262                }
 263                else
 264                {
 265                   throw new Exception("'" + name + "': No relative information found.");
 266                }
 267             }
 268             else
 269             {
 270                this.subjectId = tmp;
 271             }
 272          }
 273          else
 274          {
 275             throw new Exception("'" + name + "': No relative information found.");
 276          }
 277          if (arr2.Length > ii)
 278          {
 279             string tmp = arr2[ii++];
 280             if (SESSION_MARKER_TAG.Equals(tmp))
 281             {
 282                if (arr2.Length > ii)
 283                {
 284                   tmp = arr2[ii++];
 285                }
 286             }
 287             this.pubSessionId = long.Parse(tmp);
 288          }
 289       }
 290 
 291       /**
 292        * If the nodeId is not known, the relative name is returned
 293        * @return e.g. "/node/heron/client/joe/2", never null
 294        */
 295       public string GetAbsoluteName()
 296       {
 297          if (this.absoluteName == null)
 298          {
 299             StringBuilder buf = new StringBuilder(256);
 300             if (this.nodeId != null)
 301             {
 302                buf.Append("/node/").Append(this.nodeId).Append("/");
 303             }
 304             buf.Append(GetRelativeName());
 305             this.absoluteName = buf.ToString();
 306          }
 307          return this.absoluteName;
 308       }
 309 
 310       /**
 311        * @return #GetAbsoluteName()
 312        */
 313       public override string ToString()
 314       {
 315          return GetAbsoluteName();
 316       }
 317 
 318       /**
 319        * @return e.g. "client/joe/2" or "client/joe", never null
 320        */
 321       public string GetRelativeName()
 322       {
 323          if (this.relativeName == null)
 324          {
 325             StringBuilder buf = new StringBuilder(126);
 326             // For example "client/joe/session/-1"

 327             buf.Append(SUBJECT_MARKER_TAG).Append("/").Append(subjectId);
 328             if (IsSession())
 329             {
 330                buf.Append("/");
 331                buf.Append(SESSION_MARKER_TAG).Append("/");
 332                buf.Append("" + this.pubSessionId);
 333             }
 334             this.relativeName = buf.ToString();
 335          }
 336          return this.relativeName;
 337       }
 338 
 339       /**
 340        * @return e.g. "heron", or null
 341        */
 342       public string GetNodeIdStr()
 343       {
 344          return this.nodeId;
 345       }
 346 
 347       /**
 348        * @return e.g. "joe", never null
 349        */
 350       public string GetLoginName()
 351       {
 352          return this.subjectId;
 353       }
 354 
 355       /**
 356        * @return The public session identifier e.g. "2" or 0 if in subject context
 357        */
 358       public long GetPublicSessionId()
 359       {
 360          return this.pubSessionId;
 361       }
 362 
 363       /**
 364        * Check if we hold a session or a subject
 365        */
 366       public bool IsSession()
 367       {
 368          return this.pubSessionId != 0L;
 369       }
 370 
 371       /** @return true it publicSessionId is given by xmlBlaster server (if < 0) */
 372       public bool IsPubSessionIdInternal()
 373       {
 374          return this.pubSessionId < 0L;
 375       }
 376 
 377       /** @return true it publicSessionId is given by user/client (if > 0) */
 378       public bool IsPubSessionIdUser()
 379       {
 380          return this.pubSessionId > 0L;
 381       }
 382 
 383       /**
 384        * @return true if relative name equals
 385        */
 386       public bool equalsRelative(SessionName sessionName)
 387       {
 388          return GetRelativeName().Equals(sessionName.GetRelativeName());
 389       }
 390 
 391       public bool equalsAbsolute(SessionName sessionName)
 392       {
 393          return GetAbsoluteName().Equals(sessionName.GetAbsoluteName());
 394       }
 395    }
 396 
 397    public class KeyQosParser
 398    {
 399       protected string xml;
 400       protected XmlDocument xmlDocument;
 401 
 402       public KeyQosParser(string xml)
 403       {
 404          this.xml = xml;
 405       }
 406 
 407       public XmlNodeList GetXmlNodeList(string key)
 408       {
 409          if (this.xmlDocument == null)
 410          {
 411             this.xmlDocument = new XmlDocument();
 412             string tmp = (this.xml == null || this.xml.Length < 1) ? "<error/>" : this.xml;
 413             this.xmlDocument.LoadXml(tmp);
 414          }
 415          XmlNodeList xmlNodeList = this.xmlDocument.SelectNodes(key);
 416          return xmlNodeList;
 417       }
 418 
 419       /// <summary>

 420       /// Extract e.g. "hello" from "<a>hello</a>"

 421       /// </summary>

 422       /// <param name="xml"></param>

 423       /// <param name="tag"></param>

 424       /// <returns></returns>

 425       public static string extract(string xml, string tag) {
 426          if (xml == null || tag == null) return null;
 427          string startToken = "<" + tag + ">";
 428          string endToken = "</" + tag + ">";
 429          int start = xml.IndexOf(startToken);
 430          int end = xml.IndexOf(endToken);
 431          if (start != -1 && end != -1) {
 432             start += startToken.Length;
 433             return xml.Substring(start, end-start);
 434          }
 435          return null;
 436       }
 437 
 438 
 439       /// <summary>

 440       /// Supports query on attributes or tag values

 441       /// </summary>

 442       /// <param name="key">For example "/qos/priority/text()"</param>

 443       /// <param name="defaultValue"></param>

 444       /// <returns></returns>

 445       public string GetXPath(string key, string defaultValue)
 446       {
 447          XmlNodeList xmlNodeList = GetXmlNodeList(key);
 448          for (int i = 0; i < xmlNodeList.Count; i++)
 449          {
 450             XmlNode node = xmlNodeList[i];
 451             if (node.NodeType == XmlNodeType.Attribute)
 452                return node.Value;
 453             else if (node.NodeType == XmlNodeType.Text)
 454                return node.Value;
 455             else if (node.NodeType == XmlNodeType.Element && node.HasChildNodes) {
 456                if (node.FirstChild.NodeType == XmlNodeType.CDATA) {
 457                   // Returns string inside a CDATA section

 458                   return node.FirstChild.Value;
 459                }
 460                else if (node.FirstChild.NodeType == XmlNodeType.Element) {
 461                   // Returns string with all sub-tags

 462                   return node.OuterXml;
 463                }
 464             }
 465          }
 466          return defaultValue;
 467       }
 468 
 469       /// <summary>

 470       /// Query bools without text() to find empty tags like "<persistent/>"

 471       /// </summary>

 472       /// <param name="key">"/qos/persistent" or "qos/persistent/text()"</param>

 473       /// <param name="defaultValue"></param>

 474       /// <returns></returns>

 475       public bool GetXPath(string key, bool defaultValue)
 476       {
 477          if (key == null) return defaultValue;
 478          if (key.EndsWith("/text()"))
 479             key = key.Substring(0, key.Length - "/text()".Length);
 480          XmlNodeList xmlNodeList = GetXmlNodeList(key);
 481          string value = "" + defaultValue;
 482          for (int i = 0; i < xmlNodeList.Count; i++)
 483          {
 484             XmlNode node = xmlNodeList[i];
 485             if (node.NodeType == XmlNodeType.Attribute) {
 486                value = node.Value;
 487                break;
 488             }
 489             else if (node.NodeType == XmlNodeType.Text)
 490             {
 491                value = node.Value;
 492                break;
 493             }
 494             else if (node.NodeType == XmlNodeType.Element)
 495             {
 496                if (node.HasChildNodes &&
 497                    node.FirstChild.NodeType == XmlNodeType.Text) {
 498                   value = node.FirstChild.Value;
 499                   break;
 500                }
 501                else if (node.Value == null)
 502                   return true;
 503             }
 504          }
 505          try {
 506             return bool.Parse(value);
 507          }
 508          catch (Exception) {
 509             return defaultValue;
 510          }
 511       }
 512       /*
 513       public bool GetXPath(string key, bool defaultValue)
 514       {
 515          string ret = GetXPath(key, null);
 516          if (ret == null) return defaultValue;
 517          try
 518          {
 519             return bool.Parse(ret);
 520          }
 521          catch (Exception)
 522          {
 523             return defaultValue;
 524          }
 525       }
 526       */
 527       public long GetXPath(string key, long defaultValue)
 528       {
 529          string ret = GetXPath(key, null);
 530          if (ret == null) return defaultValue;
 531          try
 532          {
 533             return long.Parse(ret);
 534          }
 535          catch (Exception)
 536          {
 537             return defaultValue;
 538          }
 539       }
 540 
 541       public int GetXPath(string key, int defaultValue)
 542       {
 543          string ret = GetXPath(key, null);
 544          if (ret == null) return defaultValue;
 545          try
 546          {
 547             return int.Parse(ret);
 548          }
 549          catch (Exception)
 550          {
 551             return defaultValue;
 552          }
 553       }
 554    }
 555 
 556    public class Qos : KeyQosParser
 557    {
 558       public const string STATE_OK = "OK";
 559       public const string STATE_WARN = "WARNING";
 560       public const string STATE_TIMEOUT = "TIMEOUT";
 561       public const string STATE_EXPIRED = "EXPIRED";
 562       public const string STATE_ERASED = "ERASED";
 563       public const string STATE_FORWARD_ERROR = "FORWARD_ERROR";
 564       public const string INFO_QUEUED = "QUEUED";
 565 
 566       private Hashtable clientProperties;
 567 
 568       public Qos(string qos)
 569          : base(qos)
 570       {
 571       }
 572 
 573       public long GetRcvTimeNanos()
 574       {
 575          string ret = GetXPath("/qos/rcvTimestamp/@nanos", "");
 576          if (ret == null) return -1L;
 577          try
 578          {
 579             return long.Parse(ret);
 580          }
 581          catch (Exception)
 582          {
 583             return -1L;
 584          }
 585       }
 586 
 587       public string GetRcvTime()
 588       {
 589          return GetXPath("/qos/rcvTimestamp/text()", "").Trim();
 590       }
 591 
 592       public ClientProperty GetClientProperty(string key)
 593       {
 594          return (ClientProperty)GetClientProperties()[key];
 595       }
 596 
 597       public int GetClientProperty(string name, int defaultValue)
 598       {
 599          if (name == null) return defaultValue;
 600          ClientProperty clientProperty = GetClientProperty(name);
 601          if (clientProperty == null)
 602             return defaultValue;
 603          try
 604          {
 605             return clientProperty.GetIntValue();
 606          }
 607          catch (FormatException)
 608          {
 609             return defaultValue;
 610          }
 611       }
 612 
 613       public long GetClientProperty(string name, long defaultValue)
 614       {
 615          if (name == null) return defaultValue;
 616          ClientProperty clientProperty = GetClientProperty(name);
 617          if (clientProperty == null)
 618             return defaultValue;
 619          try
 620          {
 621             return clientProperty.GetLongValue();
 622          }
 623          catch (FormatException)
 624          {
 625             return defaultValue;
 626          }
 627       }
 628 
 629       public float GetClientProperty(string name, float defaultValue)
 630       {
 631          if (name == null) return defaultValue;
 632          ClientProperty clientProperty = GetClientProperty(name);
 633          if (clientProperty == null)
 634             return defaultValue;
 635          try
 636          {
 637             return clientProperty.GetFloatValue();
 638          }
 639          catch (FormatException)
 640          {
 641             return defaultValue;
 642          }
 643       }
 644 
 645       public double GetClientProperty(string name, double defaultValue)
 646       {
 647          if (name == null) return defaultValue;
 648          ClientProperty clientProperty = GetClientProperty(name);
 649          if (clientProperty == null)
 650             return defaultValue;
 651          try
 652          {
 653             return clientProperty.GetDoubleValue();
 654          }
 655          catch (FormatException)
 656          {
 657             return defaultValue;
 658          }
 659       }
 660 
 661       public byte[] GetClientProperty(string name, byte[] defaultValue)
 662       {
 663          if (name == null) return defaultValue;
 664          ClientProperty clientProperty = GetClientProperty(name);
 665          if (clientProperty == null)
 666             return defaultValue;
 667          try
 668          {
 669             return clientProperty.GetBlobValue();
 670          }
 671          catch (FormatException)
 672          {
 673             return defaultValue;
 674          }
 675       }
 676 
 677       public bool GetClientProperty(string name, bool defaultValue)
 678       {
 679          if (name == null) return defaultValue;
 680          ClientProperty clientProperty = GetClientProperty(name);
 681          if (clientProperty == null)
 682             return defaultValue;
 683          try
 684          {
 685             return clientProperty.GetBoolValue();
 686          }
 687          catch (FormatException)
 688          {
 689             return defaultValue;
 690          }
 691       }
 692 
 693       public string GetClientProperty(string name, string defaultValue)
 694       {
 695          ClientProperty clientProperty = GetClientProperty(name);
 696          if (clientProperty == null)
 697             return defaultValue;
 698          return clientProperty.GetStringValue();
 699       }
 700 
 701       public Hashtable GetClientProperties()
 702       {
 703          if (this.clientProperties != null)
 704             return this.clientProperties;
 705          this.clientProperties = new Hashtable();
 706          String key = "/qos/clientProperty";
 707          XmlNodeList xmlNodeList = GetXmlNodeList(key);
 708          for (int i = 0; i < xmlNodeList.Count; i++)
 709          {
 710             XmlNode node = xmlNodeList[i];
 711             if (node.NodeType == XmlNodeType.Element)
 712             {
 713                // <clientProperty name='myDescription' encoding="base64" charset="windows-1252">bla</clientProperty>

 714                XmlNode attr = node.Attributes.GetNamedItem("name");
 715                if (attr == null)
 716                {
 717                   throw new ApplicationException("qos clientProperty without name attribute");
 718                }
 719                string name = attr.Value;
 720                attr = node.Attributes.GetNamedItem("type");
 721                string type = (attr != null) ? attr.Value : "";
 722                attr = node.Attributes.GetNamedItem("encoding");
 723                string encoding = (attr != null) ? attr.Value : "";
 724                attr = node.Attributes.GetNamedItem("charset");
 725                string charset = (attr != null) ? attr.Value : "";
 726                string value = (node.FirstChild != null) ? node.FirstChild.Value : "";
 727                ClientProperty clientProperty = new ClientProperty("clientProperty", name, type, encoding, value);
 728                clientProperty.SetCharset(charset);
 729                this.clientProperties.Add(name, clientProperty);
 730             }
 731             else
 732             {
 733                Console.WriteLine("Ignoring '" + key + "' with nodeType=" + node.NodeType);
 734             }
 735          }
 736          return this.clientProperties;
 737       }
 738    }
 739 
 740 
 741    public class MsgQos : Qos
 742    {
 743       public MsgQos(string qos) : base(qos) { }
 744 
 745       public string GetState()
 746       {
 747          return GetXPath("/qos/state/@id", STATE_OK);
 748       }
 749 
 750       public bool IsOk()
 751       {
 752          return STATE_OK.Equals(GetState());
 753       }
 754 
 755       public bool IsErased()
 756       {
 757          return STATE_ERASED.Equals(GetState());
 758       }
 759 
 760       public bool IsPtp()
 761       {
 762          return GetXPath("", false);
 763       }
 764 
 765       public bool IsPersistent()
 766       {
 767          return GetXPath("/qos/persistent/text()", false);
 768       }
 769 
 770       //public bool isTimeout()

 771       //{

 772       //   return GetXPath("", "");

 773       //}

 774 
 775       public string GetStateInfo()
 776       {
 777          return GetXPath("/qos/state/@info", "");
 778       }
 779 
 780       public int GetPriority()
 781       {
 782          return GetXPath("/qos/priority/text()", 5);
 783       }
 784 
 785       public long GetQueueIndex()
 786       {
 787          return GetXPath("/qos/queue/@index", 0L);
 788       }
 789 
 790       public long GetQueueSize()
 791       {
 792          return GetXPath("/qos/queue/@size", 0L);
 793       }
 794 
 795       //public Timestamp GetRcvTimestamp()

 796       //{

 797       //   return GetXPath("", "");

 798       //}

 799 
 800       public int GetRedeliver()
 801       {
 802          return GetXPath("/qos/redeliver/text()", 0);
 803       }
 804 
 805       //long GetRemainingLifeStatic()

 806 
 807       public SessionName GetSender()
 808       {
 809          string text = GetXPath("/qos/sender/text()", "");
 810          if (text == null || text.Length < 1) return null;
 811          return new SessionName(text);
 812       }
 813 
 814       public string GetSubscriptionId()
 815       {
 816          return GetXPath("/qos/subscribe/@id", "");
 817       }
 818 
 819       public long GetLifeTime()
 820       {
 821          return GetXPath("/qos/expiration/@lifeTime", -1L);
 822       }
 823 
 824       public string ToXml()
 825       {
 826          return this.xml;
 827       }
 828    }
 829 
 830    public class GetQos : MsgQos
 831    {
 832       public GetQos(string qos)
 833          : base(qos)
 834       {
 835       }
 836    }
 837 
 838    public class UpdateQos : MsgQos
 839    {
 840       public UpdateQos(string qos)
 841          : base(qos)
 842       {
 843       }
 844    }
 845 
 846    /*internal*/public class StatusQos : Qos
 847    {
 848       public StatusQos(string qos) : base(qos) { }
 849 
 850       public string GetState()
 851       {
 852          return GetXPath("/qos/state/@id", STATE_OK);
 853       }
 854 
 855       public bool IsOk()
 856       {
 857          return STATE_OK.Equals(GetState());
 858       }
 859 
 860       public string GetStateInfo()
 861       {
 862          return GetXPath("/qos/state/@info", "");
 863       }
 864 
 865       public string GetSubscriptionId()
 866       {
 867          return GetXPath("/qos/subscribe/@id", "");
 868       }
 869 
 870       public string GetKeyOid()
 871       {
 872          return GetXPath("/qos/key/@oid", "");
 873       }
 874 
 875       public string toXml()
 876       {
 877          return this.xml;
 878       }
 879    }
 880 
 881    public class SubscribeReturnQos
 882    {
 883       private readonly StatusQos statusQosData;
 884       //private readonly bool isFakedReturn;

 885 
 886       public SubscribeReturnQos(string xmlQos)
 887          : this(xmlQos, false)
 888       {
 889       }
 890 
 891       public SubscribeReturnQos(string xmlQos, bool isFakedReturn)
 892       {
 893          //this.isFakedReturn = isFakedReturn;

 894          this.statusQosData = new StatusQos(xmlQos);
 895          //this.statusQosData.SetMethod(MethodName.SUBSCRIBE);

 896       }
 897 
 898       //public boolean isFakedReturn() {

 899       //   return this.isFakedReturn;

 900       //}

 901 
 902       public string GetState()
 903       {
 904          return this.statusQosData.GetState();
 905       }
 906 
 907       public string GetStateInfo()
 908       {
 909          return this.statusQosData.GetStateInfo();
 910       }
 911 
 912       public string GetSubscriptionId()
 913       {
 914          return this.statusQosData.GetSubscriptionId();
 915       }
 916 
 917       public string toXml()
 918       {
 919          return this.statusQosData.toXml();
 920       }
 921    }
 922 
 923    public class UnSubscribeReturnQos : SubscribeReturnQos
 924    {
 925       public UnSubscribeReturnQos(string xmlQos)
 926          : base(xmlQos)
 927       {
 928       }
 929    }
 930 
 931    public class EraseReturnQos
 932    {
 933       private readonly StatusQos statusQosData;
 934 
 935       public EraseReturnQos(string xmlQos)
 936       {
 937          this.statusQosData = new StatusQos(xmlQos);
 938       }
 939 
 940       public string GetState()
 941       {
 942          return this.statusQosData.GetState();
 943       }
 944 
 945       public string GetStateInfo()
 946       {
 947          return this.statusQosData.GetStateInfo();
 948       }
 949 
 950       public string GetKeyOid()
 951       {
 952          return this.statusQosData.GetKeyOid();
 953       }
 954 
 955       public string toXml()
 956       {
 957          return this.statusQosData.toXml();
 958       }
 959    }
 960 
 961    public class PublishReturnQos
 962    {
 963       private readonly StatusQos statusQosData;
 964 
 965       public PublishReturnQos(string xmlQos)
 966       {
 967          this.statusQosData = new StatusQos(xmlQos);
 968       }
 969 
 970       public string GetState()
 971       {
 972          return this.statusQosData.GetState();
 973       }
 974 
 975       public string GetStateInfo()
 976       {
 977          return this.statusQosData.GetStateInfo();
 978       }
 979 
 980       public string GetKeyOid()
 981       {
 982          return this.statusQosData.GetKeyOid();
 983       }
 984 
 985       /// "2002-02-10 10:52:40.879456789"

 986       public string GetRcvTime()
 987       {
 988          return this.statusQosData.GetRcvTime();
 989       }
 990 
 991       public long GetRcvTimeNanos()
 992       {
 993          return this.statusQosData.GetRcvTimeNanos();
 994       }
 995 
 996       public string toXml()
 997       {
 998          return this.statusQosData.toXml();
 999       }
1000    }
1001 
1002    public class ConnectReturnQos : Qos
1003    {
1004       public ConnectReturnQos(string xmlQos)
1005          : base(xmlQos)
1006       {
1007       }
1008 
1009       public string GetSecurityServiceUser()
1010       {
1011          string ret = GetXPath("/qos/securityService", "").Trim();
1012          return extract(ret, "user");
1013       }
1014 
1015       public string GetSecurityServicePasswd()
1016       {
1017          //Fails if a CDATA section

1018          //return GetXPath("/qos/securityService/passwd/text()", "");

1019          string ret = GetXPath("/qos/securityService", "").Trim();
1020          return extract(ret, "passwd");
1021       }
1022 
1023       public SessionName GetSessionName()
1024       {
1025          string text = GetXPath("/qos/session/@name", "");
1026          if (text == null || text.Length < 1) return null;
1027          return new SessionName(text);
1028       }
1029 
1030       public long GetSessionTimeout()
1031       {
1032          return GetXPath("/qos/session/@timeout", 3600000L);
1033       }
1034 
1035       public int GetSessionMax()
1036       {
1037          return GetXPath("/qos/session/@maxSessions", 10);
1038       }
1039 
1040       public bool GetSessionClear()
1041       {
1042          return GetXPath("/qos/session/@clearSessions", false);
1043       }
1044 
1045       public bool GetSessionReconnectSameOnly()
1046       {
1047          return GetXPath("/qos/session/@reconnectSameClientOnly", false);
1048       }
1049 
1050       public string GetSecretSessionId()
1051       {
1052          return GetXPath("/qos/session/@sessionId", "");
1053       }
1054 
1055       public bool IsPtp()
1056       {
1057          return GetXPath("/qos/ptp/text()", false);
1058       }
1059 
1060       public bool IsReconnected()
1061       {
1062          return GetXPath("/qos/reconnected/text()", false);
1063       }
1064 
1065       public bool IsPersistent()
1066       {
1067          return GetXPath("/qos/persistent", false);
1068       }
1069       /*
1070                               public string Get()
1071                               {
1072                                  return GetXPath("/qos/", "");
1073                               }
1074                               */
1075       public string toXml()
1076       {
1077          return base.xml;
1078       }
1079    }
1080 }


syntax highlighted by Code2HTML, v. 0.9.1