Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data.SqlXml / System / Xml / Xsl / XsltOld / CopyCodeAction.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="CopyCodeAction.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>                                                                
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
7
8 namespace System.Xml.Xsl.XsltOld {
9     using Res = System.Xml.Utils.Res;
10     using System;
11     using System.Diagnostics;
12     using System.Xml;
13     using System.Xml.XPath;
14     using System.Collections;
15
16     internal class CopyCodeAction : Action {
17         // Execution states:
18         private const int Outputting = 2;
19         
20         private ArrayList copyEvents;   // Copy code action events
21
22         internal CopyCodeAction() {
23             this.copyEvents = new ArrayList();
24         }
25
26         internal void AddEvent(Event copyEvent) {
27             this.copyEvents.Add(copyEvent);
28         }
29
30         internal void AddEvents(ArrayList copyEvents) {
31             Debug.Assert(copyEvents != null);
32             this.copyEvents.AddRange(copyEvents);
33         }
34
35         internal override void ReplaceNamespaceAlias(Compiler compiler) {
36             int count = this.copyEvents.Count;
37             for(int i = 0; i< count; i++) {
38                 ((Event) this.copyEvents[i]).ReplaceNamespaceAlias(compiler);
39             }
40         }
41         
42         internal override void Execute(Processor processor, ActionFrame frame) {
43             Debug.Assert(processor != null && frame != null);
44             Debug.Assert(this.copyEvents != null && this.copyEvents.Count > 0);
45
46             switch (frame.State) {
47             case Initialized:
48                 frame.Counter = 0;
49                 frame.State   = Outputting;
50                 goto case Outputting;
51
52             case Outputting:
53                 Debug.Assert(frame.State == Outputting);
54
55                 while (processor.CanContinue) {
56                     Debug.Assert(frame.Counter < this.copyEvents.Count);
57                     Event copyEvent = (Event) this.copyEvents[frame.Counter];
58
59                     if (copyEvent.Output(processor, frame) == false) {
60                         // This event wasn't processed
61                         break;
62                     }
63
64                     if (frame.IncrementCounter() >= this.copyEvents.Count) {
65                         frame.Finished();
66                         break;
67                     }
68                 }
69                 break;
70             default:
71                 Debug.Fail("Invalid CopyCodeAction execution state");
72                 break;
73             }
74         }
75
76         internal override DbgData GetDbgData(ActionFrame frame) {
77             Debug.Assert(frame.Counter < this.copyEvents.Count);
78             return ((Event)this.copyEvents[frame.Counter]).DbgData;        
79         }
80     }
81 }