(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.XML / System.Xml.Schema / XmlSchemaKey.cs
bloba70a608c1ead77835a8e83e58160f8a8a63a683e
1 // Author: Dwivedi, Ajay kumar
2 // Adwiv@Yahoo.com
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the
7 // "Software"), to deal in the Software without restriction, including
8 // without limitation the rights to use, copy, modify, merge, publish,
9 // distribute, sublicense, and/or sell copies of the Software, and to
10 // permit persons to whom the Software is furnished to do so, subject to
11 // the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be
14 // included in all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 using System;
25 using System.Xml;
27 namespace System.Xml.Schema
29 /// <summary>
30 /// Summary description for XmlSchemaKey.
31 /// </summary>
32 public class XmlSchemaKey : XmlSchemaIdentityConstraint
34 const string xmlname = "key";
36 public XmlSchemaKey()
39 /// <remarks>
40 /// 1. name must be present
41 /// 2. selector and field must be present
42 /// </remarks>
43 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
45 return base.Compile(h, schema);
49 internal new void error(ValidationEventHandler handle, string message)
51 errorCount++;
52 ValidationHandler.RaiseValidationError(handle, this, message);
56 //<key
57 // id = ID
58 // name = NCName
59 // {any attributes with non-schema namespace . . .}>
60 // Content: (annotation?, (selector, field+))
61 //</key>
62 internal static XmlSchemaKey Read(XmlSchemaReader reader, ValidationEventHandler h)
64 XmlSchemaKey key = new XmlSchemaKey();
65 reader.MoveToElement();
67 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
69 error(h,"Should not happen :1: XmlSchemaKey.Read, name="+reader.Name,null);
70 reader.Skip();
71 return null;
74 key.LineNumber = reader.LineNumber;
75 key.LinePosition = reader.LinePosition;
76 key.SourceUri = reader.BaseURI;
78 while(reader.MoveToNextAttribute())
80 if(reader.Name == "id")
82 key.Id = reader.Value;
84 else if(reader.Name == "name")
86 key.Name = reader.Value;
88 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
90 error(h,reader.Name + " is not a valid attribute for key",null);
92 else
94 XmlSchemaUtil.ReadUnhandledAttribute(reader,key);
98 reader.MoveToElement();
99 if(reader.IsEmptyElement)
100 return key;
102 // Content: annotation?, selector, field+
103 int level = 1;
104 while(reader.ReadNextElement())
106 if(reader.NodeType == XmlNodeType.EndElement)
108 if(reader.LocalName != xmlname)
109 error(h,"Should not happen :2: XmlSchemaKey.Read, name="+reader.Name,null);
110 break;
112 if(level <= 1 && reader.LocalName == "annotation")
114 level = 2; //Only one annotation
115 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
116 if(annotation != null)
117 key.Annotation = annotation;
118 continue;
120 if(level <= 2 && reader.LocalName == "selector")
122 level = 3;
123 XmlSchemaXPath selector = XmlSchemaXPath.Read(reader,h,"selector");
124 if(selector != null)
125 key.Selector = selector;
126 continue;
128 if(level <= 3 && reader.LocalName == "field")
130 level = 3;
131 if(key.Selector == null)
132 error(h,"selector must be defined before field declarations",null);
133 XmlSchemaXPath field = XmlSchemaXPath.Read(reader,h,"field");
134 if(field != null)
135 key.Fields.Add(field);
136 continue;
138 reader.RaiseInvalidElementError();
140 return key;