The Labs \ Source Viewer \ SSCLI \ System.Xml.Xsl.XsltOld \ CopyCodeAction

  1. //------------------------------------------------------------------------------
  2. // <copyright file="CopyCodeAction.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. namespace System.Xml.Xsl.XsltOld
  16. {
  17.     using Res = System.Xml.Utils.Res;
  18.     using System;
  19.     using System.Diagnostics;
  20.     using System.Xml;
  21.     using System.Xml.XPath;
  22.     using System.Collections;
  23.    
  24.     internal class CopyCodeAction : Action
  25.     {
  26.         // Execution states:
  27.         private const int Outputting = 2;
  28.        
  29.         private ArrayList copyEvents;
  30.         // Copy code action events
  31.         internal CopyCodeAction()
  32.         {
  33.             this.copyEvents = new ArrayList();
  34.         }
  35.        
  36.         internal void AddEvent(Event copyEvent)
  37.         {
  38.             this.copyEvents.Add(copyEvent);
  39.         }
  40.        
  41.         internal void AddEvents(ArrayList copyEvents)
  42.         {
  43.             Debug.Assert(copyEvents != null);
  44.             this.copyEvents.AddRange(copyEvents);
  45.         }
  46.        
  47.         internal override void ReplaceNamespaceAlias(Compiler compiler)
  48.         {
  49.             int count = this.copyEvents.Count;
  50.             for (int i = 0; i < count; i++) {
  51.                 ((Event)this.copyEvents[i]).ReplaceNamespaceAlias(compiler);
  52.             }
  53.         }
  54.        
  55.         internal override void Execute(Processor processor, ActionFrame frame)
  56.         {
  57.             Debug.Assert(processor != null && frame != null);
  58.             Debug.Assert(this.copyEvents != null && this.copyEvents.Count > 0);
  59.            
  60.             switch (frame.State) {
  61.                 case Initialized:
  62.                     frame.Counter = 0;
  63.                     frame.State = Outputting;
  64.                     goto case Outputting;
  65.                     break;
  66.                 case Outputting:
  67.                    
  68.                     Debug.Assert(frame.State == Outputting);
  69.                    
  70.                     while (processor.CanContinue) {
  71.                         Debug.Assert(frame.Counter < this.copyEvents.Count);
  72.                         Event copyEvent = (Event)this.copyEvents[frame.Counter];
  73.                        
  74.                         if (copyEvent.Output(processor, frame) == false) {
  75.                             // This event wasn't processed
  76.                             break;
  77.                         }
  78.                        
  79.                         if (frame.IncrementCounter() >= this.copyEvents.Count) {
  80.                             frame.Finished();
  81.                             break;
  82.                         }
  83.                     }
  84.                     break;
  85.                 default:
  86.                     Debug.Fail("Invalid CopyCodeAction execution state");
  87.                     break;
  88.             }
  89.         }
  90.        
  91.         internal override DbgData GetDbgData(ActionFrame frame)
  92.         {
  93.             Debug.Assert(frame.Counter < this.copyEvents.Count);
  94.             return ((Event)this.copyEvents[frame.Counter]).DbgData;
  95.         }
  96.     }
  97. }

Developer Fusion