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