1 //------------------------------------------------------------------------------
2 // <copyright file="newinstructionaction.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 
15     internal class NewInstructionAction : ContainerAction {
16         string name;
17         string parent;
18         bool fallback;
19 
Compile(Compiler compiler)20         internal override void Compile(Compiler compiler) {
21             XPathNavigator nav = compiler.Input.Navigator.Clone();
22             name = nav.Name;
23             nav.MoveToParent();
24             parent = nav.Name;
25             if (compiler.Recurse()) {
26                 CompileSelectiveTemplate(compiler);
27                 compiler.ToParent();
28             }
29         }
30 
CompileSelectiveTemplate(Compiler compiler)31         internal void CompileSelectiveTemplate(Compiler compiler){
32             NavigatorInput input = compiler.Input;
33             do{
34                 if (Ref.Equal(input.NamespaceURI, input.Atoms.UriXsl) &&
35                     Ref.Equal(input.LocalName, input.Atoms.Fallback)){
36                     fallback = true;
37                     if (compiler.Recurse()){
38                         CompileTemplate(compiler);
39                         compiler.ToParent();
40                     }
41                 }
42             }
43             while (compiler.Advance());
44         }
45 
Execute(Processor processor, ActionFrame frame)46        internal override void Execute(Processor processor, ActionFrame frame) {
47             Debug.Assert(processor != null && frame != null);
48 
49             switch (frame.State) {
50             case Initialized:
51                 if (!fallback) {
52                     throw XsltException.Create(Res.Xslt_UnknownExtensionElement, this.name);
53                 }
54                 if (this.containedActions != null && this.containedActions.Count > 0) {
55                     processor.PushActionFrame(frame);
56                     frame.State = ProcessingChildren;
57                     break;
58                 }
59                 else goto case ProcessingChildren;
60             case ProcessingChildren:
61                 frame.Finished();
62                 break;
63 
64             default:
65                 Debug.Fail("Invalid Container action execution state");
66                 break;
67             }
68         }
69     }
70 }
71