2 // Mono.Xml.Schema.XsdKeyTable.cs
5 // Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
7 // (C)2003 Atsushi Enomoto
10 using System.Collections;
\r
11 using System.Collections.Specialized;
\r
13 using System.Xml.Schema;
\r
15 namespace Mono.Xml.Schema
\r
17 // Created per constraining element.
\r
18 public class XsdKeyTable
\r
21 private ArrayList entries = new ArrayList ();
\r
22 private ArrayList finishedEntries = new ArrayList ();
\r
23 private XsdKeyEntry [] cachedEntries;
\r
24 private XsdKeyEntry [] cachedFinishedEntries;
\r
27 private XsdIdentitySelector selector;
\r
28 private XmlSchemaIdentityConstraint source;
\r
29 private XmlQualifiedName qname;
\r
30 private XmlQualifiedName refKeyName;
\r
32 public ArrayList Entries = new ArrayList ();
\r
33 public ArrayList FinishedEntries = new ArrayList ();
\r
35 public int StartDepth;
\r
36 public XsdKeyTable ReferencedKey;
\r
38 public XsdKeyTable (XmlSchemaIdentityConstraint source, XmlReader reader)
\r
40 Reset (source, reader);
\r
44 public XsdKeyEntry [] Entries {
\r
46 if (cachedEntries == null)
\r
47 cachedEntries = entries.ToArray (typeof (XsdKeyEntry)) as XsdKeyEntry [];
\r
48 return cachedEntries;
\r
52 public XsdKeyEntry [] FinishedEntries {
\r
54 if (cachedFinishedEntries == null)
\r
55 cachedFinishedEntries = finishedEntries.ToArray (typeof (XsdKeyEntry)) as XsdKeyEntry [];
\r
56 return cachedFinishedEntries;
\r
61 public XmlQualifiedName QualifiedName {
\r
62 get { return qname; }
\r
65 public XmlQualifiedName RefKeyName {
\r
66 get { return refKeyName; }
\r
69 public XmlSchemaIdentityConstraint SourceSchemaIdentity {
\r
70 get { return source; }
\r
73 public XsdIdentitySelector Selector {
\r
74 get { return selector; }
\r
77 public void Reset (XmlSchemaIdentityConstraint source, XmlReader reader)
\r
79 this.source = source;
\r
80 this.selector = source.CompiledSelector;
\r
81 this.qname = source.QualifiedName;
\r
82 XmlSchemaKeyref kr = source as XmlSchemaKeyref;
\r
84 this.refKeyName = kr.Refer;
\r
88 // In this method, attributes are ignored.
\r
89 public XsdIdentityPath SelectorMatches (ArrayList qnameStack, XmlReader reader)
\r
91 foreach (XsdIdentityPath path in Selector.Paths) {
\r
93 if (reader.Depth == this.StartDepth) {
\r
94 if (path.OrderedSteps.Length == 0)
\r
99 // It does not hit as yet (too shallow to hit).
\r
100 if (reader.Depth - this.StartDepth < path.OrderedSteps.Length - 1)
\r
103 int iter = path.OrderedSteps.Length;
\r
104 if (path.OrderedSteps [iter-1].IsAttribute)
\r
107 if (path.Descendants && reader.Depth < this.StartDepth + iter)
\r
109 else if (!path.Descendants && reader.Depth != this.StartDepth + iter)
\r
114 XsdIdentityStep step;
\r
115 for (int x = 0; x <= iter; x++, iter--) {
\r
116 step = path.OrderedSteps [iter - x];
\r
117 if (step.IsAnyName)
\r
119 XmlQualifiedName qname = (XmlQualifiedName) qnameStack [qnameStack.Count - x - 1];
\r
120 if (step.NsName != null && qname.Namespace == step.NsName)
\r
122 if (step.Name == qname.Name && step.Namespace == qname.Namespace)
\r
127 if (iter >= 0) // i.e. did not match against the path.
\r