Update Reference Sources to .NET Framework 4.6.1
[mono.git] / mcs / class / referencesource / System.Data.SqlXml / System / Xml / Xsl / XsltOld / AttributeSetAction.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="AttributeSetAction.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>                                                                
5 // <owner current="true" primary="true">[....]</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 AttributeSetAction : ContainerAction {
17         internal XmlQualifiedName            name;
18
19         internal XmlQualifiedName Name {
20             get { return this.name; }
21         }
22
23         internal override void Compile(Compiler compiler) {
24             CompileAttributes(compiler);
25             CheckRequiredAttribute(compiler, this.name, "name");
26             CompileContent(compiler);
27         }
28
29         internal override bool CompileAttribute(Compiler compiler) {
30             string name   = compiler.Input.LocalName;
31             string value  = compiler.Input.Value;
32             if (Ref.Equal(name, compiler.Atoms.Name)) {
33                 Debug.Assert(this.name == null);
34                 this.name = compiler.CreateXPathQName(value);
35             }
36             else if (Ref.Equal(name, compiler.Atoms.UseAttributeSets)) {
37                 // create a UseAttributeSetsAction
38                 // sets come before xsl:attributes
39                 AddAction(compiler.CreateUseAttributeSetsAction());
40             }
41             else {
42                 return false;
43             }
44
45             return true;
46         }
47
48         private void CompileContent(Compiler compiler) {
49             NavigatorInput input = compiler.Input;
50
51             if (compiler.Recurse()) {
52                 do {
53                     switch(input.NodeType) {
54                     case XPathNodeType.Element:
55                         compiler.PushNamespaceScope();
56
57                         string nspace = input.NamespaceURI;
58                         string name   = input.LocalName;
59
60                         if (Ref.Equal(nspace, input.Atoms.UriXsl) && Ref.Equal(name, input.Atoms.Attribute)) {
61                             // found attribute so add it
62                             AddAction(compiler.CreateAttributeAction());
63                         }
64                         else {
65                             throw compiler.UnexpectedKeyword();
66                         }
67                         compiler.PopScope();
68                         break;
69
70                     case XPathNodeType.Comment:
71                     case XPathNodeType.ProcessingInstruction:
72                     case XPathNodeType.Whitespace:
73                     case XPathNodeType.SignificantWhitespace:
74                         break;
75
76                     default:
77                         throw XsltException.Create(Res.Xslt_InvalidContents, "attribute-set");
78                     }
79                 }
80                 while(compiler.Advance());
81
82                 compiler.ToParent();
83             }
84         }
85
86         internal void Merge(AttributeSetAction attributeAction) {
87             // add the contents of "attributeAction" to this action
88             // place them at the end
89             Action  action;
90             int     i = 0;
91
92             while((action = attributeAction.GetAction(i)) != null) {
93                 AddAction(action);
94                 i++;
95             }
96         }
97     }
98 }