New test.
[mono.git] / mcs / class / System.XML / Mono.Xml.Schema / XsdIdentityPath.cs
1 //
2 // Mono.Xml.Schema.XsdIdentityPath.cs
3 //
4 // Author:
5 //      Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
6 //
7 //      (C)2003 Atsushi Enomoto
8 //
9 //
10 // These classses represents XML Schema's fake XPath, which 
11 // W3C specification calls "XPath", although it is very different
12 // language from XPath.
13 //
14 //
15
16 //
17 // Permission is hereby granted, free of charge, to any person obtaining
18 // a copy of this software and associated documentation files (the
19 // "Software"), to deal in the Software without restriction, including
20 // without limitation the rights to use, copy, modify, merge, publish,
21 // distribute, sublicense, and/or sell copies of the Software, and to
22 // permit persons to whom the Software is furnished to do so, subject to
23 // the following conditions:
24 // 
25 // The above copyright notice and this permission notice shall be
26 // included in all copies or substantial portions of the Software.
27 // 
28 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 //
36 using System;
37 using System.Collections;
38 using System.Xml;
39 using System.Xml.Schema;
40
41 namespace Mono.Xml.Schema
42 {
43         internal class XsdIdentitySelector
44         {
45                 XsdIdentityPath [] selectorPaths;
46
47                 ArrayList fields = new ArrayList ();
48                 XsdIdentityField [] cachedFields;
49
50                 public XsdIdentitySelector (XmlSchemaXPath selector)
51                 {
52                         selectorPaths = selector.CompiledExpression;
53                 }
54
55                 public XsdIdentityPath [] Paths {
56                         get { return selectorPaths; }
57                 }
58
59                 public void AddField (XsdIdentityField field)
60                 {
61                         cachedFields = null;
62                         fields.Add (field);
63                 }
64
65                 public XsdIdentityField [] Fields {
66                         get {
67                                 if (cachedFields == null)
68                                         cachedFields = fields.ToArray (typeof (XsdIdentityField)) as XsdIdentityField [];
69                                 return cachedFields;
70                         }
71                 }
72         }
73
74         internal class XsdIdentityField
75         {
76                 XsdIdentityPath [] fieldPaths;
77                 int index;
78
79                 public XsdIdentityField (XmlSchemaXPath field, int index)
80                 {
81                         this.index = index;
82                         fieldPaths = field.CompiledExpression;
83                 }
84
85                 public XsdIdentityPath [] Paths {
86                         get { return fieldPaths; }
87                 }
88
89                 public int Index {
90                         get { return index; }
91                 }
92         }
93
94         internal class XsdIdentityPath
95         {
96                 public XsdIdentityPath ()
97                 {
98                 }
99
100                 public XsdIdentityStep [] OrderedSteps;
101                 public bool Descendants;
102
103                 public bool IsAttribute {
104                         get {
105                                 return OrderedSteps.Length == 0 ?
106                                         false :
107                                         OrderedSteps [OrderedSteps.Length - 1].IsAttribute;
108                         }
109                 }
110         }
111
112         internal class XsdIdentityStep
113         {
114                 public bool IsCurrent;
115                 public bool IsAttribute;
116                 public bool IsAnyName;
117                 public string NsName;
118                 public string Name;
119                 public string Namespace = "";
120         }
121 }