The Labs \ Source Viewer \ SSCLI \ System.Xml.Xsl.Runtime \ XmlILIndex

  1. //------------------------------------------------------------------------------
  2. // <copyright file="XmlILIndex.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. using System;
  16. using System.Collections;
  17. using System.Xml.XPath;
  18. using System.ComponentModel;
  19. namespace System.Xml.Xsl.Runtime
  20. {
  21.    
  22.     /// <summary>
  23.     /// This class manages nodes from one input document, indexed by key value(s).
  24.     /// </summary>
  25.     [EditorBrowsable(EditorBrowsableState.Never)]
  26.     public sealed class XmlILIndex
  27.     {
  28.         private Hashtable table;
  29.        
  30.         /// <summary>
  31.         /// This constructor is internal so that external users cannot construct it (and therefore we do not have to test it separately).
  32.         /// </summary>
  33.         internal XmlILIndex()
  34.         {
  35.             this.table = new Hashtable();
  36.         }
  37.        
  38.         /// <summary>
  39.         /// Add a node indexed by the specified key value.
  40.         /// </summary>
  41.         public void Add(string key, XPathNavigator navigator)
  42.         {
  43.             XmlQueryNodeSequence seq = (XmlQueryNodeSequence)this.table[key];
  44.            
  45.             if (seq == null) {
  46.                 // Create a new sequence and add it to the index
  47.                 seq = new XmlQueryNodeSequence();
  48.                 seq.AddClone(navigator);
  49.                 this.table.Add(key, seq);
  50.             }
  51.             else {
  52.                 // Add node to existing sequence; don't add if it already there
  53.                 for (int i = 0; i < seq.Count; i++) {
  54.                     if (navigator.IsSamePosition(seq[i]))
  55.                         return;
  56.                 }
  57.                
  58.                 seq.AddClone(navigator);
  59.             }
  60.         }
  61.        
  62.         /// <summary>
  63.         /// Lookup a sequence of nodes that are indexed by the specified key value.
  64.         /// Return a non-null empty sequence, if there are no nodes associated with the key.
  65.         /// </summary>
  66.         public XmlQueryNodeSequence Lookup(string key)
  67.         {
  68.             XmlQueryNodeSequence seq = (XmlQueryNodeSequence)this.table[key];
  69.            
  70.             if (seq == null)
  71.                 seq = new XmlQueryNodeSequence();
  72.            
  73.             return seq;
  74.         }
  75.     }
  76. }

Developer Fusion