2 // Mono.Xml.Schema.XsdKeyTable.cs
5 // Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
7 // (C)2003 Atsushi Enomoto
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections;
32 using System.Collections.Specialized;
34 using System.Xml.Schema;
36 namespace Mono.Xml.Schema
38 internal class XsdKeyEntryCollection : CollectionBase
40 public void Add (XsdKeyEntry entry)
45 public XsdKeyEntry this [int i] {
46 get { return (XsdKeyEntry) List [i]; }
47 set { List [i] = value; }
51 // Created per constraining element.
52 internal class XsdKeyTable
54 // FIXME: no need after #70419
55 public readonly bool alwaysTrue = true;
57 private XsdIdentitySelector selector;
58 private XmlSchemaIdentityConstraint source;
59 private XmlQualifiedName qname;
60 private XmlQualifiedName refKeyName;
62 public XsdKeyEntryCollection Entries =
63 new XsdKeyEntryCollection ();
64 public XsdKeyEntryCollection FinishedEntries =
65 new XsdKeyEntryCollection ();
67 public int StartDepth;
68 public XsdKeyTable ReferencedKey;
70 public XsdKeyTable (XmlSchemaIdentityConstraint source)
75 public XmlQualifiedName QualifiedName {
79 public XmlQualifiedName RefKeyName {
80 get { return refKeyName; }
83 public XmlSchemaIdentityConstraint SourceSchemaIdentity {
84 get { return source; }
87 public XsdIdentitySelector Selector {
88 get { return selector; }
91 public void Reset (XmlSchemaIdentityConstraint source)
94 this.selector = source.CompiledSelector;
95 this.qname = source.QualifiedName;
96 XmlSchemaKeyref kr = source as XmlSchemaKeyref;
98 this.refKeyName = kr.Refer;
102 // In this method, attributes are ignored.
103 public XsdIdentityPath SelectorMatches (ArrayList qnameStack, int depth)
105 for (int i = 0; i < Selector.Paths.Length; i++) {
106 XsdIdentityPath path = Selector.Paths [i];
108 if (depth == this.StartDepth) {
109 if (path.OrderedSteps.Length == 0)
114 // It does not hit as yet (too shallow to hit).
115 if (depth - this.StartDepth < path.OrderedSteps.Length - 1)
118 int iter = path.OrderedSteps.Length;
119 if (path.OrderedSteps [iter-1].IsAttribute)
122 if (path.Descendants && depth < this.StartDepth + iter)
124 else if (!path.Descendants && depth != this.StartDepth + iter)
129 XsdIdentityStep step;
130 for (int x = 0; 0 <= iter; x++, iter--) {
131 step = path.OrderedSteps [iter];
134 XmlQualifiedName qname = (XmlQualifiedName) qnameStack [qnameStack.Count - x - 1];
135 if (step.NsName != null && qname.Namespace == step.NsName)
137 if (step.Name == qname.Name && step.Namespace == qname.Namespace)
142 if (iter >= 0) // i.e. did not match against the path.