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