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
),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
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 (this.IsComplied (schema
.CompilationId
))
92 error(h
,"Required attribute name must be present");
93 else if(!XmlSchemaUtil
.CheckNCName(this.name
))
94 error(h
,"attribute name must be NCName");
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.");
100 schema
.NamedIdentities
.Add (qName
, this);
104 error(h
,"selector must be present");
107 Selector
.isSelector
= true;
108 errorCount
+= Selector
.Compile(h
,schema
);
109 if (selector
.errorCount
== 0)
110 compiledSelector
= new XsdIdentitySelector (Selector
);
113 return errorCount
; // fatal
115 if(Fields
.Count
== 0)
116 error(h
,"atleast one field value must be present");
119 for (int i
= 0; i
< Fields
.Count
; i
++)
121 XmlSchemaXPath field
= Fields
[i
] as XmlSchemaXPath
;
124 errorCount
+= field
.Compile(h
,schema
);
125 if (field
.errorCount
== 0)
126 this.compiledSelector
.AddField (new XsdIdentityField (field
, i
));
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
;