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

  1. //------------------------------------------------------------------------------
  2. // <copyright file="UseAttributeSetsAction.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 UseAttributeSetsAction : CompiledAction
  25.     {
  26.         private XmlQualifiedName[] useAttributeSets;
  27.         private string useString;
  28.        
  29.         private const int ProcessingSets = 2;
  30.        
  31.         internal XmlQualifiedName[] UsedSets {
  32.             get { return this.useAttributeSets; }
  33.         }
  34.        
  35.         internal override void Compile(Compiler compiler)
  36.         {
  37.             Debug.Assert(Keywords.Equals(compiler.Input.LocalName, compiler.Atoms.UseAttributeSets));
  38.             this.useString = compiler.Input.Value;
  39.            
  40.             Debug.Assert(this.useAttributeSets == null);
  41.            
  42.             if (this.useString.Length == 0) {
  43.                 // Split creates empty node is spliting empty string
  44.                 this.useAttributeSets = new XmlQualifiedName[0];
  45.                 return;
  46.             }
  47.            
  48.             string[] qnames = XmlConvert.SplitString(this.useString);
  49.            
  50.             try {
  51.                 this.useAttributeSets = new XmlQualifiedName[qnames.Length];
  52.                 {
  53.                     for (int i = 0; i < qnames.Length; i++) {
  54.                         this.useAttributeSets[i] = compiler.CreateXPathQName(qnames[i]);
  55.                     }
  56.                 }
  57.             }
  58.             catch (XsltException) {
  59.                 if (!compiler.ForwardCompatibility) {
  60.                     // Rethrow the exception if we're not in forwards-compatible mode
  61.                     throw;
  62.                 }
  63.                 // Ignore the whole list in forwards-compatible mode
  64.                 this.useAttributeSets = new XmlQualifiedName[0];
  65.             }
  66.         }
  67.        
  68.         internal override void Execute(Processor processor, ActionFrame frame)
  69.         {
  70.             switch (frame.State) {
  71.                 case Initialized:
  72.                     frame.Counter = 0;
  73.                     frame.State = ProcessingSets;
  74.                     goto case ProcessingSets;
  75.                     break;
  76.                 case ProcessingSets:
  77.                    
  78.                     if (frame.Counter < this.useAttributeSets.Length) {
  79.                         AttributeSetAction action = processor.RootAction.GetAttributeSet(this.useAttributeSets[frame.Counter]);
  80.                         frame.IncrementCounter();
  81.                         processor.PushActionFrame(action, frame.NodeSet);
  82.                     }
  83.                     else {
  84.                         frame.Finished();
  85.                     }
  86.                     break;
  87.                 default:
  88.                    
  89.                     Debug.Fail("Invalid Container action execution state");
  90.                     break;
  91.             }
  92.         }
  93.     }
  94. }

Developer Fusion