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;
\r
32 using System.Collections.Specialized;
\r
34 using System.Xml.Schema;
\r
36 namespace Mono.Xml.Schema
\r
38 // Created per constraining element.
\r
39 internal class XsdKeyTable
\r
41 private XsdIdentitySelector selector;
\r
42 private XmlSchemaIdentityConstraint source;
\r
43 private XmlQualifiedName qname;
\r
44 private XmlQualifiedName refKeyName;
\r
46 public ArrayList Entries = new ArrayList ();
\r
47 public ArrayList FinishedEntries = new ArrayList ();
\r
49 public int StartDepth;
\r
50 public XsdKeyTable ReferencedKey;
\r
52 public XsdKeyTable (XmlSchemaIdentityConstraint source, XmlReader reader)
\r
54 Reset (source, reader);
\r
57 public XmlQualifiedName QualifiedName {
\r
58 get { return qname; }
\r
61 public XmlQualifiedName RefKeyName {
\r
62 get { return refKeyName; }
\r
65 public XmlSchemaIdentityConstraint SourceSchemaIdentity {
\r
66 get { return source; }
\r
69 public XsdIdentitySelector Selector {
\r
70 get { return selector; }
\r
73 public void Reset (XmlSchemaIdentityConstraint source, XmlReader reader)
\r
75 this.source = source;
\r
76 this.selector = source.CompiledSelector;
\r
77 this.qname = source.QualifiedName;
\r
78 XmlSchemaKeyref kr = source as XmlSchemaKeyref;
\r
80 this.refKeyName = kr.Refer;
\r
84 // In this method, attributes are ignored.
\r
85 public XsdIdentityPath SelectorMatches (ArrayList qnameStack, XmlReader reader)
\r
87 for (int i = 0; i < Selector.Paths.Length; i++) {
\r
88 XsdIdentityPath path = Selector.Paths [i];
\r
90 if (reader.Depth == this.StartDepth) {
\r
91 if (path.OrderedSteps.Length == 0)
\r
96 // It does not hit as yet (too shallow to hit).
\r
97 if (reader.Depth - this.StartDepth < path.OrderedSteps.Length - 1)
\r
100 int iter = path.OrderedSteps.Length;
\r
101 if (path.OrderedSteps [iter-1].IsAttribute)
\r
104 if (path.Descendants && reader.Depth < this.StartDepth + iter)
\r
106 else if (!path.Descendants && reader.Depth != this.StartDepth + iter)
\r
111 XsdIdentityStep step;
\r
112 for (int x = 0; 0 <= iter; x++, iter--) {
\r
113 step = path.OrderedSteps [iter];
\r
114 if (step.IsAnyName)
\r
116 XmlQualifiedName qname = (XmlQualifiedName) qnameStack [qnameStack.Count - x - 1];
\r
117 if (step.NsName != null && qname.Namespace == step.NsName)
\r
119 if (step.Name == qname.Name && step.Namespace == qname.Namespace)
\r
124 if (iter >= 0) // i.e. did not match against the path.
\r