d6bb8a5ea766f12583682e7ea60a43930410c5a7
[mono.git] / mcs / class / referencesource / System.Xml / System / Xml / Schema / CompiledidEntityConstraint.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="CompiledIdentityConstraint.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 // <owner current="true" primary="true">Microsoft</owner>                                                                
6 //------------------------------------------------------------------------------
7
8 namespace System.Xml.Schema {
9
10     using System.Text;
11     using System.Collections;
12     using System.Diagnostics;
13     using System.Xml.XPath;
14     using MS.Internal.Xml.XPath;
15
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;
22
23         public enum ConstraintRole {
24             Unique,
25             Key,
26             Keyref
27         }
28
29         public ConstraintRole Role {
30             get { return this.role; }
31         }
32
33         public Asttree Selector {
34             get { return this.selector; }
35         }
36
37         public Asttree[] Fields {
38             get { return this.fields; }
39         }
40
41         public static readonly CompiledIdentityConstraint Empty = new CompiledIdentityConstraint();
42
43         private CompiledIdentityConstraint() {}
44
45         public CompiledIdentityConstraint(XmlSchemaIdentityConstraint constraint, XmlNamespaceManager nsmgr) {
46             this.name = constraint.QualifiedName;
47
48             //public Asttree (string xPath, bool isField, XmlNamespaceManager nsmgr)
49             try {
50                 this.selector = new Asttree(constraint.Selector.XPath, false, nsmgr);
51             }
52             catch (XmlSchemaException e) {
53                 e.SetSource(constraint.Selector);
54                 throw e;
55             }
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 ++) {
60                 try {
61                     this.fields[idxField] = new Asttree(((XmlSchemaXPath)fields[idxField]).XPath, true, nsmgr);
62                 }
63                 catch (XmlSchemaException e) {
64                     e.SetSource(constraint.Fields[idxField]);
65                     throw e;
66                 }
67             }
68             if (constraint is XmlSchemaUnique) {
69                 this.role = ConstraintRole.Unique;
70             } 
71             else if (constraint is XmlSchemaKey) {
72                 this.role = ConstraintRole.Key;
73             } 
74             else {             // XmlSchemaKeyref
75                 this.role = ConstraintRole.Keyref;
76                 this.refer = ((XmlSchemaKeyref)constraint).Refer; 
77             }
78         }
79     }
80
81 }
82
83