2002-06-10 Dwivedi, Ajay kumar <adwiv@yahoo.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                 private static 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                 [MonoTODO]\r
51                 internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
52                 {\r
53                         if(Name == null)\r
54                                 error(h,"Required attribute name must be present");\r
55                         else if(!XmlSchemaUtil.CheckNCName(this.name)) \r
56                                 error(h,"attribute name must be NCName");\r
57                         else\r
58                                 qualifiedName = new XmlQualifiedName(Name,info.targetNS);\r
59 \r
60                         if(Public==null||Public == "")\r
61                                 error(h,"public must be present");\r
62                         else if(!XmlSchemaUtil.CheckAnyUri(Public))\r
63                                 error(h,"public must be anyURI");\r
64 \r
65                         if(system != null && XmlSchemaUtil.CheckAnyUri(system))\r
66                                 error(h,"system must be anyURI");\r
67 \r
68                         if(this.Id != null && !XmlSchemaUtil.CheckID(Id))\r
69                                 error(h, "id must be a valid ID");\r
70 \r
71                         return errorCount;\r
72                 }\r
73                 \r
74                 [MonoTODO]\r
75                 internal int Validate(ValidationEventHandler h)\r
76                 {\r
77                         return errorCount;\r
78                 }\r
79 \r
80                 //<notation \r
81                 //  id = ID \r
82                 //  name = NCName \r
83                 //  public = anyURI \r
84                 //  system = anyURI \r
85                 //  {any attributes with non-schema namespace . . .}>\r
86                 //  Content: (annotation?)\r
87                 //</notation>\r
88                 internal static XmlSchemaNotation Read(XmlSchemaReader reader, ValidationEventHandler h)\r
89                 {\r
90                         XmlSchemaNotation notation = new XmlSchemaNotation();\r
91                         reader.MoveToElement();\r
92 \r
93                         if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)\r
94                         {\r
95                                 error(h,"Should not happen :1: XmlSchemaInclude.Read, name="+reader.Name,null);\r
96                                 reader.Skip();\r
97                                 return null;\r
98                         }\r
99 \r
100                         notation.LineNumber = reader.LineNumber;\r
101                         notation.LinePosition = reader.LinePosition;\r
102                         notation.SourceUri = reader.BaseURI;\r
103 \r
104                         while(reader.MoveToNextAttribute())\r
105                         {\r
106                                 if(reader.Name == "id")\r
107                                 {\r
108                                         notation.Id = reader.Value;\r
109                                 }\r
110                                 else if(reader.Name == "name")\r
111                                 {\r
112                                         notation.name = reader.Value;\r
113                                 }\r
114                                 else if(reader.Name == "public")\r
115                                 {\r
116                                         notation.pub = reader.Value;\r
117                                 }\r
118                                 else if(reader.Name == "system")\r
119                                 {\r
120                                         notation.system = reader.Value;\r
121                                 }\r
122                                 else if(reader.NamespaceURI == "" || reader.NamespaceURI == XmlSchema.Namespace)\r
123                                 {\r
124                                         error(h,reader.Name + " is not a valid attribute for notation",null);\r
125                                 }\r
126                                 else\r
127                                 {\r
128                                         //TODO: Add to Unhandled attributes\r
129                                 }\r
130                         }\r
131 \r
132                         reader.MoveToElement();\r
133                         if(reader.IsEmptyElement)\r
134                                 return notation;\r
135 \r
136                         //  Content: (annotation?)\r
137                         int level = 1;\r
138                         while(reader.ReadNextElement())\r
139                         {\r
140                                 if(reader.NodeType == XmlNodeType.EndElement)\r
141                                 {\r
142                                         if(reader.LocalName != xmlname)\r
143                                                 error(h,"Should not happen :2: XmlSchemaNotation.Read, name="+reader.Name,null);\r
144                                         break;\r
145                                 }\r
146                                 if(level <= 1 && reader.LocalName == "annotation")\r
147                                 {\r
148                                         level = 2;      //Only one annotation\r
149                                         XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);\r
150                                         if(annotation != null)\r
151                                                 notation.Annotation = annotation;\r
152                                         continue;\r
153                                 }\r
154                                 reader.RaiseInvalidElementError();\r
155                         }\r
156                         return notation;\r
157                 }\r
158         }\r
159 }\r