1 // Author: Dwivedi, Ajay kumar
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:
13 // The above copyright notice and this permission notice shall be
14 // included in all copies or substantial portions of the Software.
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.
25 using System.Collections;
27 using System.Xml.Serialization;
28 using Mono.Xml.Schema;
30 namespace System.Xml.Schema
33 /// Summary description for XmlSchemaIdentityConstraint.
35 public class XmlSchemaIdentityConstraint : XmlSchemaAnnotated
37 private XmlSchemaObjectCollection fields;
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")]
58 [XmlElement("selector",typeof(XmlSchemaXPath))]
59 public XmlSchemaXPath Selector
61 get{ return selector; }
62 set{ selector = value; }
65 [XmlElement("field",typeof(XmlSchemaXPath))]
66 public XmlSchemaObjectCollection Fields
72 public XmlQualifiedName QualifiedName
77 internal XsdIdentitySelector CompiledSelector {
78 get { return compiledSelector; }
82 /// 1. name must be present
83 /// 2. selector and field must be present
85 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
87 // If this is already compiled this time, simply skip.
88 if (CompilationId == schema.CompilationId)
93 Selector.Parent = this;
94 foreach (XmlSchemaObject obj in Fields)
99 error(h,"Required attribute name must be present");
100 else if(!XmlSchemaUtil.CheckNCName(this.name))
101 error(h,"attribute name must be NCName");
103 this.qName = new XmlQualifiedName(Name,schema.TargetNamespace);
104 if (schema.NamedIdentities.Contains (qName))
105 error(h,"There is already same named identity constraint in this namespace.");
107 schema.NamedIdentities.Add (qName, this);
111 error(h,"selector must be present");
114 Selector.isSelector = true;
115 errorCount += Selector.Compile(h,schema);
116 if (selector.errorCount == 0)
117 compiledSelector = new XsdIdentitySelector (Selector);
120 return errorCount; // fatal
122 if(Fields.Count == 0)
123 error(h,"atleast one field value must be present");
126 for (int i = 0; i < Fields.Count; i++)
128 XmlSchemaXPath field = Fields [i] as XmlSchemaXPath;
131 errorCount += field.Compile(h,schema);
132 if (field.errorCount == 0)
133 this.compiledSelector.AddField (new XsdIdentityField (field, i));
136 error (h, "Object of type " + Fields [i].GetType() + " is invalid in the Fields Collection");
139 XmlSchemaUtil.CompileID(Id,this,schema.IDCollection,h);
141 this.CompilationId = schema.CompilationId;