Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data.SqlXml / System / Xml / Xsl / XsltOld / ChooseAction.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="ChooseAction.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 ChooseAction : ContainerAction {
16         internal override void Compile(Compiler compiler) {
17             CompileAttributes(compiler);
18
19             if (compiler.Recurse()) {
20                 CompileConditions(compiler);
21                 compiler.ToParent();
22             }
23         }
24
25         private void CompileConditions(Compiler compiler) {
26             NavigatorInput input = compiler.Input;
27             bool when       = false;
28             bool otherwise  = false;
29
30             do {
31                 switch (input.NodeType) {
32                 case XPathNodeType.Element:
33                     compiler.PushNamespaceScope();
34                     string nspace = input.NamespaceURI;
35                     string name   = input.LocalName;
36
37                     if (Ref.Equal(nspace, input.Atoms.UriXsl)) {
38                         IfAction action = null;
39                         if (Ref.Equal(name, input.Atoms.When)) {
40                             if (otherwise) {
41                                 throw XsltException.Create(Res.Xslt_WhenAfterOtherwise);
42                             }
43                             action = compiler.CreateIfAction(IfAction.ConditionType.ConditionWhen);
44                             when = true;
45                         }
46                         else if (Ref.Equal(name, input.Atoms.Otherwise)) {
47                             if (otherwise) {
48                                 throw XsltException.Create(Res.Xslt_DupOtherwise);
49                             }
50                             action = compiler.CreateIfAction(IfAction.ConditionType.ConditionOtherwise);
51                             otherwise = true;
52                         }
53                         else {
54                             throw compiler.UnexpectedKeyword();
55                         }
56                         AddAction(action);
57                     }
58                     else {
59                         throw compiler.UnexpectedKeyword();
60                     }
61                     compiler.PopScope();
62                     break;
63
64                 case XPathNodeType.Comment:
65                 case XPathNodeType.ProcessingInstruction:
66                 case XPathNodeType.Whitespace:
67                 case XPathNodeType.SignificantWhitespace:
68                     break;
69
70                 default:
71                     throw XsltException.Create(Res.Xslt_InvalidContents, "choose");
72                 }
73             }
74             while (compiler.Advance());
75             if (! when) {
76                 throw XsltException.Create(Res.Xslt_NoWhen);
77             }
78         }
79     }
80 }