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