1 // Author: Dwivedi, Ajay kumar
\r
4 using System.Collections;
\r
6 using System.Xml.Serialization;
\r
7 using Mono.Xml.Schema;
\r
9 namespace System.Xml.Schema
\r
12 /// Summary description for XmlSchemaIdentityConstraint.
\r
14 public class XmlSchemaIdentityConstraint : XmlSchemaAnnotated
\r
16 private XmlSchemaObjectCollection fields;
\r
17 private string name;
\r
18 private XmlQualifiedName qName;
\r
19 private XmlSchemaXPath selector;
\r
21 private XsdIdentitySelector compiledSelector;
\r
22 // ArrayList compiledFields;
\r
24 public XmlSchemaIdentityConstraint()
\r
26 fields = new XmlSchemaObjectCollection();
\r
27 qName = XmlQualifiedName.Empty;
\r
30 [System.Xml.Serialization.XmlAttribute("name")]
\r
33 get{ return name; }
\r
34 set{ name = value; }
\r
37 [XmlElement("selector",typeof(XmlSchemaXPath),Namespace=XmlSchema.Namespace)]
\r
38 public XmlSchemaXPath Selector
\r
40 get{ return selector; }
\r
41 set{ selector = value; }
\r
44 [XmlElement("field",typeof(XmlSchemaXPath),Namespace=XmlSchema.Namespace)]
\r
45 public XmlSchemaObjectCollection Fields
\r
47 get{ return fields; }
\r
51 public XmlQualifiedName QualifiedName
\r
53 get{ return qName; }
\r
56 internal XsdIdentitySelector CompiledSelector {
\r
57 get { return compiledSelector; }
\r
61 /// 1. name must be present
\r
62 /// 2. selector and field must be present
\r
64 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
\r
66 // If this is already compiled this time, simply skip.
\r
67 if (this.IsComplied (schema.CompilationId))
\r
71 error(h,"Required attribute name must be present");
\r
72 else if(!XmlSchemaUtil.CheckNCName(this.name))
\r
73 error(h,"attribute name must be NCName");
\r
75 this.qName = new XmlQualifiedName(Name,schema.TargetNamespace);
\r
76 if (schema.NamedIdentities.Contains (qName))
\r
77 error(h,"There is already same named identity constraint in this namespace.");
\r
79 schema.NamedIdentities.Add (qName, this);
\r
82 if(Selector == null)
\r
83 error(h,"selector must be present");
\r
86 Selector.isSelector = true;
\r
87 errorCount += Selector.Compile(h,schema);
\r
88 if (selector.errorCount == 0)
\r
89 compiledSelector = new XsdIdentitySelector (Selector);
\r
92 return errorCount; // fatal
\r
94 if(Fields.Count == 0)
\r
95 error(h,"atleast one field value must be present");
\r
98 for (int i = 0; i < Fields.Count; i++)
\r
100 XmlSchemaXPath field = Fields [i] as XmlSchemaXPath;
\r
103 errorCount += field.Compile(h,schema);
\r
104 if (field.errorCount == 0)
\r
105 this.compiledSelector.AddField (new XsdIdentityField (field, i));
\r
108 error (h, "Object of type " + Fields [i].GetType() + " is invalid in the Fields Collection");
\r
111 XmlSchemaUtil.CompileID(Id,this,schema.IDCollection,h);
\r
113 this.CompilationId = schema.CompilationId;
\r