1 //------------------------------------------------------------------------------
2 // <copyright file="CompiledIdentityConstraint.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
8 namespace System.Xml.Schema {
11 using System.Collections;
12 using System.Diagnostics;
13 using System.Xml.XPath;
14 using MS.Internal.Xml.XPath;
16 internal class CompiledIdentityConstraint {
17 internal XmlQualifiedName name = XmlQualifiedName.Empty;
18 private ConstraintRole role;
19 private Asttree selector;
20 private Asttree[] fields;
21 internal XmlQualifiedName refer = XmlQualifiedName.Empty;
23 public enum ConstraintRole {
29 public ConstraintRole Role {
30 get { return this.role; }
33 public Asttree Selector {
34 get { return this.selector; }
37 public Asttree[] Fields {
38 get { return this.fields; }
41 public static readonly CompiledIdentityConstraint Empty = new CompiledIdentityConstraint();
43 private CompiledIdentityConstraint() {}
45 public CompiledIdentityConstraint(XmlSchemaIdentityConstraint constraint, XmlNamespaceManager nsmgr) {
46 this.name = constraint.QualifiedName;
48 //public Asttree (string xPath, bool isField, XmlNamespaceManager nsmgr)
50 this.selector = new Asttree(constraint.Selector.XPath, false, nsmgr);
52 catch (XmlSchemaException e) {
53 e.SetSource(constraint.Selector);
56 XmlSchemaObjectCollection fields = constraint.Fields;
57 Debug.Assert(fields.Count > 0);
58 this.fields = new Asttree[fields.Count];
59 for(int idxField = 0; idxField < fields.Count; idxField ++) {
61 this.fields[idxField] = new Asttree(((XmlSchemaXPath)fields[idxField]).XPath, true, nsmgr);
63 catch (XmlSchemaException e) {
64 e.SetSource(constraint.Fields[idxField]);
68 if (constraint is XmlSchemaUnique) {
69 this.role = ConstraintRole.Unique;
71 else if (constraint is XmlSchemaKey) {
72 this.role = ConstraintRole.Key;
74 else { // XmlSchemaKeyref
75 this.role = ConstraintRole.Keyref;
76 this.refer = ((XmlSchemaKeyref)constraint).Refer;