2003-07-19 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
[mono.git] / mcs / class / System.XML / System.Xml.Schema / XmlSchemaImport.cs
1 // Author: Dwivedi, Ajay kumar\r
2 //            Adwiv@Yahoo.com\r
3 using System;\r
4 using System.Xml;\r
5 using System.Xml.Serialization;\r
6 \r
7 namespace System.Xml.Schema\r
8 {\r
9         /// <summary>\r
10         /// Summary description for XmlSchemaImport.\r
11         /// </summary>\r
12         public class XmlSchemaImport : XmlSchemaExternal\r
13         {\r
14                 private XmlSchemaAnnotation annotation;\r
15                 private string nameSpace;\r
16                 private static string xmlname = "import";\r
17 \r
18                 public XmlSchemaImport()\r
19                 {\r
20                 }\r
21                 \r
22                 [System.Xml.Serialization.XmlAttribute("namespace")]\r
23                 public string Namespace \r
24                 {\r
25                         get{ return  nameSpace; } \r
26                         set{ nameSpace = value; }\r
27                 }\r
28 \r
29                 [XmlElement("annotation",Namespace=XmlSchema.Namespace)]\r
30                 public XmlSchemaAnnotation Annotation \r
31                 {\r
32                         get{ return  annotation; } \r
33                         set{ annotation = value; }\r
34                 }\r
35                 //<import \r
36                 //  id = ID \r
37                 //  namespace = anyURI \r
38                 //  schemaLocation = anyURI \r
39                 //  {any attributes with non-schema namespace . . .}>\r
40                 //  Content: (annotation?)\r
41                 //</import>\r
42                 internal static XmlSchemaImport Read(XmlSchemaReader reader, ValidationEventHandler h)\r
43                 {\r
44                         XmlSchemaImport import = new XmlSchemaImport();\r
45                         reader.MoveToElement();\r
46 \r
47                         if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != "import")\r
48                         {\r
49                                 error(h,"Should not happen :1: XmlSchemaImport.Read, name="+reader.Name,null);\r
50                                 reader.SkipToEnd();\r
51                                 return null;\r
52                         }\r
53 \r
54                         import.LineNumber = reader.LineNumber;\r
55                         import.LinePosition = reader.LinePosition;\r
56                         import.SourceUri = reader.BaseURI;\r
57 \r
58                         while(reader.MoveToNextAttribute())\r
59                         {\r
60                                 if(reader.Name == "id")\r
61                                 {\r
62                                         import.Id = reader.Value;\r
63                                 }\r
64                                 else if(reader.Name == "namespace")\r
65                                 {\r
66                                         import.nameSpace = reader.Value;\r
67                                 }\r
68                                 else if(reader.Name == "schemaLocation")\r
69                                 {\r
70                                         import.SchemaLocation = reader.Value;\r
71                                 }\r
72                                 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)\r
73                                 {\r
74                                         error(h,reader.Name + " is not a valid attribute for import",null);\r
75                                 }\r
76                                 else\r
77                                 {\r
78                                         XmlSchemaUtil.ReadUnhandledAttribute(reader,import);\r
79                                 }\r
80                         }\r
81 \r
82                         reader.MoveToElement(); \r
83                         if(reader.IsEmptyElement)\r
84                                 return import;\r
85 \r
86                         //  Content: (annotation?)\r
87                         int level = 1;\r
88                         while(reader.ReadNextElement())\r
89                         {\r
90                                 if(reader.NodeType == XmlNodeType.EndElement)\r
91                                 {\r
92                                         if(reader.LocalName != xmlname)\r
93                                                 error(h,"Should not happen :2: XmlSchemaImport.Read, name="+reader.Name,null);\r
94                                         break;\r
95                                 }\r
96                                 if(level <= 1 && reader.LocalName == "annotation")\r
97                                 {\r
98                                         level = 2;      //Only one annotation\r
99                                         XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);\r
100                                         if(annotation != null)\r
101                                                 import.Annotation = annotation;\r
102                                         continue;\r
103                                 }\r
104                                 reader.RaiseInvalidElementError();\r
105                         }\r
106                         return import;\r
107                 }\r
108         }\r
109 }\r