7bfe81d4f14f12c58c7b2d0aa96260c22ab1e74a
[mono.git] / mcs / class / System.XML / System.Xml.Schema / XmlSchemaInclude.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 XmlSchemaInclude.\r
32         /// </summary>\r
33         public class XmlSchemaInclude : XmlSchemaExternal\r
34         {\r
35                 private XmlSchemaAnnotation annotation;\r
36                 const string xmlname = "include";\r
37 \r
38                 public XmlSchemaInclude()\r
39                 {\r
40                 }\r
41                 [XmlElement("annotation",Namespace=XmlSchema.Namespace)]\r
42                 public XmlSchemaAnnotation Annotation \r
43                 {\r
44                         get{ return  annotation; } \r
45                         set{ annotation = value; }\r
46                 }\r
47 \r
48                 //<include \r
49                 //  id = ID \r
50                 //  schemaLocation = anyURI \r
51                 //  {any attributes with non-schema namespace . . .}>\r
52                 //  Content: (annotation?)\r
53                 //</include>\r
54                 internal static XmlSchemaInclude Read(XmlSchemaReader reader, ValidationEventHandler h)\r
55                 {\r
56                         XmlSchemaInclude include = new XmlSchemaInclude();\r
57                         reader.MoveToElement();\r
58 \r
59                         if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)\r
60                         {\r
61                                 error(h,"Should not happen :1: XmlSchemaInclude.Read, name="+reader.Name,null);\r
62                                 reader.SkipToEnd();\r
63                                 return null;\r
64                         }\r
65 \r
66                         include.LineNumber = reader.LineNumber;\r
67                         include.LinePosition = reader.LinePosition;\r
68                         include.SourceUri = reader.BaseURI;\r
69 \r
70                         while(reader.MoveToNextAttribute())\r
71                         {\r
72                                 if(reader.Name == "id")\r
73                                 {\r
74                                         include.Id = reader.Value;\r
75                                 }\r
76                                 else if(reader.Name == "schemaLocation")\r
77                                 {\r
78                                         include.SchemaLocation = reader.Value;\r
79                                 }\r
80                                 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)\r
81                                 {\r
82                                         error(h,reader.Name + " is not a valid attribute for include",null);\r
83                                 }\r
84                                 else\r
85                                 {\r
86                                         XmlSchemaUtil.ReadUnhandledAttribute(reader,include);\r
87                                 }\r
88                         }\r
89 \r
90                         reader.MoveToElement(); \r
91                         if(reader.IsEmptyElement)\r
92                                 return include;\r
93 \r
94                         //  Content: (annotation?)\r
95                         int level = 1;\r
96                         while(reader.ReadNextElement())\r
97                         {\r
98                                 if(reader.NodeType == XmlNodeType.EndElement)\r
99                                 {\r
100                                         if(reader.LocalName != xmlname)\r
101                                                 error(h,"Should not happen :2: XmlSchemaInclude.Read, name="+reader.Name,null);\r
102                                         break;\r
103                                 }\r
104                                 if(level <= 1 && reader.LocalName == "annotation")\r
105                                 {\r
106                                         level = 2;      //Only one annotation\r
107                                         XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);\r
108                                         if(annotation != null)\r
109                                                 include.Annotation = annotation;\r
110                                         continue;\r
111                                 }\r
112                                 reader.RaiseInvalidElementError();\r
113                         }\r
114 \r
115                         return include;\r
116                 }\r
117         }\r
118 }