The Labs \ Source Viewer \ SSCLI \ System.Xml.Schema \ ConstraintRole

  1. //------------------------------------------------------------------------------
  2. // <copyright file="CompiledIdentityConstraint.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. // <owner current="true" primary="true">priyal</owner>
  15. //------------------------------------------------------------------------------
  16. namespace System.Xml.Schema
  17. {
  18.    
  19.     using System.Text;
  20.     using System.Collections;
  21.     using System.Diagnostics;
  22.     using System.Xml.XPath;
  23.     using MS.Internal.Xml.XPath;
  24.    
  25.     internal class CompiledIdentityConstraint
  26.     {
  27.         internal XmlQualifiedName name = XmlQualifiedName.Empty;
  28.         private ConstraintRole role;
  29.         private Asttree selector;
  30.         private Asttree[] fields;
  31.         internal XmlQualifiedName refer = XmlQualifiedName.Empty;
  32.        
  33.         public enum ConstraintRole
  34.         {
  35.             Unique,
  36.             Key,
  37.             Keyref
  38.         }
  39.        
  40.         public ConstraintRole Role {
  41.             get { return this.role; }
  42.         }
  43.        
  44.         public Asttree Selector {
  45.             get { return this.selector; }
  46.         }
  47.        
  48.         public Asttree[] Fields {
  49.             get { return this.fields; }
  50.         }
  51.        
  52.         public static readonly CompiledIdentityConstraint Empty = new CompiledIdentityConstraint();
  53.        
  54.         private CompiledIdentityConstraint()
  55.         {
  56.         }
  57.        
  58.         public CompiledIdentityConstraint(XmlSchemaIdentityConstraint constraint, XmlNamespaceManager nsmgr)
  59.         {
  60.             this.name = constraint.QualifiedName;
  61.            
  62.             //public Asttree (string xPath, bool isField, XmlNamespaceManager nsmgr)
  63.             try {
  64.                 this.selector = new Asttree(constraint.Selector.XPath, false, nsmgr);
  65.             }
  66.             catch (XmlSchemaException e) {
  67.                 e.SetSource(constraint.Selector);
  68.                 throw e;
  69.             }
  70.             XmlSchemaObjectCollection fields = constraint.Fields;
  71.             Debug.Assert(fields.Count > 0);
  72.             this.fields = new Asttree[fields.Count];
  73.             for (int idxField = 0; idxField < fields.Count; idxField++) {
  74.                 try {
  75.                     this.fields[idxField] = new Asttree(((XmlSchemaXPath)fields[idxField]).XPath, true, nsmgr);
  76.                 }
  77.                 catch (XmlSchemaException e) {
  78.                     e.SetSource(constraint.Fields[idxField]);
  79.                     throw e;
  80.                 }
  81.             }
  82.             if (constraint is XmlSchemaUnique) {
  83.                 this.role = ConstraintRole.Unique;
  84.             }
  85.             else if (constraint is XmlSchemaKey) {
  86.                 this.role = ConstraintRole.Key;
  87.             }
  88.             else {
  89.                 // XmlSchemaKeyref
  90.                 this.role = ConstraintRole.Keyref;
  91.                 this.refer = ((XmlSchemaKeyref)constraint).Refer;
  92.             }
  93.         }
  94.     }
  95.    
  96. }

Developer Fusion