Add MIT license to System.XML.DLL
[mono.git] / mcs / class / System.XML / System.Xml.Schema / XmlSchemaNotation.cs
1 // Author: Dwivedi, Ajay kumar\r
2 //            Adwiv@Yahoo.com\r
3
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.
23 //
24 using System;\r
25 using System.Xml.Serialization;\r
26 using System.Xml;\r
27 \r
28 namespace System.Xml.Schema\r
29 {\r
30         /// <summary>\r
31         /// Summary description for XmlSchemaNotation.\r
32         /// </summary>\r
33         public class XmlSchemaNotation : XmlSchemaAnnotated\r
34         {\r
35                 private string name;\r
36                 private string pub;\r
37                 private string system;\r
38                 private XmlQualifiedName qualifiedName;\r
39                 const string xmlname = "notation";\r
40 \r
41                 public XmlSchemaNotation()\r
42                 {\r
43                 }\r
44                 [System.Xml.Serialization.XmlAttribute("name")]\r
45                 public string Name \r
46                 {\r
47                         get{ return  name; } \r
48                         set{ name = value; }\r
49                 }\r
50                 [System.Xml.Serialization.XmlAttribute("public")]\r
51                 public string Public \r
52                 {\r
53                         get{ return  pub; } \r
54                         set{ pub = value; }\r
55                 }\r
56                 [System.Xml.Serialization.XmlAttribute("system")]\r
57                 public string System \r
58                 {\r
59                         get{ return  system; } \r
60                         set{ system = value; }\r
61                 }\r
62 \r
63                 [XmlIgnore]\r
64                 internal XmlQualifiedName QualifiedName \r
65                 {\r
66                         get{ return qualifiedName;}\r
67                 }\r
68 \r
69                 // 1. name and public must be present\r
70                 // public and system must be anyURI\r
71                 internal override int Compile(ValidationEventHandler h, XmlSchema schema)\r
72                 {\r
73                         // If this is already compiled this time, simply skip.\r
74                         if (this.IsComplied (schema.CompilationId))\r
75                                 return 0;\r
76 \r
77                         if(Name == null)\r
78                                 error(h,"Required attribute name must be present");\r
79                         else if(!XmlSchemaUtil.CheckNCName(this.name)) \r
80                                 error(h,"attribute name must be NCName");\r
81                         else\r
82                                 qualifiedName = new XmlQualifiedName(Name,schema.TargetNamespace);\r
83 \r
84                         if(Public==null)\r
85                                 error(h,"public must be present");\r
86                         else if(!XmlSchemaUtil.CheckAnyUri(Public))\r
87                                 error(h,"public must be anyURI");\r
88 \r
89                         if(system != null && !XmlSchemaUtil.CheckAnyUri(system))\r
90                                 error(h,"system must be present and of Type anyURI");\r
91                         \r
92                         XmlSchemaUtil.CompileID(Id,this,schema.IDCollection,h);\r
93 \r
94                         return errorCount;\r
95                 }\r
96                 \r
97                 internal override int Validate(ValidationEventHandler h, XmlSchema schema)\r
98                 {\r
99                         return errorCount;\r
100                 }\r
101 \r
102                 //<notation \r
103                 //  id = ID \r
104                 //  name = NCName \r
105                 //  public = anyURI \r
106                 //  system = anyURI \r
107                 //  {any attributes with non-schema namespace . . .}>\r
108                 //  Content: (annotation?)\r
109                 //</notation>\r
110                 internal static XmlSchemaNotation Read(XmlSchemaReader reader, ValidationEventHandler h)\r
111                 {\r
112                         XmlSchemaNotation notation = new XmlSchemaNotation();\r
113                         reader.MoveToElement();\r
114 \r
115                         if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)\r
116                         {\r
117                                 error(h,"Should not happen :1: XmlSchemaInclude.Read, name="+reader.Name,null);\r
118                                 reader.Skip();\r
119                                 return null;\r
120                         }\r
121 \r
122                         notation.LineNumber = reader.LineNumber;\r
123                         notation.LinePosition = reader.LinePosition;\r
124                         notation.SourceUri = reader.BaseURI;\r
125 \r
126                         while(reader.MoveToNextAttribute())\r
127                         {\r
128                                 if(reader.Name == "id")\r
129                                 {\r
130                                         notation.Id = reader.Value;\r
131                                 }\r
132                                 else if(reader.Name == "name")\r
133                                 {\r
134                                         notation.name = reader.Value;\r
135                                 }\r
136                                 else if(reader.Name == "public")\r
137                                 {\r
138                                         notation.pub = reader.Value;\r
139                                 }\r
140                                 else if(reader.Name == "system")\r
141                                 {\r
142                                         notation.system = reader.Value;\r
143                                 }\r
144                                 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)\r
145                                 {\r
146                                         error(h,reader.Name + " is not a valid attribute for notation",null);\r
147                                 }\r
148                                 else\r
149                                 {\r
150                                         XmlSchemaUtil.ReadUnhandledAttribute(reader,notation);\r
151                                 }\r
152                         }\r
153 \r
154                         reader.MoveToElement();\r
155                         if(reader.IsEmptyElement)\r
156                                 return notation;\r
157 \r
158                         //  Content: (annotation?)\r
159                         int level = 1;\r
160                         while(reader.ReadNextElement())\r
161                         {\r
162                                 if(reader.NodeType == XmlNodeType.EndElement)\r
163                                 {\r
164                                         if(reader.LocalName != xmlname)\r
165                                                 error(h,"Should not happen :2: XmlSchemaNotation.Read, name="+reader.Name,null);\r
166                                         break;\r
167                                 }\r
168                                 if(level <= 1 && reader.LocalName == "annotation")\r
169                                 {\r
170                                         level = 2;      //Only one annotation\r
171                                         XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);\r
172                                         if(annotation != null)\r
173                                                 notation.Annotation = annotation;\r
174                                         continue;\r
175                                 }\r
176                                 reader.RaiseInvalidElementError();\r
177                         }\r
178                         return notation;\r
179                 }\r
180         }\r
181 }\r