The Labs \ Source Viewer \ SSCLI \ System.Xml.Xsl.Qil \ QilExpression

  1. //------------------------------------------------------------------------------
  2. // <copyright file="QilExpression.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. using System;
  16. using System.Collections.Generic;
  17. using System.Diagnostics;
  18. using System.Xml;
  19. using System.Security;
  20. using System.Security.Permissions;
  21. using System.Security.Policy;
  22. using System.Xml.Schema;
  23. using System.Xml.Xsl;
  24. namespace System.Xml.Xsl.Qil
  25. {
  26.    
  27.     /// <summary>
  28.     /// The CQR implementation of QilExpression.
  29.     /// </summary>
  30.     /// <remarks>
  31.     /// <p>QilExpression is the XML Query Intermediate Language invented by Michael Brundage and Chris Suver.
  32.     /// QilExpression is an intermediate representation (IR) for all XML query and view languages. QilExpression is
  33.     /// designed for optimization, composition with virtual XML views, translation into other forms,
  34.     /// and direct execution. See also <a href="http://dynamo/qil/qil.xml">the QIL specification</a>.</p>
  35.     /// </remarks>
  36.     internal class QilExpression : QilNode
  37.     {
  38.         private QilFactory factory;
  39.         private QilNode isDebug;
  40.         private QilNode defWSet;
  41.         private QilNode wsRules;
  42.         private QilNode funList;
  43.         private QilNode gloVars;
  44.         private QilNode gloParams;
  45.         private QilNode rootNod;
  46.        
  47.        
  48.         //-----------------------------------------------
  49.         // Constructors
  50.         //-----------------------------------------------
  51.        
  52.         /// <summary>
  53.         /// Construct QIL from a rooted graph of QilNodes with a new factory.
  54.         /// </summary>
  55.         public QilExpression(QilNodeType nodeType, QilNode root) : this(nodeType, root, new QilFactory())
  56.         {
  57.         }
  58.        
  59.         /// <summary>
  60.         /// Construct QIL from a rooted graph of QilNodes with a specific factory.
  61.         /// </summary>
  62.         public QilExpression(QilNodeType nodeType, QilNode root, QilFactory factory) : base(nodeType)
  63.         {
  64.             this.factory = factory;
  65.             this.isDebug = factory.False();
  66.            
  67.             XmlWriterSettings settings = new XmlWriterSettings();
  68.             settings.ConformanceLevel = ConformanceLevel.Auto;
  69.             this.defWSet = factory.LiteralObject(settings);
  70.            
  71.             this.wsRules = factory.LiteralObject(new List<WhitespaceRule>());
  72.             this.funList = factory.FunctionList();
  73.             this.gloVars = factory.GlobalVariableList();
  74.             this.gloParams = factory.GlobalParameterList();
  75.             this.rootNod = root;
  76.         }
  77.        
  78.        
  79.         //-----------------------------------------------
  80.         // IList<QilNode> methods -- override
  81.         //-----------------------------------------------
  82.        
  83.         public override int Count {
  84.             get { return 7; }
  85.         }
  86.        
  87.         public override QilNode this[int index]
  88.         {
  89.             get {
  90.                 switch (index) {
  91.                     case 0:
  92.                         return this.isDebug;
  93.                     case 1:
  94.                         return this.defWSet;
  95.                     case 2:
  96.                         return this.wsRules;
  97.                     case 3:
  98.                         return this.gloParams;
  99.                     case 4:
  100.                         return this.gloVars;
  101.                     case 5:
  102.                         return this.funList;
  103.                     case 6:
  104.                         return this.rootNod;
  105.                     default:
  106.                         throw new IndexOutOfRangeException();
  107.                         break;
  108.                 }
  109.             }
  110.             set {
  111.                 switch (index) {
  112.                     case 0:
  113.                         this.isDebug = value;
  114.                         break;
  115.                     case 1:
  116.                         this.defWSet = value;
  117.                         break;
  118.                     case 2:
  119.                         this.wsRules = value;
  120.                         break;
  121.                     case 3:
  122.                         this.gloParams = value;
  123.                         break;
  124.                     case 4:
  125.                         this.gloVars = value;
  126.                         break;
  127.                     case 5:
  128.                         this.funList = value;
  129.                         break;
  130.                     case 6:
  131.                         this.rootNod = value;
  132.                         break;
  133.                     default:
  134.                         throw new IndexOutOfRangeException();
  135.                         break;
  136.                 }
  137.             }
  138.         }
  139.        
  140.        
  141.         //-----------------------------------------------
  142.         // QilExpression methods
  143.         //-----------------------------------------------
  144.        
  145.         /// <summary>
  146.         /// QilFactory to be used in constructing nodes in this graph.
  147.         /// </summary>
  148.         public QilFactory Factory {
  149.             get { return this.factory; }
  150.             set { this.factory = value; }
  151.         }
  152.        
  153.         /// <summary>
  154.         /// True if this expression contains debugging information.
  155.         /// </summary>
  156.         public bool IsDebug {
  157.             get { return this.isDebug.NodeType == QilNodeType.True; }
  158.             set { this.isDebug = value ? this.factory.True() : this.factory.False(); }
  159.         }
  160.        
  161.         /// <summary>
  162.         /// Default serialization options that will be used if the user does not supply a writer at execution time.
  163.         /// </summary>
  164.         public XmlWriterSettings DefaultWriterSettings {
  165.             get { return (XmlWriterSettings)((QilLiteral)this.defWSet).Value; }
  166.             set {
  167.                 value.ReadOnly = true;
  168.                 ((QilLiteral)this.defWSet).Value = value;
  169.             }
  170.         }
  171.        
  172.         /// <summary>
  173.         /// Xslt whitespace strip/preserve rules.
  174.         /// </summary>
  175.         public IList<WhitespaceRule> WhitespaceRules {
  176.             get { return (IList<WhitespaceRule>)((QilLiteral)this.wsRules).Value; }
  177.             set { ((QilLiteral)this.wsRules).Value = value; }
  178.         }
  179.        
  180.         /// <summary>
  181.         /// External parameters.
  182.         /// </summary>
  183.         public QilList GlobalParameterList {
  184.             get { return (QilList)this.gloParams; }
  185.             set { this.gloParams = value; }
  186.         }
  187.        
  188.         /// <summary>
  189.         /// Global variables.
  190.         /// </summary>
  191.         public QilList GlobalVariableList {
  192.             get { return (QilList)this.gloVars; }
  193.             set { this.gloVars = value; }
  194.         }
  195.        
  196.         /// <summary>
  197.         /// Function definitions.
  198.         /// </summary>
  199.         public QilList FunctionList {
  200.             get { return (QilList)this.funList; }
  201.             set { this.funList = value; }
  202.         }
  203.        
  204.         /// <summary>
  205.         /// The root node of the QilExpression graph
  206.         /// </summary>
  207.         public QilNode Root {
  208.             get { return this.rootNod; }
  209.             set { this.rootNod = value; }
  210.         }
  211.     }
  212. }

Developer Fusion