(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.XML / System.Xml.Schema / XmlSchemaIdentityConstraint.cs
blob49f8b76041ee2c7be44e2a9b23bbb811a5147fef
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.Collections;
26 using System.Xml;
27 using System.Xml.Serialization;
28 using Mono.Xml.Schema;
30 namespace System.Xml.Schema
32 /// <summary>
33 /// Summary description for XmlSchemaIdentityConstraint.
34 /// </summary>
35 public class XmlSchemaIdentityConstraint : XmlSchemaAnnotated
37 private XmlSchemaObjectCollection fields;
38 private string name;
39 private XmlQualifiedName qName;
40 private XmlSchemaXPath selector;
42 private XsdIdentitySelector compiledSelector;
43 // ArrayList compiledFields;
45 public XmlSchemaIdentityConstraint()
47 fields = new XmlSchemaObjectCollection();
48 qName = XmlQualifiedName.Empty;
51 [System.Xml.Serialization.XmlAttribute("name")]
52 public string Name
54 get{ return name; }
55 set{ name = value; }
58 [XmlElement("selector",typeof(XmlSchemaXPath),Namespace=XmlSchema.Namespace)]
59 public XmlSchemaXPath Selector
61 get{ return selector; }
62 set{ selector = value; }
65 [XmlElement("field",typeof(XmlSchemaXPath),Namespace=XmlSchema.Namespace)]
66 public XmlSchemaObjectCollection Fields
68 get{ return fields; }
71 [XmlIgnore]
72 public XmlQualifiedName QualifiedName
74 get{ return qName; }
77 internal XsdIdentitySelector CompiledSelector {
78 get { return compiledSelector; }
81 /// <remarks>
82 /// 1. name must be present
83 /// 2. selector and field must be present
84 /// </remarks>
85 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
87 // If this is already compiled this time, simply skip.
88 if (this.IsComplied (schema.CompilationId))
89 return 0;
91 if(Name == null)
92 error(h,"Required attribute name must be present");
93 else if(!XmlSchemaUtil.CheckNCName(this.name))
94 error(h,"attribute name must be NCName");
95 else {
96 this.qName = new XmlQualifiedName(Name,schema.TargetNamespace);
97 if (schema.NamedIdentities.Contains (qName))
98 error(h,"There is already same named identity constraint in this namespace.");
99 else
100 schema.NamedIdentities.Add (qName, this);
103 if(Selector == null)
104 error(h,"selector must be present");
105 else
107 Selector.isSelector = true;
108 errorCount += Selector.Compile(h,schema);
109 if (selector.errorCount == 0)
110 compiledSelector = new XsdIdentitySelector (Selector);
112 if (errorCount > 0)
113 return errorCount; // fatal
115 if(Fields.Count == 0)
116 error(h,"atleast one field value must be present");
117 else
119 for (int i = 0; i < Fields.Count; i++)
121 XmlSchemaXPath field = Fields [i] as XmlSchemaXPath;
122 if(field != null)
124 errorCount += field.Compile(h,schema);
125 if (field.errorCount == 0)
126 this.compiledSelector.AddField (new XsdIdentityField (field, i));
128 else
129 error (h, "Object of type " + Fields [i].GetType() + " is invalid in the Fields Collection");
132 XmlSchemaUtil.CompileID(Id,this,schema.IDCollection,h);
134 this.CompilationId = schema.CompilationId;
135 return errorCount;