2010-04-06 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.XML / System.Xml.Schema / XmlSchemaNotation.cs
blobf5b8ab363df1bc9624a3b6c58f7ae85f43bb4ad0
1 // Author: Dwivedi, Ajay kumar
2 // Adwiv@Yahoo.com
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.
24 using System;
25 using System.Xml.Serialization;
26 using System.Xml;
28 namespace System.Xml.Schema
30 /// <summary>
31 /// Summary description for XmlSchemaNotation.
32 /// </summary>
33 public class XmlSchemaNotation : XmlSchemaAnnotated
35 private string name;
36 private string pub;
37 private string system;
38 private XmlQualifiedName qualifiedName;
39 const string xmlname = "notation";
41 public XmlSchemaNotation()
44 [System.Xml.Serialization.XmlAttribute("name")]
45 public string Name
47 get{ return name; }
48 set{ name = value; }
50 [System.Xml.Serialization.XmlAttribute("public")]
51 public string Public
53 get{ return pub; }
54 set{ pub = value; }
56 [System.Xml.Serialization.XmlAttribute("system")]
57 public string System
59 get{ return system; }
60 set{ system = value; }
63 [XmlIgnore]
64 internal XmlQualifiedName QualifiedName
66 get{ return qualifiedName;}
69 // 1. name and public must be present
70 // public and system must be anyURI
71 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
73 // If this is already compiled this time, simply skip.
74 if (CompilationId == schema.CompilationId)
75 return 0;
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, AncestorSchema.TargetNamespace);
84 if(Public==null)
85 error(h,"public must be present");
86 else if(!XmlSchemaUtil.CheckAnyUri(Public))
87 error(h,"public must be anyURI");
89 if(system != null && !XmlSchemaUtil.CheckAnyUri(system))
90 error(h,"system must be present and of Type anyURI");
92 XmlSchemaUtil.CompileID(Id,this,schema.IDCollection,h);
94 return errorCount;
97 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
99 return errorCount;
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)
112 XmlSchemaNotation notation = new XmlSchemaNotation();
113 reader.MoveToElement();
115 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
117 error(h,"Should not happen :1: XmlSchemaInclude.Read, name="+reader.Name,null);
118 reader.Skip();
119 return null;
122 notation.LineNumber = reader.LineNumber;
123 notation.LinePosition = reader.LinePosition;
124 notation.SourceUri = reader.BaseURI;
126 while(reader.MoveToNextAttribute())
128 if(reader.Name == "id")
130 notation.Id = reader.Value;
132 else if(reader.Name == "name")
134 notation.name = reader.Value;
136 else if(reader.Name == "public")
138 notation.pub = reader.Value;
140 else if(reader.Name == "system")
142 notation.system = reader.Value;
144 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
146 error(h,reader.Name + " is not a valid attribute for notation",null);
148 else
150 XmlSchemaUtil.ReadUnhandledAttribute(reader,notation);
154 reader.MoveToElement();
155 if(reader.IsEmptyElement)
156 return notation;
158 // Content: (annotation?)
159 int level = 1;
160 while(reader.ReadNextElement())
162 if(reader.NodeType == XmlNodeType.EndElement)
164 if(reader.LocalName != xmlname)
165 error(h,"Should not happen :2: XmlSchemaNotation.Read, name="+reader.Name,null);
166 break;
168 if(level <= 1 && reader.LocalName == "annotation")
170 level = 2; //Only one annotation
171 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
172 if(annotation != null)
173 notation.Annotation = annotation;
174 continue;
176 reader.RaiseInvalidElementError();
178 return notation;