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