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